新增okex gateway

This commit is contained in:
msincenselee 2018-03-18 23:15:12 +08:00
parent 2b197fa0c6
commit 46afeb57d4
8 changed files with 4216 additions and 0 deletions

41
vnpy/api/okex/README.md Normal file
View File

@ -0,0 +1,41 @@
### 简介
OKEX的比特币交易接口基于Websocket API开发实现了以下功能
1. 发送、撤销委托
2. 查询委托、持仓、资金、成交历史
3. 实时行情、成交、资金更新的推送
币币交易WebSocket服务连接地址wss://real.okex.com:10441/websocket
发送请求
请求数据格式为:
{'event':'addChannel','channel':'channelValue','parameters':{'api_key':'value1','sign':'value2'}}
其中
event: addChannel(注册请求数据)/removeChannel(注销请求数据)
channel: OKEx提供请求数据类型
parameters: 参数为选填参数其中api_key为用户申请的APIKEYsign为签名字符串签名规则参照请求说明
binary: 参数为选填参数是否为压缩数据。1 压缩数据0 原始数据默认0
例如: websocket.send("{'event':'addChannel','channel':'ok_sub_spot_usd_btc_ticker','binary','1'}")
websocket.send("[{'event':'addChannel','channel':'ok_sub_spot_usd_btc_ticker'},{'event':'addChannel','channel':'ok_sub_spot_usd_btc_depth'},{'event':'addChannel','channel':'ok_sub_spot_usd_btc_trades'}]"),支持批量注册
服务器响应
返回数据格式为: [{"channel":"channel","success":"","errorcode":"","data":{}}, {"channel":"channel","success":"","errorcode":1,"data":{}}]
其中
channel: 请求的数据类型
result: true成功false失败(用于WebSocket 交易API) data: 返回结果数据
errorcode: 错误码(用于WebSocket 交易API)
推送过程说明
为保证推送的及时性及减少流量行情数据ticker和委托深度depth这两种数据类型只会在数据发生变化的情况下才会推送数据交易记录trades是推送从上次推送到本次推送产生的增量数据。
如何判断连接是否断开
OKEx通过心跳机制解决这个问题。客户端每30秒发送一次心跳数据{'event':'ping'},服务器会响应客户端:{"event":"pong"}以此来表明客户端和服务端保持正常连接。如果客户端未接到服务端响应的心跳数据则需要客户端重新建立连接。
### API信息
链接:[https://github.com/okcoin-okex/OKEx.com-api-docs/](https://github.com/okcoin-okex/OKEx.com-api-docs/)

View File

@ -0,0 +1,3 @@
# encoding: UTF-8
from vnpy.api.okex.vnokex import WsSpotApi, WsFuturesApi,SPOT_SYMBOL, CONTRACT_SYMBOL, SPOT_CURRENCY,CONTRACT_TYPE

705
vnpy/api/okex/okexData.py Normal file
View File

@ -0,0 +1,705 @@
# encoding: UTF-8
# 币币最小交易量
# key: symbol_pair, value: min_size
# -----------------------------------------
SPOT_TRADE_SIZE_DICT = {}
SPOT_TRADE_SIZE_DICT['eth_usdt'] = 0.0001
SPOT_TRADE_SIZE_DICT['btc_usdt'] = 0.0001
SPOT_TRADE_SIZE_DICT['bch_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['bt2_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['etc_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['btg_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['ltc_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['etc_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['bch_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['qtum_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['qtum_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['qtum_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['neo_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['gas_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['hsr_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['neo_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['gas_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['hsr_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['neo_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['gas_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['hsr_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['dash_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['xrp_btc'] = 1
SPOT_TRADE_SIZE_DICT['zec_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['dash_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['xrp_eth'] = 1
SPOT_TRADE_SIZE_DICT['zec_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['dash_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['xrp_usdt'] = 1
SPOT_TRADE_SIZE_DICT['zec_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['iota_btc'] = 1
SPOT_TRADE_SIZE_DICT['xuc_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['iota_eth'] = 1
SPOT_TRADE_SIZE_DICT['xuc_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['iota_usdt'] = 1
SPOT_TRADE_SIZE_DICT['xuc_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['eos_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['omg_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['eos_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['omg_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['eos_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['omg_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['act_btc'] = 1
SPOT_TRADE_SIZE_DICT['btm_btc'] = 1
SPOT_TRADE_SIZE_DICT['act_eth'] = 1
SPOT_TRADE_SIZE_DICT['btm_eth'] = 1
SPOT_TRADE_SIZE_DICT['act_usdt'] = 1
SPOT_TRADE_SIZE_DICT['btm_usdt'] = 1
SPOT_TRADE_SIZE_DICT['bcd_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['bcd_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['storj_btc'] = 1
SPOT_TRADE_SIZE_DICT['snt_btc'] = 10
SPOT_TRADE_SIZE_DICT['storj_eth'] = 1
SPOT_TRADE_SIZE_DICT['snt_eth'] = 10
SPOT_TRADE_SIZE_DICT['storj_usdt'] = 1
SPOT_TRADE_SIZE_DICT['snt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['pay_btc'] = 1
SPOT_TRADE_SIZE_DICT['dgd_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['gnt_btc'] = 1
SPOT_TRADE_SIZE_DICT['pay_eth'] = 1
SPOT_TRADE_SIZE_DICT['dgd_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['gnt_eth'] = 1
SPOT_TRADE_SIZE_DICT['pay_usdt'] = 1
SPOT_TRADE_SIZE_DICT['dgd_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['gnt_usdt'] = 1
SPOT_TRADE_SIZE_DICT['lrc_btc'] = 1
SPOT_TRADE_SIZE_DICT['nuls_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['mco_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['lrc_eth'] = 1
SPOT_TRADE_SIZE_DICT['nuls_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['mco_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['lrc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['nuls_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['mco_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['btg_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['cmt_btc'] = 10
SPOT_TRADE_SIZE_DICT['itc_btc'] = 1
SPOT_TRADE_SIZE_DICT['cmt_eth'] = 10
SPOT_TRADE_SIZE_DICT['itc_eth'] = 1
SPOT_TRADE_SIZE_DICT['cmt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['itc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['sbtc_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['pra_btc'] = 1
SPOT_TRADE_SIZE_DICT['san_btc'] = 1
SPOT_TRADE_SIZE_DICT['edo_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['avt_btc'] = 1
SPOT_TRADE_SIZE_DICT['pra_eth'] = 1
SPOT_TRADE_SIZE_DICT['san_eth'] = 1
SPOT_TRADE_SIZE_DICT['edo_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['avt_eth'] = 1
SPOT_TRADE_SIZE_DICT['pra_usdt'] = 1
SPOT_TRADE_SIZE_DICT['san_usdt'] = 1
SPOT_TRADE_SIZE_DICT['edo_usdt'] = 1
SPOT_TRADE_SIZE_DICT['avt_usdt'] = 1
SPOT_TRADE_SIZE_DICT['ltc_bch'] = 0.001
SPOT_TRADE_SIZE_DICT['ltc_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['etc_bch'] = 0.01
SPOT_TRADE_SIZE_DICT['btg_bch'] = 0.01
SPOT_TRADE_SIZE_DICT['avt_bch'] = 1
SPOT_TRADE_SIZE_DICT['act_bch'] = 1
SPOT_TRADE_SIZE_DICT['cmt_bch'] = 10
SPOT_TRADE_SIZE_DICT['dgd_bch'] = 0.001
SPOT_TRADE_SIZE_DICT['dash_bch'] = 0.001
SPOT_TRADE_SIZE_DICT['eos_bch'] = 0.1
SPOT_TRADE_SIZE_DICT['edo_bch'] = 0.1
SPOT_TRADE_SIZE_DICT['ctr_btc'] = 1
SPOT_TRADE_SIZE_DICT['link_btc'] = 1
SPOT_TRADE_SIZE_DICT['salt_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['1st_btc'] = 1
SPOT_TRADE_SIZE_DICT['wtc_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['sngls_btc'] = 10
SPOT_TRADE_SIZE_DICT['snm_btc'] = 10
SPOT_TRADE_SIZE_DICT['zrx_btc'] = 1
SPOT_TRADE_SIZE_DICT['bnt_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['cvc_btc'] = 1
SPOT_TRADE_SIZE_DICT['ctr_eth'] = 1
SPOT_TRADE_SIZE_DICT['link_eth'] = 1
SPOT_TRADE_SIZE_DICT['salt_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['1st_eth'] = 1
SPOT_TRADE_SIZE_DICT['wtc_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['sngls_eth'] = 10
SPOT_TRADE_SIZE_DICT['snm_eth'] = 10
SPOT_TRADE_SIZE_DICT['zrx_eth'] = 1
SPOT_TRADE_SIZE_DICT['bnt_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['cvc_eth'] = 1
SPOT_TRADE_SIZE_DICT['ctr_usdt'] = 1
SPOT_TRADE_SIZE_DICT['link_usdt'] = 1
SPOT_TRADE_SIZE_DICT['salt_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['1st_usdt'] = 1
SPOT_TRADE_SIZE_DICT['wtc_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['sngls_usdt'] = 10
SPOT_TRADE_SIZE_DICT['snm_usdt'] = 10
SPOT_TRADE_SIZE_DICT['zrx_usdt'] = 1
SPOT_TRADE_SIZE_DICT['bnt_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['cvc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['bcd_bch'] = 0.1
SPOT_TRADE_SIZE_DICT['sbtc_bch'] = 0.1
SPOT_TRADE_SIZE_DICT['bcx_btc'] = 10
SPOT_TRADE_SIZE_DICT['bcx_bch'] = 10
SPOT_TRADE_SIZE_DICT['mana_btc'] = 10
SPOT_TRADE_SIZE_DICT['rcn_btc'] = 10
SPOT_TRADE_SIZE_DICT['mana_eth'] = 10
SPOT_TRADE_SIZE_DICT['mana_usdt'] = 10
SPOT_TRADE_SIZE_DICT['vee_btc'] = 10
SPOT_TRADE_SIZE_DICT['vee_eth'] = 10
SPOT_TRADE_SIZE_DICT['vee_usdt'] = 10
SPOT_TRADE_SIZE_DICT['tnb_btc'] = 10
SPOT_TRADE_SIZE_DICT['tnb_eth'] = 10
SPOT_TRADE_SIZE_DICT['tnb_usdt'] = 10
SPOT_TRADE_SIZE_DICT['amm_btc'] = 1
SPOT_TRADE_SIZE_DICT['amm_eth'] = 1
SPOT_TRADE_SIZE_DICT['amm_usdt'] = 1
SPOT_TRADE_SIZE_DICT['knc_btc'] = 1
SPOT_TRADE_SIZE_DICT['knc_eth'] = 1
SPOT_TRADE_SIZE_DICT['knc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['dat_eth'] = 10
SPOT_TRADE_SIZE_DICT['dat_btc'] = 10
SPOT_TRADE_SIZE_DICT['dat_usdt'] = 10
SPOT_TRADE_SIZE_DICT['gnx_btc'] = 1
SPOT_TRADE_SIZE_DICT['gnx_eth'] = 1
SPOT_TRADE_SIZE_DICT['gnx_usdt'] = 1
SPOT_TRADE_SIZE_DICT['icx_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['icx_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['icx_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['ark_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['ark_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['ark_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['yoyo_btc'] = 10
SPOT_TRADE_SIZE_DICT['yoyo_eth'] = 10
SPOT_TRADE_SIZE_DICT['yoyo_usdt'] = 10
SPOT_TRADE_SIZE_DICT['qvt_btc'] = 1
SPOT_TRADE_SIZE_DICT['qvt_eth'] = 1
SPOT_TRADE_SIZE_DICT['qvt_usdt'] = 1
SPOT_TRADE_SIZE_DICT['elf_eth'] = 1
SPOT_TRADE_SIZE_DICT['elf_btc'] = 1
SPOT_TRADE_SIZE_DICT['elf_usdt'] = 1
SPOT_TRADE_SIZE_DICT['ast_btc'] = 1
SPOT_TRADE_SIZE_DICT['ast_eth'] = 1
SPOT_TRADE_SIZE_DICT['ast_usdt'] = 1
SPOT_TRADE_SIZE_DICT['sub_btc'] = 1
SPOT_TRADE_SIZE_DICT['sub_eth'] = 1
SPOT_TRADE_SIZE_DICT['sub_usdt'] = 1
SPOT_TRADE_SIZE_DICT['dnt_btc'] = 10
SPOT_TRADE_SIZE_DICT['dnt_eth'] = 10
SPOT_TRADE_SIZE_DICT['dnt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['fun_btc'] = 10
SPOT_TRADE_SIZE_DICT['fun_eth'] = 10
SPOT_TRADE_SIZE_DICT['fun_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ace_btc'] = 10
SPOT_TRADE_SIZE_DICT['ace_eth'] = 10
SPOT_TRADE_SIZE_DICT['ace_usdt'] = 10
SPOT_TRADE_SIZE_DICT['trx_btc'] = 10
SPOT_TRADE_SIZE_DICT['trx_eth'] = 10
SPOT_TRADE_SIZE_DICT['trx_usdt'] = 10
SPOT_TRADE_SIZE_DICT['evx_btc'] = 1
SPOT_TRADE_SIZE_DICT['evx_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['evx_usdt'] = 1
SPOT_TRADE_SIZE_DICT['mda_btc'] = 1
SPOT_TRADE_SIZE_DICT['mda_eth'] = 1
SPOT_TRADE_SIZE_DICT['mda_usdt'] = 1
SPOT_TRADE_SIZE_DICT['mth_btc'] = 10
SPOT_TRADE_SIZE_DICT['mth_eth'] = 10
SPOT_TRADE_SIZE_DICT['mth_usdt'] = 10
SPOT_TRADE_SIZE_DICT['mtl_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['mtl_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['mtl_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['xem_btc'] = 1
SPOT_TRADE_SIZE_DICT['xem_eth'] = 1
SPOT_TRADE_SIZE_DICT['xem_usdt'] = 1
SPOT_TRADE_SIZE_DICT['icn_btc'] = 1
SPOT_TRADE_SIZE_DICT['icn_eth'] = 1
SPOT_TRADE_SIZE_DICT['icn_usdt'] = 1
SPOT_TRADE_SIZE_DICT['eng_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['req_btc'] = 1
SPOT_TRADE_SIZE_DICT['oax_btc'] = 1
SPOT_TRADE_SIZE_DICT['dgb_btc'] = 10
SPOT_TRADE_SIZE_DICT['ppt_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['dgb_eth'] = 10
SPOT_TRADE_SIZE_DICT['dgb_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ppt_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['ppt_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['oax_eth'] = 1
SPOT_TRADE_SIZE_DICT['oax_usdt'] = 1
SPOT_TRADE_SIZE_DICT['req_eth'] = 1
SPOT_TRADE_SIZE_DICT['req_usdt'] = 1
SPOT_TRADE_SIZE_DICT['eng_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['eng_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['rcn_eth'] = 10
SPOT_TRADE_SIZE_DICT['rcn_usdt'] = 10
SPOT_TRADE_SIZE_DICT['swftc_btc'] = 10
SPOT_TRADE_SIZE_DICT['swftc_eth'] = 10
SPOT_TRADE_SIZE_DICT['swftc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['rdn_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['rdn_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['rdn_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['xmr_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['xmr_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['xmr_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['xlm_btc'] = 1
SPOT_TRADE_SIZE_DICT['xlm_eth'] = 1
SPOT_TRADE_SIZE_DICT['xlm_usdt'] = 1
SPOT_TRADE_SIZE_DICT['kcash_btc'] = 10
SPOT_TRADE_SIZE_DICT['kcash_eth'] = 10
SPOT_TRADE_SIZE_DICT['kcash_usdt'] = 10
SPOT_TRADE_SIZE_DICT['mdt_btc'] = 10
SPOT_TRADE_SIZE_DICT['mdt_eth'] = 10
SPOT_TRADE_SIZE_DICT['mdt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['nas_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['nas_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['nas_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['rnt_btc'] = 10
SPOT_TRADE_SIZE_DICT['rnt_eth'] = 10
SPOT_TRADE_SIZE_DICT['rnt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['wrc_btc'] = 10
SPOT_TRADE_SIZE_DICT['wrc_eth'] = 10
SPOT_TRADE_SIZE_DICT['wrc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ukg_btc'] = 1
SPOT_TRADE_SIZE_DICT['ukg_eth'] = 1
SPOT_TRADE_SIZE_DICT['ukg_usdt'] = 1
SPOT_TRADE_SIZE_DICT['ugc_btc'] = 10
SPOT_TRADE_SIZE_DICT['ugc_eth'] = 10
SPOT_TRADE_SIZE_DICT['ugc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['dpy_btc'] = 1
SPOT_TRADE_SIZE_DICT['dpy_eth'] = 1
SPOT_TRADE_SIZE_DICT['dpy_usdt'] = 1
SPOT_TRADE_SIZE_DICT['read_btc'] = 10
SPOT_TRADE_SIZE_DICT['read_eth'] = 10
SPOT_TRADE_SIZE_DICT['read_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ssc_btc'] = 10
SPOT_TRADE_SIZE_DICT['ssc_eth'] = 10
SPOT_TRADE_SIZE_DICT['ssc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['aac_btc'] = 10
SPOT_TRADE_SIZE_DICT['smt_btc'] = 10
SPOT_TRADE_SIZE_DICT['fair_btc'] = 10
SPOT_TRADE_SIZE_DICT['aac_eth'] = 10
SPOT_TRADE_SIZE_DICT['smt_eth'] = 10
SPOT_TRADE_SIZE_DICT['aac_usdt'] = 10
SPOT_TRADE_SIZE_DICT['smt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['fair_eth'] = 10
SPOT_TRADE_SIZE_DICT['fair_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ubtc_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['ubtc_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['ubtc_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['cag_btc'] = 1
SPOT_TRADE_SIZE_DICT['cag_eth'] = 1
SPOT_TRADE_SIZE_DICT['cag_usdt'] = 1
SPOT_TRADE_SIZE_DICT['dna_btc'] = 1
SPOT_TRADE_SIZE_DICT['lend_btc'] = 10
SPOT_TRADE_SIZE_DICT['lend_eth'] = 10
SPOT_TRADE_SIZE_DICT['dna_eth'] = 1
SPOT_TRADE_SIZE_DICT['lend_usdt'] = 10
SPOT_TRADE_SIZE_DICT['dna_usdt'] = 1
SPOT_TRADE_SIZE_DICT['rct_btc'] = 10
SPOT_TRADE_SIZE_DICT['rct_eth'] = 10
SPOT_TRADE_SIZE_DICT['rct_usdt'] = 10
SPOT_TRADE_SIZE_DICT['bch_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['show_btc'] = 10
SPOT_TRADE_SIZE_DICT['show_eth'] = 10
SPOT_TRADE_SIZE_DICT['show_usdt'] = 10
SPOT_TRADE_SIZE_DICT['vib_btc'] = 1
SPOT_TRADE_SIZE_DICT['vib_eth'] = 1
SPOT_TRADE_SIZE_DICT['vib_usdt'] = 1
SPOT_TRADE_SIZE_DICT['mot_btc'] = 1
SPOT_TRADE_SIZE_DICT['mot_eth'] = 1
SPOT_TRADE_SIZE_DICT['mot_usdt'] = 1
SPOT_TRADE_SIZE_DICT['utk_btc'] = 10
SPOT_TRADE_SIZE_DICT['utk_eth'] = 10
SPOT_TRADE_SIZE_DICT['utk_usdt'] = 1
SPOT_TRADE_SIZE_DICT['mag_btc'] = 10
SPOT_TRADE_SIZE_DICT['mag_eth'] = 10
SPOT_TRADE_SIZE_DICT['mag_usdt'] = 10
SPOT_TRADE_SIZE_DICT['topc_btc'] = 10
SPOT_TRADE_SIZE_DICT['topc_eth'] = 10
SPOT_TRADE_SIZE_DICT['brd_btc'] = 1
SPOT_TRADE_SIZE_DICT['topc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['qun_btc'] = 10
SPOT_TRADE_SIZE_DICT['brd_eth'] = 1
SPOT_TRADE_SIZE_DICT['qun_eth'] = 10
SPOT_TRADE_SIZE_DICT['qun_usdt'] = 10
SPOT_TRADE_SIZE_DICT['brd_usdt'] = 1
SPOT_TRADE_SIZE_DICT['viu_btc'] = 10
SPOT_TRADE_SIZE_DICT['viu_eth'] = 10
SPOT_TRADE_SIZE_DICT['ost_btc'] = 1
SPOT_TRADE_SIZE_DICT['viu_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ost_eth'] = 1
SPOT_TRADE_SIZE_DICT['ost_usdt'] = 1
SPOT_TRADE_SIZE_DICT['aidoc_btc'] = 10
SPOT_TRADE_SIZE_DICT['aidoc_eth'] = 10
SPOT_TRADE_SIZE_DICT['aidoc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['int_btc'] = 10
SPOT_TRADE_SIZE_DICT['la_btc'] = 1
SPOT_TRADE_SIZE_DICT['la_eth'] = 1
SPOT_TRADE_SIZE_DICT['la_usdt'] = 1
SPOT_TRADE_SIZE_DICT['int_eth'] = 10
SPOT_TRADE_SIZE_DICT['int_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ipc_btc'] = 1
SPOT_TRADE_SIZE_DICT['ipc_eth'] = 1
SPOT_TRADE_SIZE_DICT['ipc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['ngc_btc'] = 1
SPOT_TRADE_SIZE_DICT['ngc_eth'] = 1
SPOT_TRADE_SIZE_DICT['ngc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['tio_btc'] = 1
SPOT_TRADE_SIZE_DICT['tio_eth'] = 1
SPOT_TRADE_SIZE_DICT['tio_usdt'] = 1
SPOT_TRADE_SIZE_DICT['iost_btc'] = 10
SPOT_TRADE_SIZE_DICT['iost_eth'] = 10
SPOT_TRADE_SIZE_DICT['iost_usdt'] = 10
SPOT_TRADE_SIZE_DICT['poe_btc'] = 10
SPOT_TRADE_SIZE_DICT['poe_eth'] = 10
SPOT_TRADE_SIZE_DICT['poe_usdt'] = 10
SPOT_TRADE_SIZE_DICT['mof_btc'] = 1
SPOT_TRADE_SIZE_DICT['yee_btc'] = 10
SPOT_TRADE_SIZE_DICT['mof_eth'] = 1
SPOT_TRADE_SIZE_DICT['yee_eth'] = 10
SPOT_TRADE_SIZE_DICT['yee_usdt'] = 10
SPOT_TRADE_SIZE_DICT['mof_usdt'] = 1
SPOT_TRADE_SIZE_DICT['ins_btc'] = 1
SPOT_TRADE_SIZE_DICT['ins_eth'] = 1
SPOT_TRADE_SIZE_DICT['ins_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['tct_btc'] = 10
SPOT_TRADE_SIZE_DICT['tct_eth'] = 10
SPOT_TRADE_SIZE_DICT['tct_usdt'] = 10
SPOT_TRADE_SIZE_DICT['atl_btc'] = 1
SPOT_TRADE_SIZE_DICT['atl_eth'] = 1
SPOT_TRADE_SIZE_DICT['atl_usdt'] = 1
SPOT_TRADE_SIZE_DICT['theta_btc'] = 10
SPOT_TRADE_SIZE_DICT['theta_eth'] = 10
SPOT_TRADE_SIZE_DICT['lev_btc'] = 10
SPOT_TRADE_SIZE_DICT['theta_usdt'] = 10
SPOT_TRADE_SIZE_DICT['lev_eth'] = 10
SPOT_TRADE_SIZE_DICT['lev_usdt'] = 10
SPOT_TRADE_SIZE_DICT['stc_btc'] = 10
SPOT_TRADE_SIZE_DICT['spf_btc'] = 1
SPOT_TRADE_SIZE_DICT['stc_eth'] = 10
SPOT_TRADE_SIZE_DICT['spf_eth'] = 1
SPOT_TRADE_SIZE_DICT['spf_usdt'] = 1
SPOT_TRADE_SIZE_DICT['stc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ref_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['ref_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['ref_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['snc_btc'] = 1
SPOT_TRADE_SIZE_DICT['snc_eth'] = 1
SPOT_TRADE_SIZE_DICT['snc_usdt'] = 1
SPOT_TRADE_SIZE_DICT['pst_btc'] = 1
SPOT_TRADE_SIZE_DICT['pst_eth'] = 1
SPOT_TRADE_SIZE_DICT['pst_usdt'] = 1
SPOT_TRADE_SIZE_DICT['can_btc'] = 10
SPOT_TRADE_SIZE_DICT['can_eth'] = 10
SPOT_TRADE_SIZE_DICT['can_usdt'] = 10
SPOT_TRADE_SIZE_DICT['hot_btc'] = 10
SPOT_TRADE_SIZE_DICT['mkr_btc'] = 0.001
SPOT_TRADE_SIZE_DICT['mkr_eth'] = 0.001
SPOT_TRADE_SIZE_DICT['mkr_usdt'] = 0.001
SPOT_TRADE_SIZE_DICT['hot_eth'] = 10
SPOT_TRADE_SIZE_DICT['key_btc'] = 10
SPOT_TRADE_SIZE_DICT['hot_usdt'] = 10
SPOT_TRADE_SIZE_DICT['key_eth'] = 10
SPOT_TRADE_SIZE_DICT['key_usdt'] = 10
SPOT_TRADE_SIZE_DICT['light_btc'] = 10
SPOT_TRADE_SIZE_DICT['light_eth'] = 10
SPOT_TRADE_SIZE_DICT['light_usdt'] = 10
SPOT_TRADE_SIZE_DICT['true_btc'] = 1
SPOT_TRADE_SIZE_DICT['true_eth'] = 1
SPOT_TRADE_SIZE_DICT['true_usdt'] = 1
SPOT_TRADE_SIZE_DICT['of_btc'] = 10
SPOT_TRADE_SIZE_DICT['of_eth'] = 10
SPOT_TRADE_SIZE_DICT['of_usdt'] = 10
SPOT_TRADE_SIZE_DICT['soc_btc'] = 10
SPOT_TRADE_SIZE_DICT['soc_eth'] = 10
SPOT_TRADE_SIZE_DICT['soc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['wbtc_btc'] = 10
SPOT_TRADE_SIZE_DICT['dent_btc'] = 10
SPOT_TRADE_SIZE_DICT['dent_eth'] = 10
SPOT_TRADE_SIZE_DICT['dent_usdt'] = 10
SPOT_TRADE_SIZE_DICT['zen_btc'] = 0.01
SPOT_TRADE_SIZE_DICT['zen_eth'] = 0.01
SPOT_TRADE_SIZE_DICT['zen_usdt'] = 0.01
SPOT_TRADE_SIZE_DICT['hmc_btc'] = 10
SPOT_TRADE_SIZE_DICT['hmc_eth'] = 10
SPOT_TRADE_SIZE_DICT['hmc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['zip_btc'] = 10
SPOT_TRADE_SIZE_DICT['zip_eth'] = 10
SPOT_TRADE_SIZE_DICT['zip_usdt'] = 10
SPOT_TRADE_SIZE_DICT['nano_btc'] = 0.1
SPOT_TRADE_SIZE_DICT['nano_eth'] = 0.1
SPOT_TRADE_SIZE_DICT['nano_usdt'] = 0.1
SPOT_TRADE_SIZE_DICT['cic_btc'] = 10
SPOT_TRADE_SIZE_DICT['cic_eth'] = 10
SPOT_TRADE_SIZE_DICT['cic_usdt'] = 10
SPOT_TRADE_SIZE_DICT['gto_btc'] = 1
SPOT_TRADE_SIZE_DICT['gto_eth'] = 1
SPOT_TRADE_SIZE_DICT['gto_usdt'] = 1
SPOT_TRADE_SIZE_DICT['chat_btc'] = 10
SPOT_TRADE_SIZE_DICT['chat_eth'] = 10
SPOT_TRADE_SIZE_DICT['chat_usdt'] = 10
SPOT_TRADE_SIZE_DICT['insur_btc'] = 10
SPOT_TRADE_SIZE_DICT['insur_eth'] = 10
SPOT_TRADE_SIZE_DICT['insur_usdt'] = 10
SPOT_TRADE_SIZE_DICT['cbt_btc'] = 10
SPOT_TRADE_SIZE_DICT['cbt_eth'] = 10
SPOT_TRADE_SIZE_DICT['cbt_usdt'] = 10
SPOT_TRADE_SIZE_DICT['r_btc'] = 1
SPOT_TRADE_SIZE_DICT['r_eth'] = 1
SPOT_TRADE_SIZE_DICT['r_usdt'] = 1
SPOT_TRADE_SIZE_DICT['uct_btc'] = 10
SPOT_TRADE_SIZE_DICT['uct_eth'] = 1
SPOT_TRADE_SIZE_DICT['uct_usdt'] = 1
SPOT_TRADE_SIZE_DICT['bec_btc'] = 1
SPOT_TRADE_SIZE_DICT['bec_eth'] = 1
SPOT_TRADE_SIZE_DICT['bec_usdt'] = 1
SPOT_TRADE_SIZE_DICT['mith_btc'] = 1
SPOT_TRADE_SIZE_DICT['mith_eth'] = 1
SPOT_TRADE_SIZE_DICT['mith_usdt'] = 1
SPOT_TRADE_SIZE_DICT['abt_btc'] = 1
SPOT_TRADE_SIZE_DICT['abt_eth'] = 1
SPOT_TRADE_SIZE_DICT['abt_usdt'] = 1
SPOT_TRADE_SIZE_DICT['bkx_btc'] = 1
SPOT_TRADE_SIZE_DICT['bkx_eth'] = 1
SPOT_TRADE_SIZE_DICT['bkx_usdt'] = 1
SPOT_TRADE_SIZE_DICT['gtc_btc'] = 10
SPOT_TRADE_SIZE_DICT['gtc_eth'] = 10
SPOT_TRADE_SIZE_DICT['gtc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['auto_btc'] = 10
SPOT_TRADE_SIZE_DICT['auto_eth'] = 10
SPOT_TRADE_SIZE_DICT['auto_usdt'] = 10
SPOT_TRADE_SIZE_DICT['gsc_btc'] = 10
SPOT_TRADE_SIZE_DICT['gsc_eth'] = 10
SPOT_TRADE_SIZE_DICT['gsc_usdt'] = 10
SPOT_TRADE_SIZE_DICT['rfr_btc'] = 10
SPOT_TRADE_SIZE_DICT['rfr_eth'] = 10
SPOT_TRADE_SIZE_DICT['rfr_usdt'] = 10
SPOT_TRADE_SIZE_DICT['trio_btc'] = 10
SPOT_TRADE_SIZE_DICT['trio_eth'] = 10
SPOT_TRADE_SIZE_DICT['trio_usdt'] = 10
SPOT_TRADE_SIZE_DICT['tra_btc'] = 10
SPOT_TRADE_SIZE_DICT['tra_eth'] = 10
SPOT_TRADE_SIZE_DICT['tra_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ren_btc'] = 10
SPOT_TRADE_SIZE_DICT['ren_eth'] = 10
SPOT_TRADE_SIZE_DICT['ren_usdt'] = 10
SPOT_TRADE_SIZE_DICT['wfee_btc'] = 10
SPOT_TRADE_SIZE_DICT['wfee_eth'] = 10
SPOT_TRADE_SIZE_DICT['wfee_usdt'] = 10
SPOT_TRADE_SIZE_DICT['dadi_btc'] = 1
SPOT_TRADE_SIZE_DICT['dadi_eth'] = 1
SPOT_TRADE_SIZE_DICT['dadi_usdt'] = 1
SPOT_TRADE_SIZE_DICT['enj_btc'] = 10
SPOT_TRADE_SIZE_DICT['enj_eth'] = 10
SPOT_TRADE_SIZE_DICT['enj_usdt'] = 10
SPOT_TRADE_SIZE_DICT['ont_btc'] = 1
SPOT_TRADE_SIZE_DICT['ont_eth'] = 1
SPOT_TRADE_SIZE_DICT['ont_usdt'] = 1
# -------------------------------------
SPOT_ERROR_DICT = {}
SPOT_ERROR_DICT['1000'] = u'必选参数不能为空'
SPOT_ERROR_DICT['1000'] = u'用户请求频率过快,超过该接口允许的限额'
SPOT_ERROR_DICT['1000'] = u'系统错误'
SPOT_ERROR_DICT['1000'] = u'请求失败'
SPOT_ERROR_DICT['1000'] = u'SecretKey不存在'
SPOT_ERROR_DICT['1000'] = u'Api_key不存在'
SPOT_ERROR_DICT['1000'] = u'签名不匹配'
SPOT_ERROR_DICT['1000'] = u'非法参数'
SPOT_ERROR_DICT['1000'] = u'订单不存在'
SPOT_ERROR_DICT['1001'] = u'余额不足'
SPOT_ERROR_DICT['1001'] = u'买卖的数量小于BTC/LTC最小买卖额度'
SPOT_ERROR_DICT['1001'] = u'当前网站暂时只支持btc_usdltc_usd'
SPOT_ERROR_DICT['1001'] = u'此接口只支持https请求'
SPOT_ERROR_DICT['1001'] = u'下单价格不得≤0或≥'
SPOT_ERROR_DICT['1001'] = u'下单价格与最新成交价偏差过大'
SPOT_ERROR_DICT['1001'] = u'币数量不足'
SPOT_ERROR_DICT['1001'] = u'API鉴权失败'
SPOT_ERROR_DICT['1001'] = u'借入不能小于最低限额[SD:100,BTC:0.1,LTC:1]'
SPOT_ERROR_DICT['1001'] = u'页面没有同意借贷协议'
SPOT_ERROR_DICT['1002'] = u'费率不能大于1%'
SPOT_ERROR_DICT['1002'] = u'费率不能小于0.01%'
SPOT_ERROR_DICT['1002'] = u'获取最新成交价错误'
SPOT_ERROR_DICT['1002'] = u'可借金额不足'
SPOT_ERROR_DICT['1002'] = u'额度已满,暂时无法借款'
SPOT_ERROR_DICT['1002'] = u'借款(含预约借款)及保证金部分不能提出'
SPOT_ERROR_DICT['1002'] = u'修改敏感提币验证信息24小时内不允许提现'
SPOT_ERROR_DICT['1002'] = u'提币金额已超过今日提币限额'
SPOT_ERROR_DICT['1002'] = u'账户有借款,请撤消借款或者还清借款后提币'
SPOT_ERROR_DICT['1003'] = u'存在BTC/LTC充值该部分等值金额需6个网络确认后方能提出'
SPOT_ERROR_DICT['1003'] = u'未绑定手机或谷歌验证'
SPOT_ERROR_DICT['1003'] = u'服务费大于最大网络手续费'
SPOT_ERROR_DICT['1003'] = u'服务费小于最低网络手续费'
SPOT_ERROR_DICT['1003'] = u'可用BTC/LTC不足'
SPOT_ERROR_DICT['1003'] = u'提币数量小于最小提币数量'
SPOT_ERROR_DICT['1003'] = u'交易密码未设置'
SPOT_ERROR_DICT['1004'] = u'取消提币失败'
SPOT_ERROR_DICT['1004'] = u'提币地址不存在或未认证'
SPOT_ERROR_DICT['1004'] = u'交易密码错误'
SPOT_ERROR_DICT['1004'] = u'合约权益错误,提币失败'
SPOT_ERROR_DICT['1004'] = u'取消借款失败'
SPOT_ERROR_DICT['1004'] = u'当前为子账户,此功能未开放'
SPOT_ERROR_DICT['1004'] = u'提币信息不存在'
SPOT_ERROR_DICT['1004'] = u'小额委托(<0.15BTC)的未成交委托数量不得大于50个'
SPOT_ERROR_DICT['1005'] = u'重复撤单'
SPOT_ERROR_DICT['1005'] = u'提币受限'
SPOT_ERROR_DICT['1006'] = u'美元充值后的48小时内该部分资产不能提出'
SPOT_ERROR_DICT['1010'] = u'账户被冻结'
SPOT_ERROR_DICT['1010'] = u'订单类型错误'
SPOT_ERROR_DICT['1010'] = u'不是本用户的订单'
SPOT_ERROR_DICT['1010'] = u'私密订单密钥错误'
SPOT_ERROR_DICT['1021'] = u'非开放API'
SPOT_ERROR_DICT['1002'] = u'交易金额大于余额'
SPOT_ERROR_DICT['1003'] = u'交易金额小于最小交易值'
SPOT_ERROR_DICT['1004'] = u'交易金额小于0'
SPOT_ERROR_DICT['1007'] = u'没有交易市场信息'
SPOT_ERROR_DICT['1008'] = u'没有最新行情信息'
SPOT_ERROR_DICT['1009'] = u'没有订单'
SPOT_ERROR_DICT['1010'] = u'撤销订单与原订单用户不一致'
SPOT_ERROR_DICT['1011'] = u'没有查询到该用户'
SPOT_ERROR_DICT['1013'] = u'没有订单类型'
SPOT_ERROR_DICT['1014'] = u'没有登录'
SPOT_ERROR_DICT['1015'] = u'没有获取到行情深度信息'
SPOT_ERROR_DICT['1017'] = u'日期参数错误'
SPOT_ERROR_DICT['1018'] = u'下单失败'
SPOT_ERROR_DICT['1019'] = u'撤销订单失败'
SPOT_ERROR_DICT['1024'] = u'币种不存在'
SPOT_ERROR_DICT['1025'] = u'没有K线类型'
SPOT_ERROR_DICT['1026'] = u'没有基准币数量'
SPOT_ERROR_DICT['1027'] = u'参数不合法可能超出限制'
SPOT_ERROR_DICT['1028'] = u'保留小数位失败'
SPOT_ERROR_DICT['1029'] = u'正在准备中'
SPOT_ERROR_DICT['1030'] = u'有融资融币无法进行交易'
SPOT_ERROR_DICT['1031'] = u'转账余额不足'
SPOT_ERROR_DICT['1032'] = u'该币种不能转账'
SPOT_ERROR_DICT['1035'] = u'密码不合法'
SPOT_ERROR_DICT['1036'] = u'谷歌验证码不合法'
SPOT_ERROR_DICT['1037'] = u'谷歌验证码不正确'
SPOT_ERROR_DICT['1038'] = u'谷歌验证码重复使用'
SPOT_ERROR_DICT['1039'] = u'短信验证码输错限制'
SPOT_ERROR_DICT['1040'] = u'短信验证码不合法'
SPOT_ERROR_DICT['1041'] = u'短信验证码不正确'
SPOT_ERROR_DICT['1042'] = u'谷歌验证码输错限制'
SPOT_ERROR_DICT['1043'] = u'登陆密码不允许与交易密码一致'
SPOT_ERROR_DICT['1044'] = u'原密码错误'
SPOT_ERROR_DICT['1045'] = u'未设置二次验证'
SPOT_ERROR_DICT['1046'] = u'原密码未输入'
SPOT_ERROR_DICT['1048'] = u'用户被冻结'
SPOT_ERROR_DICT['1050'] = u'订单已撤销或者撤单中'
SPOT_ERROR_DICT['1051'] = u'订单已完成交易'
SPOT_ERROR_DICT['1201'] = u'账号零时删除'
SPOT_ERROR_DICT['1202'] = u'账号不存在'
SPOT_ERROR_DICT['1203'] = u'转账金额大于余额'
SPOT_ERROR_DICT['1204'] = u'不同种币种不能转账'
SPOT_ERROR_DICT['1205'] = u'账号不存在主从关系'
SPOT_ERROR_DICT['1206'] = u'提现用户被冻结'
SPOT_ERROR_DICT['1207'] = u'不支持转账'
SPOT_ERROR_DICT['1208'] = u'没有该转账用户'
SPOT_ERROR_DICT['1209'] = u'当前api不可用'
SPOT_ERROR_DICT['1216'] = u'市价交易暂停,请选择限价交易'
SPOT_ERROR_DICT['1217'] = u'您的委托价格超过最新成交价的±5%,存在风险,请重新下单'
SPOT_ERROR_DICT['1218'] = u'下单失败,请稍后再试'
# --------------------------------------
FUTURES_ERROR_DICT = {}
FUTURES_ERROR_DICT['10000'] = u'必填参数为空'
FUTURES_ERROR_DICT['10001'] = u'参数错误'
FUTURES_ERROR_DICT['10002'] = u'验证失败'
FUTURES_ERROR_DICT['10003'] = u'该连接已经请求了其他用户的实时交易数据'
FUTURES_ERROR_DICT['10004'] = u'该连接没有请求此用户的实时交易数据'
FUTURES_ERROR_DICT['10005'] = u'api_key或者sign不合法'
FUTURES_ERROR_DICT['10008'] = u'非法参数'
FUTURES_ERROR_DICT['10009'] = u'订单不存在'
FUTURES_ERROR_DICT['10010'] = u'余额不足'
FUTURES_ERROR_DICT['10011'] = u'卖的数量小于BTC/LTC最小买卖额度'
FUTURES_ERROR_DICT['10012'] = u'当前网站暂时只支持btc_usdltc_usd'
FUTURES_ERROR_DICT['10014'] = u'下单价格不得≤0或≥1000000'
FUTURES_ERROR_DICT['10015'] = u'暂不支持此channel订阅'
FUTURES_ERROR_DICT['10016'] = u'币数量不足'
FUTURES_ERROR_DICT['10017'] = u'WebSocket鉴权失败'
FUTURES_ERROR_DICT['10100'] = u'用户被冻结'
FUTURES_ERROR_DICT['10049'] = u'小额委托(<0.15BTC)的未成交委托数量不得大于50个'
FUTURES_ERROR_DICT['10216'] = u'非开放API'
FUTURES_ERROR_DICT['20001'] = u'用户不存在'
FUTURES_ERROR_DICT['20002'] = u'用户被冻结'
FUTURES_ERROR_DICT['20003'] = u'用户被爆仓冻结'
FUTURES_ERROR_DICT['20004'] = u'合约账户被冻结'
FUTURES_ERROR_DICT['20005'] = u'用户合约账户不存在'
FUTURES_ERROR_DICT['20006'] = u'必填参数为空'
FUTURES_ERROR_DICT['20007'] = u'参数错误'
FUTURES_ERROR_DICT['20008'] = u'合约账户余额为空'
FUTURES_ERROR_DICT['20009'] = u'虚拟合约状态错误'
FUTURES_ERROR_DICT['20010'] = u'合约风险率信息不存在'
FUTURES_ERROR_DICT['20011'] = u'开仓前保证金率超过90%'
FUTURES_ERROR_DICT['20012'] = u'开仓后保证金率超过90%'
FUTURES_ERROR_DICT['20013'] = u'暂无对手价'
FUTURES_ERROR_DICT['20014'] = u'系统错误'
FUTURES_ERROR_DICT['20015'] = u'订单信息不存在'
FUTURES_ERROR_DICT['20016'] = u'平仓数量是否大于同方向可用持仓数量'
FUTURES_ERROR_DICT['20017'] = u'非本人操作'
FUTURES_ERROR_DICT['20018'] = u'下单价格高于前一分钟的105%或低于95%'
FUTURES_ERROR_DICT['20019'] = u'该IP限制不能请求该资源'
FUTURES_ERROR_DICT['20020'] = u'密钥不存在'
FUTURES_ERROR_DICT['20021'] = u'指数信息不存在'
FUTURES_ERROR_DICT['20022'] = u'接口调用错误'
FUTURES_ERROR_DICT['20023'] = u'逐仓用户'
FUTURES_ERROR_DICT['20024'] = u'sign签名不匹配'
FUTURES_ERROR_DICT['20025'] = u'杠杆比率错误'
FUTURES_ERROR_DICT['20100'] = u'请求超时'
FUTURES_ERROR_DICT['20101'] = u'数据格式无效'
FUTURES_ERROR_DICT['20102'] = u'登录无效'
FUTURES_ERROR_DICT['20103'] = u'数据事件类型无效'
FUTURES_ERROR_DICT['20104'] = u'数据订阅类型无效'
FUTURES_ERROR_DICT['20107'] = u'JSON格式错误'
FUTURES_ERROR_DICT['20115'] = u'quote参数未匹配到'
FUTURES_ERROR_DICT['20116'] = u'参数不匹配'
FUTURES_ERROR_DICT['1002'] = u'交易金额大于余额'
FUTURES_ERROR_DICT['1003'] = u'交易金额小于最小交易值'
FUTURES_ERROR_DICT['1004'] = u'交易金额小于0'
FUTURES_ERROR_DICT['1007'] = u'没有交易市场信息'
FUTURES_ERROR_DICT['1008'] = u'没有最新行情信息'
FUTURES_ERROR_DICT['1009'] = u'没有订单'
FUTURES_ERROR_DICT['1010'] = u'撤销订单与原订单用户不一致'
FUTURES_ERROR_DICT['1011'] = u'没有查询到该用户'
FUTURES_ERROR_DICT['1013'] = u'没有订单类型'
FUTURES_ERROR_DICT['1014'] = u'没有登录'
FUTURES_ERROR_DICT['1015'] = u'没有获取到行情深度信息'
FUTURES_ERROR_DICT['1017'] = u'日期参数错误'
FUTURES_ERROR_DICT['1018'] = u'下单失败'
FUTURES_ERROR_DICT['1019'] = u'撤销订单失败'
FUTURES_ERROR_DICT['1024'] = u'币种不存在'
FUTURES_ERROR_DICT['1025'] = u'没有K线类型'
FUTURES_ERROR_DICT['1026'] = u'没有基准币数量'
FUTURES_ERROR_DICT['1027'] = u'参数不合法可能超出限制'
FUTURES_ERROR_DICT['1028'] = u'保留小数位失败'
FUTURES_ERROR_DICT['1029'] = u'正在准备中'
FUTURES_ERROR_DICT['1030'] = u'有融资融币无法进行交易'
FUTURES_ERROR_DICT['1031'] = u'转账余额不足'
FUTURES_ERROR_DICT['1032'] = u'该币种不能转账'
FUTURES_ERROR_DICT['1035'] = u'密码不合法'
FUTURES_ERROR_DICT['1036'] = u'谷歌验证码不合法'
FUTURES_ERROR_DICT['1037'] = u'谷歌验证码不正确'
FUTURES_ERROR_DICT['1038'] = u'谷歌验证码重复使用'
FUTURES_ERROR_DICT['1039'] = u'短信验证码输错限制'
FUTURES_ERROR_DICT['1040'] = u'短信验证码不合法'
FUTURES_ERROR_DICT['1041'] = u'短信验证码不正确'
FUTURES_ERROR_DICT['1042'] = u'谷歌验证码输错限制'
FUTURES_ERROR_DICT['1043'] = u'登陆密码不允许与交易密码一致'
FUTURES_ERROR_DICT['1044'] = u'原密码错误'
FUTURES_ERROR_DICT['1045'] = u'未设置二次验证'
FUTURES_ERROR_DICT['1046'] = u'原密码未输入'
FUTURES_ERROR_DICT['1048'] = u'用户被冻结'
FUTURES_ERROR_DICT['1050'] = u'订单已撤销或者撤销中'
FUTURES_ERROR_DICT['1051'] = u'订单已完成交易'
FUTURES_ERROR_DICT['1201'] = u'账号零时删除'
FUTURES_ERROR_DICT['1202'] = u'账号不存在'
FUTURES_ERROR_DICT['1203'] = u'转账金额大于余额'
FUTURES_ERROR_DICT['1204'] = u'不同种币种不能转账'
FUTURES_ERROR_DICT['1205'] = u'账号不存在主从关系'
FUTURES_ERROR_DICT['1206'] = u'提现用户被冻结'
FUTURES_ERROR_DICT['1207'] = u'不支持转账'
FUTURES_ERROR_DICT['1208'] = u'没有该转账用户'
FUTURES_ERROR_DICT['1209'] = u'当前api不可用'

51
vnpy/api/okex/test.py Normal file
View File

@ -0,0 +1,51 @@
# encoding: UTF-8
from vnokex import *
# 在OkCoin网站申请这两个Key分别对应用户名和密码
apiKey = '你的apiKey'
secretKey = '你的secretKey'
# 创建API对象
api = OkexSpotApi()
api.connect(apiKey, secretKey, True)
sleep(3)
api.login()
api.subscribeSpotTicker("bch_btc")
api.subscribeSpotDepth("bch_btc")
api.subscribeSpotDepth("bch_btc", 5)
api.subscribeSpotDeals("bch_btc")
api.subscribeSpotKlines("bch_btc","30min")
#api.spotTrade("etc_usdt","sell", "50" , "0.01")
#api.spotCancelOrder("etc_btc","44274138")
#api.spotUserInfo()
#api.spotOrderInfo("etc_btc", 44284731)
# api = OkexFuturesApi()
# api.connect(apiKey, secretKey, True)
# sleep(3)
#api.subsribeFutureTicker("btc","this_week")
#api.subscribeFutureKline("btc","this_week", "30min")
#api.subscribeFutureDepth("btc","this_week")
#api.subscribeFutureDepth("btc","this_week", 5)
#api.subscribeFutureTrades("btc","this_week")
#api.subscribeFutureIndex("btc")
#api.subscribeFutureForecast_price("btc")
#api.login()
#api.futureTrade( "etc_usd", "this_week" ,"1" , 20 , 1 , _match_price = '0' , _lever_rate = '10') # 14245727693
#api.futureCancelOrder("etc_usd","14245727693" , "this_week")
#api.futureUserInfo()
#api.futureOrderInfo("etc_usd" , "14245727693" , "this_week" , '1', '1' , '10')
# api.subscribeFutureTrades()
'''
合约账户信息 持仓信息等在登录后都会自动推送官方文档这样写的还没实际验证过
'''
input()

735
vnpy/api/okex/vnokex.py Normal file
View File

@ -0,0 +1,735 @@
# encoding: UTF-8
import hashlib
import zlib
import json
from time import sleep
from threading import Thread
import traceback
import websocket
import requests
import sys
# API文档 https://github.com/okcoin-okex/OKEx.com-api-docs
from vnpy.api.okex.okexData import SPOT_TRADE_SIZE_DICT,SPOT_ERROR_DICT, FUTURES_ERROR_DICT
# OKEX网站
OKEX_USD_SPOT = 'wss://real.okex.com:10441/websocket' # OKEX (币币交易)现货地址
OKEX_USD_CONTRACT = 'wss://real.okex.com:10440/websocket/okexapi' # OKEX 期货地址
OKEX_CONTRACT_HOST = 'https://www.okex.com/api/v1/future_hold_amount.do?symbol=%s_usd&contract_type=%s' # 合约持仓查询地址
SPOT_CURRENCY = ["usdt",
"btc",
"ltc",
"eth",
"etc",
"bch"]
SPOT_SYMBOL = ["ltc_btc",
"eth_btc",
"etc_btc",
"bch_btc",
"btc_usdt",
"eth_usdt",
"ltc_usdt",
"etc_usdt",
"bch_usdt",
"etc_eth",
"bt1_btc",
"bt2_btc",
"btg_btc",
"qtum_btc",
"hsr_btc",
"neo_btc",
"gas_btc",
"qtum_usdt",
"hsr_usdt",
"neo_usdt",
"gas_usdt"]
KLINE_PERIOD = ["1min","3min","5min","15min","30min","1hour","2hour","4hour","6hour","12hour","day","3day","week"]
CONTRACT_SYMBOL = ["btc","ltc","eth","etc","bch","eos","xrp","btg"]
# 合约类型 当周,下周,季度
CONTRACT_TYPE = ["this_week", "next_week", "quarter"]
########################################################################
class OkexApi(object):
"""交易接口"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
self.host = '' # 服务器
self.apiKey = '' # 用户名
self.secretKey = '' # 密码
self.ws = None # websocket应用对象 现货对象
self.thread = None # 初始化线程
#----------------------------------------------------------------------
def reconnect(self):
"""重新连接"""
# 首先关闭之前的连接
self.close()
# 再执行重连任务
self.ws = websocket.WebSocketApp(self.host,
on_message=self.onMessage,
on_error=self.onError,
on_close=self.onClose,
on_open=self.onOpen)
self.thread = Thread(target=self.ws.run_forever)
self.thread.start()
#----------------------------------------------------------------------
def connect(self, apiKey, secretKey, trace=False):
"""
连接网关
:param apiKey : 申请的API key
:param secretKey: 签名key
:param trace : 是否开启websocket的日志跟踪功能输出到StreamHandler
:return:
"""
# 更新websocket服务器地址/API key/
self.host = OKEX_USD_SPOT
self.apiKey = apiKey
self.secretKey = secretKey
# 是否开启日志
websocket.enableTrace(trace)
# 创建websocket绑定本地回调函数 onMessage/onError/onClose/onOpen
self.ws = websocket.WebSocketApp(self.host,
on_message=self.onMessage,
on_error=self.onError,
on_close=self.onClose,
on_open=self.onOpen)
self.thread = Thread(target=self.ws.run_forever)
self.thread.start()
#----------------------------------------------------------------------
def readData(self, evt):
"""
解码推送收到的数据
:param evt:
:return:
"""
data = json.loads(evt)
return data
#----------------------------------------------------------------------
def close(self):
"""
关闭接口
:return:
"""
if self.thread and self.thread.isAlive():
print(u'vnokex.close')
self.ws.close()
self.thread.join()
#----------------------------------------------------------------------
def onMessage(self, ws, evt):
"""
信息推送事件
:param ws: 接口
:param evt: 事件
:return:
"""
print(u'vnokex.onMessage:{}'.format(evt))
#----------------------------------------------------------------------
def onError(self, ws, evt):
"""
接口错误推送事件
:param ws:
:param evt:
:return:
"""
print(u'vnokex.onApiError:{}'.format(evt))
#----------------------------------------------------------------------
def onClose(self, ws):
"""
接口断开事件
:param ws:
:return:
"""
print(u'vnokex.onClose')
#----------------------------------------------------------------------
def onOpen(self, ws):
"""
接口打开事件
:param ws:
:return:
"""
print(u'vnokex.onOpen')
#----------------------------------------------------------------------
def generateSign(self, params):
"""生成签名"""
print(u'vnokex.generateSign')
l = []
for key in sorted(params.keys()):
l.append('%s=%s' %(key, params[key]))
l.append('secret_key=%s' %self.secretKey)
sign = '&'.join(l)
return hashlib.md5(sign.encode('utf-8')).hexdigest().upper()
#----------------------------------------------------------------------
def sendTradingRequest(self, channel, params):
"""发送交易请求"""
print(u'vnokex.sendTradingRequest')
# 在参数字典中加上api_key和签名字段
params['api_key'] = self.apiKey
params['sign'] = self.generateSign(params)
# 生成请求
d = {}
d['event'] = 'addChannel'
d['channel'] = channel
d['parameters'] = params
# 使用json打包并发送
j = json.dumps(d)
# 若触发异常则重连
try:
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'vnokex.sendTradingRequest Exception:{}'.format(str(ex)),file=sys.stderr)
#----------------------------------------------------------------------
def sendDataRequest(self, channel):
"""发送数据请求"""
print(u'vnokex.sendDataRequest')
d = {}
d['event'] = 'addChannel'
d['channel'] = channel
j = json.dumps(d)
# 若触发异常则重连
try:
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'vnokex.sendDataRequest Exception:{},{}'.format(str(ex),traceback.format_exc()), file=sys.stderr)
except Exception as ex:
print(u'vnokex.sendDataRequest Exception:{},{}'.format(str(ex),traceback.format_exc()), file=sys.stderr)
def sendHeartBeat(self):
"""
发送心跳
:return:
"""
d = {'event': 'ping'}
# 若触发异常则重连
try:
print(u'vnokex.sendHeartBeat')
j = json.dumps(d)
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'vnokex.sendHeartBeat Exception:{}'.format(str(ex)), file=sys.stderr)
#----------------------------------------------------------------------
def login(self):
"""
登录
:return: True/False
"""
print(u'vnokex.login()')
params = {}
params['api_key'] = self.apiKey
params['sign'] = self.generateSign(params)
# 生成请求
d = {}
d['event'] = 'login'
d['parameters'] = params
# 使用json打包并发送
j = json.dumps(d)
# 若触发异常则重连
try:
self.ws.send(j)
return True
except websocket.WebSocketConnectionClosedException as ex:
print(u'vnokex.login exception:{},{}'.format(str(ex), traceback.format_exc()), file=sys.stderr)
return False
########################################################################
class WsSpotApi(OkexApi):
"""现货交易接口"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
super(WsSpotApi, self).__init__()
#----------------------------------------------------------------------
def subscribeSpotTicker(self, symbol):
print(u'vnokex.subscribeSpotTicker:{}'.format(symbol))
"""订阅现货的Tick"""
channel = 'ok_sub_spot_%s_ticker' %symbol
self.sendDataRequest(channel)
#----------------------------------------------------------------------
def subscribeSpotDepth(self, symbol, depth=0):
"""订阅现货的深度"""
print(u'vnokex.subscribeSpotDepth:{}'.format(symbol))
channel = 'ok_sub_spot_%s_depth' %symbol
if depth:
channel = channel + '_' + str(depth)
self.sendDataRequest(channel)
#----------------------------------------------------------------------
def subscribeSpotDeals(self, symbol):
"""
订阅成交记录
:param symbol:
:return:
"""
print(u'vnokex.subscribeSpotDeals:{}'.format(symbol))
channel = 'ok_sub_spot_%s_deals' %symbol
self.sendDataRequest(channel)
#----------------------------------------------------------------------
def subscribeSpotKlines(self, symbol, period):
"""
订阅K线数据
:param symbol:
:param period:
:return:
"""
print(u'vnokex.subscribeSpotKlines:{} {}'.format(symbol,period))
channel = 'ok_sub_spot_%s_kline_%s' %(symbol, period)
self.sendDataRequest(channel)
#----------------------------------------------------------------------
def spotTrade(self, symbol, type_, price, amount):
"""现货委托"""
print(u'vnokex.stopTrade:symbol:{} type:{} price:{} amount:{}'.format(symbol, type_, price,amount))
params = {}
params['symbol'] = str(symbol)
params['type'] = str(type_)
params['price'] = str(price)
params['amount'] = str(amount)
channel = 'ok_spot_order'
self.sendTradingRequest(channel, params)
#----------------------------------------------------------------------
def spotCancelOrder(self, symbol, orderid):
"""
现货撤单指令
:param symbol:现货合约
:param orderid:
:return:
"""
print(u'vnokex.spotCancelOrder:{} orderid:{}'.format(symbol, orderid))
params = {}
params['symbol'] = str(symbol)
params['order_id'] = str(orderid)
channel = 'ok_spot_cancel_order'
self.sendTradingRequest(channel, params)
#----------------------------------------------------------------------
def spotUserInfo(self):
"""
查询现货账户"
:return:
"""""
print(u'vnokex.spotUserInfo()')
channel = 'ok_spot_userinfo'
self.sendTradingRequest(channel, {})
#----------------------------------------------------------------------
def spotOrderInfo(self, symbol, orderid):
"""
查询现货委托信息
:param symbol: 现货合约
:param orderid: 委托编号
:return:
"""
print(u'vnokex.spotOrderInfo:{},orderid:{}'.format(symbol,orderid))
params = {}
params['symbol'] = str(symbol)
params['order_id'] = str(orderid)
channel = 'ok_spot_orderinfo'
self.sendTradingRequest(channel, params)
########################################################################
'''
OKEX 合约接口
[{
"channel": "btc_forecast_price",
"timestamp":"1490341322021",
"data": "998.8"
}]
data(string): 预估交割价格
timestamp(string): 时间戳
操作说明
无需订阅交割前一小时自动返回
这段数据交割前会自动返回
'''
class WsFuturesApi(object):
# ----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
self.apiKey = '' # 用户名
self.secretKey = '' # 密码
self.ws = None # websocket应用对象 期货对象
self.active = False # 还存活
self.use_lever_rate = 10
self.trace = False
# -----------------------------------------------------------------------
def connect(self, apiKey, secretKey, trace=False):
self.host = OKEX_USD_CONTRACT
self.apiKey = apiKey
self.secretKey = secretKey
self.trace = trace
websocket.enableTrace(trace)
self.ws = websocket.WebSocketApp(self.host,
on_message=self.onMessage,
on_error=self.onError,
on_close=self.onClose,
on_open=self.onOpen)
self.thread = Thread(target=self.ws.run_forever, args=(None, None, 60, 30))
self.thread.start()
# ----------------------------------------------------------------------
def http_get_request(self, url, params, add_to_headers=None, TIMEOUT=5):
headers = {
"Content-type": "application/x-www-form-urlencoded",
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0'
}
if add_to_headers:
headers.update(add_to_headers)
#postdata = urllib.urlencode(params)
try:
# response = requests.get(url, postdata, headers=headers, timeout=TIMEOUT)
response = requests.get(url, headers=headers, timeout=TIMEOUT)
if response.status_code == 200:
return response.json()
else:
return {"status": "fail"}
except Exception as e:
print(u'httpGet failed :{}'.format(str(e)), file=sys.stderr)
return {"status": "fail", "msg": e}
# ----------------------------------------------------------------------
def getContractName(self, symbol_no_usd, contract_type):
try:
url = OKEX_CONTRACT_HOST % (symbol_no_usd, contract_type)
data = self.http_get_request(url, {})
if type(data) == type([]) and len(data) > 0:
d1 = data[0]
contract_name = d1["contract_name"]
return contract_name
except Exception as ex:
print(u'OkexContractApi.getContractName exception:{},{}'.format(str(ex),traceback.format_exc()), file=sys.stderr)
return None
def sendHeartBeat(self):
"""
发送心跳
:return:
"""
d = {'event': 'ping'}
# 若触发异常则重连
try:
print(u'vnokex.futuresApi.sendHeartBeat')
j = json.dumps(d)
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'vnokex.futuresApi.sendHeartBeat Exception:{}'.format(str(ex)), file=sys.stderr)
# ----------------------------------------------------------------------
def close(self):
"""关闭接口"""
if self.thread and self.thread.isAlive():
self.ws.close()
self.thread.join()
# ----------------------------------------------------------------------
def readData(self, evt):
"""解压缩推送收到的数据"""
# # 创建解压器
# decompress = zlib.decompressobj(-zlib.MAX_WBITS)
# # 将原始数据解压成字符串
# inflated = decompress.decompress(evt) + decompress.flush()
# 通过json解析字符串
# data = json.loads(inflated)
data = json.loads(evt)
return data
# ----------------------------------------------------------------------
def onMessage(self, ws, evt):
"""信息推送"""
print(evt)
# ----------------------------------------------------------------------
def onError(self, ws, evt):
"""错误推送"""
print('OkexContractApi.onError:{}'.format(evt))
# ----------------------------------------------------------------------
def onClose(self, ws):
"""接口断开"""
print('OkexContractApi.onClose')
# ----------------------------------------------------------------------
def onOpen(self, ws):
"""接口打开"""
print('OkexContractApi.onOpen')
def subsribeFutureTicker(self, symbol, contract_type):
req = "{'event':'addChannel','channel':'ok_sub_futureusd_%s_ticker_%s'}" % (symbol, contract_type)
self.ws.send(req)
def subscribeFutureKline(self, symbol, contract_type, time_period):
req = "{'event':'addChannel','channel':'ok_sub_futureusd_%s_kline_%s_%s'}" % (
symbol, contract_type, time_period)
self.ws.send(req)
def subscribeFutureDepth(self, symbol, contract_type):
req = "{'event':'addChannel','channel':'ok_sub_future_%s_depth_%s_usd'}" % (symbol, contract_type)
self.ws.send(req)
def subscribeFutureDepth20(self, symbol, contract_type):
req = "{'event':'addChannel','channel':'ok_sub_futureusd_%s_depth_%s_20'}" % (symbol, contract_type)
self.ws.send(req)
def subscribeFutureTrades(self, symbol, contract_type):
req = "{'event':'addChannel','channel':'ok_sub_futureusd_%s_trade_%s'}" % (symbol, contract_type)
self.ws.send(req)
def subscribeFutureIndex(self, symbol):
req = "{'event':'addChannel','channel':'ok_sub_futureusd_%s_index'}" % (symbol)
self.ws.send(req)
# ----------------------------------------------------------------------
def generateSign(self, params):
"""生成签名"""
l = []
for key in sorted(params.keys()):
l.append('%s=%s' % (key, params[key]))
l.append('secret_key=%s' % self.secretKey)
sign = '&'.join(l)
return hashlib.md5(sign.encode('utf-8')).hexdigest().upper()
# ----------------------------------------------------------------------
def sendTradingRequest(self, channel, params):
"""发送交易请求"""
# 在参数字典中加上api_key和签名字段
params['api_key'] = self.apiKey
params['sign'] = self.generateSign(params)
# 生成请求
d = {}
d['event'] = 'addChannel'
d['channel'] = channel
d['parameters'] = params
# 使用json打包并发送
j = json.dumps(d)
# 若触发异常则重连
try:
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'OkexContractApi.sendTradingRequest exception:{},{}'.format(str(ex),traceback.format_exc()), file=sys.stderr)
except Exception as ex:
print(u'OkexContractApi.sendTradingRequest exception:{},{}'.format(str(ex), traceback.format_exc()), file=sys.stderr)
# ----------------------------------------------------------------------
def login(self):
"""
登录
:return:
"""
params = {}
params['api_key'] = self.apiKey
params['sign'] = self.generateSign(params)
# 生成请求
d = {}
d['event'] = 'login'
d['parameters'] = params
# 使用json打包并发送
j = json.dumps(d)
# 若触发异常则重连
try:
self.ws.send(j)
except websocket.WebSocketConnectionClosedException as ex:
print(u'OkexContractApi.login exception:{},{}'.format(str(ex), traceback.format_exc()), file=sys.stderr)
except Exception as ex:
print(u'OkexContractApi.login exception:{},{}'.format(str(ex), traceback.format_exc()), file=sys.stderr)
# ----------------------------------------------------------------------
def futureSubscribeIndex(self, symbol):
"""
订阅期货合约指数行情
:param symbol: 合约
:return:
"""
channel = 'ok_sub_futureusd_%s_index' % symbol
self.sendTradingRequest(channel, {})
# ----------------------------------------------------------------------
def futureAllIndexSymbol(self):
"""
订阅所有的期货合约指数行情
:return:
"""
for symbol in CONTRACT_SYMBOL:
self.futureSubscribeIndex(symbol)
# ----------------------------------------------------------------------
def futureTrade(self, symbol_pair, contract_type, type_, price, amount, _match_price='0', _lever_rate=None):
"""期货委托"""
params = {}
params['symbol'] = str(symbol_pair)
params['contract_type'] = str(contract_type)
params['price'] = str(price)
params['amount'] = str(amount)
params['type'] = type_ # 1:开多 2:开空 3:平多 4:平空
params['match_price'] = _match_price # 是否为对手价: 0:不是 1:是 当取值为1时,price无效
if _lever_rate != None:
params['lever_rate'] = _lever_rate
else:
params['lever_rate'] = str(self.use_lever_rate)
channel = 'ok_futureusd_trade'
self.sendTradingRequest(channel, params)
# ----------------------------------------------------------------------
def futureCancelOrder(self, symbol_pair, orderid, contract_type):
"""
期货撤单指令
:param symbol_pair: 合约对
:param orderid: 委托单编号
:param contract_type: 合约类型
:return:
"""
params = {}
params['symbol'] = str(symbol_pair)
params['order_id'] = str(orderid)
params['contract_type'] = str(contract_type)
channel = 'ok_futureusd_cancel_order'
self.sendTradingRequest(channel, params)
# ----------------------------------------------------------------------
def futureUserInfo(self):
"""查询期货账户"""
channel = 'ok_futureusd_userinfo'
self.sendTradingRequest(channel, {})
# ----------------------------------------------------------------------
# def futureSubUserInfo(self):
# channel = 'ok_sub_futureusd_userinfo'
# self.sendTradingRequest(channel, {})
# ----------------------------------------------------------------------
def futureOrderInfo(self, symbol_pair, order_id, contract_type, status, current_page, page_length=50):
"""
发出查询期货委托
:param symbol_pair: 合约对
:param order_id: 委托单编号
:param contract_type: 合约类型
:param status: 状态
:param current_page:当前页
:param page_length: 每页长度
:return:
"""
params = {}
params['symbol'] = str(symbol_pair)
params['order_id'] = str(order_id)
params['contract_type'] = str(contract_type)
params['status'] = str(status)
params['current_page'] = str(current_page)
params['page_length'] = str(page_length)
channel = 'ok_futureusd_orderinfo'
self.sendTradingRequest(channel, params)
# ----------------------------------------------------------------------
def futureAllUnfinishedOrderInfo(self):
"""
订阅所有未完成的委托单信息
:return:
"""
for symbol in CONTRACT_SYMBOL:
symbol_usd = symbol + "_usd"
for contract_type in CONTRACT_TYPE:
# orderid = -1,
self.futureOrderInfo(symbol_usd, -1, contract_type, 1, 1, 50)
# ----------------------------------------------------------------------
def subscribeFutureTrades(self):
"""
订阅期货成交回报
:return:
"""
channel = 'ok_sub_futureusd_trades'
self.sendTradingRequest(channel, {})
# ----------------------------------------------------------------------
def subscribeFutureUserInfo(self):
"""订阅期货账户信息"""
channel = 'ok_sub_futureusd_userinfo'
self.sendTradingRequest(channel, {})
# ----------------------------------------------------------------------
def subscribeFuturePositions(self):
"""订阅期货持仓信息"""
channel = 'ok_sub_futureusd_positions'
self.sendTradingRequest(channel, {})

View File

@ -0,0 +1,6 @@
{
"apiKey": "你的apiKey",
"secretKey": "你的secretKey",
"trace": false,
"leverage": 10
}

View File

@ -0,0 +1,11 @@
# encoding: UTF-8
from vnpy.trader import vtConstant
from vnpy.trader.gateway.okexGateway.okexGateway import OkexGateway
gatewayClass = OkexGateway
gatewayName = 'OKEX'
gatewayDisplayName = u'OKEX'
gatewayType = vtConstant.GATEWAYTYPE_BTC
gatewayQryEnabled = True

File diff suppressed because it is too large Load Diff