# dsxkline_python **Repository Path**: quarky/dsxkline_python ## Basic Information - **Project Name**: dsxkline_python - **Description**: No description available - **Primary Language**: Python - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-28 - **Last Updated**: 2024-09-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pydsxkline pydsxkline是一个有趣的python包,一行代码即可显示K线图,主要应用于股票金融量化领域,当您想要把股票数据图形化的时候,可以试试这个小工具,希望能帮到有需要的朋友。 pydsxkline基于dsxkline进行封装,具体的接口可以查看官网 http://www.dsxkline.com ![PyPI](https://img.shields.io/pypi/v/pydsxkline?color=0&label=pypi%20pydsxkline) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydsxkline?color=0) ![PyPI - Downloads](https://img.shields.io/pypi/dm/pydsxkline) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/dsxkline/dsxkline_python) # 预览 WechatIMG548 # Getting started ### Install ``` bash pip install pydsxkline ``` - Currently only python version 3.8 or older supported ### Hello world ``` python from pydsxkline.dsxkline import DsxKline DsxKline.show("sh000001","上证指数") ``` ### 分时图 ``` python DsxKline.show("sh000001","上证指数",CycleType.t) ``` WechatIMG549 ### 五日图 ``` python # 五日图 DsxKline.show("sh000001","上证指数",CycleType.t5) ``` WechatIMG550 ### 日K ``` python DsxKline.show("sh000001","上证指数",CycleType.day) ``` ### 周K ``` python DsxKline.show("sh000001","上证指数",CycleType.week) ``` ### 月K ``` python DsxKline.show("sh000001","上证指数",CycleType.month) ``` ### 年K ``` python DsxKline.show("sh000001","上证指数",CycleType.year) ``` ### 1分钟k线 ``` python DsxKline.show("sh000001","上证指数",CycleType.m1) ``` ### 自定义 ``` python DsxKline.show("sh000001","上证指数",CycleType.day,FqType.qfq,theme=DsxThemeName.white,sides["VOL","MACD","KDJ","RSI","WR","CCI","PSY","BIAS"],height=1600) ``` ### 加载本地数据 ``` python # 日线数据 datas = [ "20210915,3651.16,3677.53,3638.32,3656.22,474970001.00,60423154.41", "20210916,3664.84,3677.92,3606.73,3607.09,546741474.00,67395534.04", "20210917,3595.27,3620.96,3569.27,3613.97,516850210.00,62883439.43", "20210922,3563.21,3629.45,3560.50,3628.49,472296053.00,55987472.96", "20210923,3651.27,3670.95,3632.28,3642.22,534995486.00,63321892.91", "20210924,3637.87,3651.43,3607.79,3613.07,507304772.00,60678860.91", ... ] DsxKline.show("sh000001","上证指数",datas=datas,enable_data_api=False,cycle=CycleType.day) ``` ### 画买卖点 ```python def draw_event(): return [ DsxKline.draw_cycle_with_date("20230313","买","red","#ffffff"), DsxKline.draw_cycle_with_date("20221129","卖","green","#ffffff",12.99), DsxKline.draw_cycle_with_date("202303241104","买","red","#ffffff") ] DsxKline.show("sh000001","上证指数",CycleType.day,draw_event=draw_event(),main=["SAR"]) ``` ### 自定义头部HTML ```python header = """

这是一个大师兄线图 pydsxkline

""" DsxKline.show("sh000001","上证指数",CycleType.day,header_html=header,header_height=160) ``` image ### 自定义指标数据 ```python # 自定义指标数据 # 这个要准备跟K线数据一一对应的指标数据 # 指标名称 name1 = "MYMA" def _install_js(): # 指标值名称 MA10,line 画折线,颜色 #ff0000 _model = [DrawModel("MA10","line","#ff0000")] # 支持蜡烛图 _chartType = [ChartType.candle] # 副图 sides 或者主图 main 或者两者 _location = ["sides"] # 指标数据 _datas = [] # 这里模拟计算一个均线指标 N = 10 # 获取K线数据 klines = get_datas() for i in range(len(klines)): if i>=N: amount = 0 for j in range(max(0,i-N+1),i+1): subitem = klines[j] subobj = subitem.split(",") close = float(subobj[4]) amount += close MA10 = amount / N _datas.append({"MA10":MA10}) else: _datas.append({"MA10":None}) # 生成js install_js = DsxKline.get_install_index_js(name1,_model,_chartType,_location,_datas) return install_js DsxKline.show("sh000001","上证指数",CycleType.day,main=["SAR"],sides=[name1,"VOL","MACD","KDJ"],datas=get_datas(),enable_data_api=False,install_index_js=_install_js()) ``` ### 自定义指标算法 自定义指标算法比较麻烦,因为js引擎只能执行js代码,所以指标算法需要用js代码来写 ```python # 自定义指标算法,这个比较麻烦,算法需要用js来写 name2 = "MYMAMA" def _create_index_js(): # 指标值名称 MA10,line 画折线,颜色 #ff0000 _model = [ DrawModel("MA10","line","#ff0000"), DrawModel("MA30","line","#ffff00") ] # 支持蜡烛图 _chartType = [ChartType.candle] # 副图 sides 或者主图 main 或者两者 _location = ["sides"] # 指标算法帧函数 _func = """ // 这里写js函数代码 var _name2 = "%s"; var _func = function(){ // 取得当前坐标数据 var item = this.datas[this.day]; // 初始化指标 if (item.ZHIBIAO[_name2] == null) item.ZHIBIAO[_name2] = { }; // 开始计算指标值,这里我们计算个均线指标吧 var N = 10; if(this.day ### 参数属性 - 详细的文档可参考:http://www.dsxkline.com ``` python # 名称 name = "" # 证券代码 symbol = "" # 昨日收盘价 last_close = 0 # 宽 width = 800 # 高 height = 600 # 图表类型 chartType = ChartType.timeSharing # 周期类型 cycle = CycleType.t # 复权类型 fq = FqType.default # 主题 theme = DsxThemeName.dark # 主图指标 main = ["MA"] # 副图指标 sides = ["VOL","MACD","RSI"] # 数据 datas = [] # 每页请求数据大小 page_size = 320 # 页码 page = 1 # 十字线回调 on_crossing = None # 更新完成 update_complate = None # 副图高度 side_height = 80 # 底部间距 padding_bottom = 10 # 蜡烛图类型 默认空心 candel_type = CandleType.hollow # 缩放类型 默认固定左边进行缩放 zoom_lock_type = ZoomLockType.right # 是否显示提示面板,十字线移动的时候显示的详情面板 is_show_kline_tip_pannel = True # 自动适配,k线图根据父窗口的大小自动调整 autosize = False # 是否启用内置行情数据接口,当使用本地数据的时候请关闭设置为 false enable_data_api = True # debug debug = False # 画图事件集合 draw_event = None # 头部html header_html = None # 头部高度 header_height = 0 # 安装自定义指标数据 install_index_js = install_index_js # 创建自定义指标算法js代码 create_index_js = create_index_js ```