diff --git a/vnpy/api/okex/__init__.py b/vnpy/api/okex/__init__.py index cf2a383b..960b69d0 100644 --- a/vnpy/api/okex/__init__.py +++ b/vnpy/api/okex/__init__.py @@ -1,3 +1,3 @@ # encoding: UTF-8 -from vnpy.api.okex.vnokex import WsSpotApi, WsFuturesApi,SPOT_SYMBOL, CONTRACT_SYMBOL, SPOT_CURRENCY,CONTRACT_TYPE \ No newline at end of file +from vnpy.api.okex.vnokex import WsSpotApi, WsFuturesApi,SPOT_SYMBOL_PAIRS, CONTRACT_SYMBOL, SPOT_CURRENCY,CONTRACT_TYPE \ No newline at end of file diff --git a/vnpy/api/okex/okexData.py b/vnpy/api/okex/okexData.py index 9eb73ec0..621e3b69 100644 --- a/vnpy/api/okex/okexData.py +++ b/vnpy/api/okex/okexData.py @@ -498,110 +498,210 @@ 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'下单失败,请稍后再试' +# --- REST API ERROR CODE------------------------------------- +SPOT_REST_ERROR_DICT = {} +SPOT_REST_ERROR_DICT['1000'] = u'必选参数不能为空' +SPOT_REST_ERROR_DICT['1000'] = u'用户请求频率过快,超过该接口允许的限额' +SPOT_REST_ERROR_DICT['1000'] = u'系统错误' +SPOT_REST_ERROR_DICT['1000'] = u'请求失败' +SPOT_REST_ERROR_DICT['1000'] = u'SecretKey不存在' +SPOT_REST_ERROR_DICT['1000'] = u'Api_key不存在' +SPOT_REST_ERROR_DICT['1000'] = u'签名不匹配' +SPOT_REST_ERROR_DICT['1000'] = u'非法参数' +SPOT_REST_ERROR_DICT['1000'] = u'订单不存在' +SPOT_REST_ERROR_DICT['1001'] = u'余额不足' +SPOT_REST_ERROR_DICT['1001'] = u'买卖的数量小于BTC/LTC最小买卖额度' +SPOT_REST_ERROR_DICT['1001'] = u'当前网站暂时只支持btc_usdltc_usd' +SPOT_REST_ERROR_DICT['1001'] = u'此接口只支持https请求' +SPOT_REST_ERROR_DICT['1001'] = u'下单价格不得≤0或≥' +SPOT_REST_ERROR_DICT['1001'] = u'下单价格与最新成交价偏差过大' +SPOT_REST_ERROR_DICT['1001'] = u'币数量不足' +SPOT_REST_ERROR_DICT['1001'] = u'API鉴权失败' +SPOT_REST_ERROR_DICT['1001'] = u'借入不能小于最低限额[SD:100,BTC:0.1,LTC:1]' +SPOT_REST_ERROR_DICT['1001'] = u'页面没有同意借贷协议' +SPOT_REST_ERROR_DICT['1002'] = u'费率不能大于1%' +SPOT_REST_ERROR_DICT['1002'] = u'费率不能小于0.01%' +SPOT_REST_ERROR_DICT['1002'] = u'获取最新成交价错误' +SPOT_REST_ERROR_DICT['1002'] = u'可借金额不足' +SPOT_REST_ERROR_DICT['1002'] = u'额度已满,暂时无法借款' +SPOT_REST_ERROR_DICT['1002'] = u'借款(含预约借款)及保证金部分不能提出' +SPOT_REST_ERROR_DICT['1002'] = u'修改敏感提币验证信息,24小时内不允许提现' +SPOT_REST_ERROR_DICT['1002'] = u'提币金额已超过今日提币限额' +SPOT_REST_ERROR_DICT['1002'] = u'账户有借款,请撤消借款或者还清借款后提币' +SPOT_REST_ERROR_DICT['1003'] = u'存在BTC/LTC充值,该部分等值金额需6个网络确认后方能提出' +SPOT_REST_ERROR_DICT['1003'] = u'未绑定手机或谷歌验证' +SPOT_REST_ERROR_DICT['1003'] = u'服务费大于最大网络手续费' +SPOT_REST_ERROR_DICT['1003'] = u'服务费小于最低网络手续费' +SPOT_REST_ERROR_DICT['1003'] = u'可用BTC/LTC不足' +SPOT_REST_ERROR_DICT['1003'] = u'提币数量小于最小提币数量' +SPOT_REST_ERROR_DICT['1003'] = u'交易密码未设置' +SPOT_REST_ERROR_DICT['1004'] = u'取消提币失败' +SPOT_REST_ERROR_DICT['1004'] = u'提币地址不存在或未认证' +SPOT_REST_ERROR_DICT['1004'] = u'交易密码错误' +SPOT_REST_ERROR_DICT['1004'] = u'合约权益错误,提币失败' +SPOT_REST_ERROR_DICT['1004'] = u'取消借款失败' +SPOT_REST_ERROR_DICT['1004'] = u'当前为子账户,此功能未开放' +SPOT_REST_ERROR_DICT['1004'] = u'提币信息不存在' +SPOT_REST_ERROR_DICT['1004'] = u'小额委托(<0.15BTC)的未成交委托数量不得大于50个' +SPOT_REST_ERROR_DICT['1005'] = u'重复撤单' +SPOT_REST_ERROR_DICT['1005'] = u'提币受限' +SPOT_REST_ERROR_DICT['1006'] = u'美元充值后的48小时内,该部分资产不能提出' +SPOT_REST_ERROR_DICT['1010'] = u'账户被冻结' +SPOT_REST_ERROR_DICT['1010'] = u'订单类型错误' +SPOT_REST_ERROR_DICT['1010'] = u'不是本用户的订单' +SPOT_REST_ERROR_DICT['1010'] = u'私密订单密钥错误' +SPOT_REST_ERROR_DICT['1021'] = u'非开放API' +SPOT_REST_ERROR_DICT['1002'] = u'交易金额大于余额' +SPOT_REST_ERROR_DICT['1003'] = u'交易金额小于最小交易值' +SPOT_REST_ERROR_DICT['1004'] = u'交易金额小于0' +SPOT_REST_ERROR_DICT['1007'] = u'没有交易市场信息' +SPOT_REST_ERROR_DICT['1008'] = u'没有最新行情信息' +SPOT_REST_ERROR_DICT['1009'] = u'没有订单' +SPOT_REST_ERROR_DICT['1010'] = u'撤销订单与原订单用户不一致' +SPOT_REST_ERROR_DICT['1011'] = u'没有查询到该用户' +SPOT_REST_ERROR_DICT['1013'] = u'没有订单类型' +SPOT_REST_ERROR_DICT['1014'] = u'没有登录' +SPOT_REST_ERROR_DICT['1015'] = u'没有获取到行情深度信息' +SPOT_REST_ERROR_DICT['1017'] = u'日期参数错误' +SPOT_REST_ERROR_DICT['1018'] = u'下单失败' +SPOT_REST_ERROR_DICT['1019'] = u'撤销订单失败' +SPOT_REST_ERROR_DICT['1024'] = u'币种不存在' +SPOT_REST_ERROR_DICT['1025'] = u'没有K线类型' +SPOT_REST_ERROR_DICT['1026'] = u'没有基准币数量' +SPOT_REST_ERROR_DICT['1027'] = u'参数不合法可能超出限制' +SPOT_REST_ERROR_DICT['1028'] = u'保留小数位失败' +SPOT_REST_ERROR_DICT['1029'] = u'正在准备中' +SPOT_REST_ERROR_DICT['1030'] = u'有融资融币无法进行交易' +SPOT_REST_ERROR_DICT['1031'] = u'转账余额不足' +SPOT_REST_ERROR_DICT['1032'] = u'该币种不能转账' +SPOT_REST_ERROR_DICT['1035'] = u'密码不合法' +SPOT_REST_ERROR_DICT['1036'] = u'谷歌验证码不合法' +SPOT_REST_ERROR_DICT['1037'] = u'谷歌验证码不正确' +SPOT_REST_ERROR_DICT['1038'] = u'谷歌验证码重复使用' +SPOT_REST_ERROR_DICT['1039'] = u'短信验证码输错限制' +SPOT_REST_ERROR_DICT['1040'] = u'短信验证码不合法' +SPOT_REST_ERROR_DICT['1041'] = u'短信验证码不正确' +SPOT_REST_ERROR_DICT['1042'] = u'谷歌验证码输错限制' +SPOT_REST_ERROR_DICT['1043'] = u'登陆密码不允许与交易密码一致' +SPOT_REST_ERROR_DICT['1044'] = u'原密码错误' +SPOT_REST_ERROR_DICT['1045'] = u'未设置二次验证' +SPOT_REST_ERROR_DICT['1046'] = u'原密码未输入' +SPOT_REST_ERROR_DICT['1048'] = u'用户被冻结' +SPOT_REST_ERROR_DICT['1050'] = u'订单已撤销或者撤单中' +SPOT_REST_ERROR_DICT['1051'] = u'订单已完成交易' +SPOT_REST_ERROR_DICT['1201'] = u'账号零时删除' +SPOT_REST_ERROR_DICT['1202'] = u'账号不存在' +SPOT_REST_ERROR_DICT['1203'] = u'转账金额大于余额' +SPOT_REST_ERROR_DICT['1204'] = u'不同种币种不能转账' +SPOT_REST_ERROR_DICT['1205'] = u'账号不存在主从关系' +SPOT_REST_ERROR_DICT['1206'] = u'提现用户被冻结' +SPOT_REST_ERROR_DICT['1207'] = u'不支持转账' +SPOT_REST_ERROR_DICT['1208'] = u'没有该转账用户' +SPOT_REST_ERROR_DICT['1209'] = u'当前api不可用' +SPOT_REST_ERROR_DICT['1216'] = u'市价交易暂停,请选择限价交易' +SPOT_REST_ERROR_DICT['1217'] = u'您的委托价格超过最新成交价的±5%,存在风险,请重新下单' +SPOT_REST_ERROR_DICT['1218'] = u'下单失败,请稍后再试' + +SPORT_WS_ERROR_DICT = {} +SPORT_WS_ERROR_DICT['10000'] = u'必填参数为空' +SPORT_WS_ERROR_DICT['10001'] = u'参数错误' +SPORT_WS_ERROR_DICT['10002'] = u'验证失败' +SPORT_WS_ERROR_DICT['10003'] = u'该连接已经请求了其他用户的实时交易数据' +SPORT_WS_ERROR_DICT['10004'] = u'该连接没有请求此用户的实时交易数据' +SPORT_WS_ERROR_DICT['10005'] = u'api_key或者sign不合法' +SPORT_WS_ERROR_DICT['10008'] = u'非法参数' +SPORT_WS_ERROR_DICT['10009'] = u'订单不存在' +SPORT_WS_ERROR_DICT['10010'] = u'余额不足' +SPORT_WS_ERROR_DICT['10011'] = u'卖的数量小于BTC/LTC最小买卖额度' +SPORT_WS_ERROR_DICT['10012'] = u'当前网站暂时只支持btc_usdltc_usd' +SPORT_WS_ERROR_DICT['10014'] = u'下单价格不得≤0或≥1000000' +SPORT_WS_ERROR_DICT['10015'] = u'暂不支持此channel订阅' +SPORT_WS_ERROR_DICT['10016'] = u'币数量不足' +SPORT_WS_ERROR_DICT['10017'] = u'WebSocket鉴权失败' +SPORT_WS_ERROR_DICT['10100'] = u'用户被冻结' +SPORT_WS_ERROR_DICT['10049'] = u'小额委托(<0.15BTC)的未成交委托数量不得大于50个' +SPORT_WS_ERROR_DICT['10216'] = u'非开放API' +SPORT_WS_ERROR_DICT['20001'] = u'用户不存在' +SPORT_WS_ERROR_DICT['20002'] = u'用户被冻结' +SPORT_WS_ERROR_DICT['20003'] = u'用户被爆仓冻结' +SPORT_WS_ERROR_DICT['20004'] = u'合约账户被冻结' +SPORT_WS_ERROR_DICT['20005'] = u'用户合约账户不存在' +SPORT_WS_ERROR_DICT['20006'] = u'必填参数为空' +SPORT_WS_ERROR_DICT['20007'] = u'参数错误' +SPORT_WS_ERROR_DICT['20008'] = u'合约账户余额为空' +SPORT_WS_ERROR_DICT['20009'] = u'虚拟合约状态错误' +SPORT_WS_ERROR_DICT['20010'] = u'合约风险率信息不存在' +SPORT_WS_ERROR_DICT['20011'] = u'开仓前保证金率超过90%' +SPORT_WS_ERROR_DICT['20012'] = u'开仓后保证金率超过90%' +SPORT_WS_ERROR_DICT['20013'] = u'暂无对手价' +SPORT_WS_ERROR_DICT['20014'] = u'系统错误' +SPORT_WS_ERROR_DICT['20015'] = u'订单信息不存在' +SPORT_WS_ERROR_DICT['20016'] = u'平仓数量是否大于同方向可用持仓数量' +SPORT_WS_ERROR_DICT['20017'] = u'非本人操作' +SPORT_WS_ERROR_DICT['20018'] = u'下单价格高于前一分钟的105%或低于95%' +SPORT_WS_ERROR_DICT['20019'] = u'该IP限制不能请求该资源' +SPORT_WS_ERROR_DICT['20020'] = u'密钥不存在' +SPORT_WS_ERROR_DICT['20021'] = u'指数信息不存在' +SPORT_WS_ERROR_DICT['20022'] = u'接口调用错误' +SPORT_WS_ERROR_DICT['20023'] = u'逐仓用户' +SPORT_WS_ERROR_DICT['20024'] = u'sign签名不匹配' +SPORT_WS_ERROR_DICT['20025'] = u'杠杆比率错误' +SPORT_WS_ERROR_DICT['20100'] = u'请求超时' +SPORT_WS_ERROR_DICT['20101'] = u'数据格式无效' +SPORT_WS_ERROR_DICT['20102'] = u'登录无效' +SPORT_WS_ERROR_DICT['20103'] = u'数据事件类型无效' +SPORT_WS_ERROR_DICT['20104'] = u'数据订阅类型无效' +SPORT_WS_ERROR_DICT['20107'] = u'JSON格式错误' +SPORT_WS_ERROR_DICT['20115'] = u'quote参数未匹配到' +SPORT_WS_ERROR_DICT['20116'] = u'参数不匹配' +SPORT_WS_ERROR_DICT['1002'] = u'交易金额大于余额' +SPORT_WS_ERROR_DICT['1003'] = u'交易金额小于最小交易值' +SPORT_WS_ERROR_DICT['1004'] = u'交易金额小于0' +SPORT_WS_ERROR_DICT['1007'] = u'没有交易市场信息' +SPORT_WS_ERROR_DICT['1008'] = u'没有最新行情信息' +SPORT_WS_ERROR_DICT['1009'] = u'没有订单' +SPORT_WS_ERROR_DICT['1010'] = u'撤销订单与原订单用户不一致' +SPORT_WS_ERROR_DICT['1011'] = u'没有查询到该用户' +SPORT_WS_ERROR_DICT['1013'] = u'没有订单类型' +SPORT_WS_ERROR_DICT['1014'] = u'没有登录' +SPORT_WS_ERROR_DICT['1015'] = u'没有获取到行情深度信息' +SPORT_WS_ERROR_DICT['1017'] = u'日期参数错误' +SPORT_WS_ERROR_DICT['1018'] = u'下单失败' +SPORT_WS_ERROR_DICT['1019'] = u'撤销订单失败' +SPORT_WS_ERROR_DICT['1024'] = u'币种不存在' +SPORT_WS_ERROR_DICT['1025'] = u'没有K线类型' +SPORT_WS_ERROR_DICT['1026'] = u'没有基准币数量' +SPORT_WS_ERROR_DICT['1027'] = u'参数不合法可能超出限制' +SPORT_WS_ERROR_DICT['1028'] = u'保留小数位失败' +SPORT_WS_ERROR_DICT['1029'] = u'正在准备中' +SPORT_WS_ERROR_DICT['1030'] = u'有融资融币无法进行交易' +SPORT_WS_ERROR_DICT['1031'] = u'转账余额不足' +SPORT_WS_ERROR_DICT['1032'] = u'该币种不能转账' +SPORT_WS_ERROR_DICT['1035'] = u'密码不合法' +SPORT_WS_ERROR_DICT['1036'] = u'谷歌验证码不合法' +SPORT_WS_ERROR_DICT['1037'] = u'谷歌验证码不正确' +SPORT_WS_ERROR_DICT['1038'] = u'谷歌验证码重复使用' +SPORT_WS_ERROR_DICT['1039'] = u'短信验证码输错限制' +SPORT_WS_ERROR_DICT['1040'] = u'短信验证码不合法' +SPORT_WS_ERROR_DICT['1041'] = u'短信验证码不正确' +SPORT_WS_ERROR_DICT['1042'] = u'谷歌验证码输错限制' +SPORT_WS_ERROR_DICT['1043'] = u'登陆密码不允许与交易密码一致' +SPORT_WS_ERROR_DICT['1044'] = u'原密码错误' +SPORT_WS_ERROR_DICT['1045'] = u'未设置二次验证' +SPORT_WS_ERROR_DICT['1046'] = u'原密码未输入' +SPORT_WS_ERROR_DICT['1048'] = u'用户被冻结' +SPORT_WS_ERROR_DICT['1050'] = u'订单已撤销或者撤销中' +SPORT_WS_ERROR_DICT['1051'] = u'订单已完成交易' +SPORT_WS_ERROR_DICT['1201'] = u'账号零时删除' +SPORT_WS_ERROR_DICT['1202'] = u'账号不存在' +SPORT_WS_ERROR_DICT['1203'] = u'转账金额大于余额' +SPORT_WS_ERROR_DICT['1204'] = u'不同种币种不能转账' +SPORT_WS_ERROR_DICT['1205'] = u'账号不存在主从关系' +SPORT_WS_ERROR_DICT['1206'] = u'提现用户被冻结' +SPORT_WS_ERROR_DICT['1207'] = u'不支持转账' +SPORT_WS_ERROR_DICT['1208'] = u'没有该转账用户' +SPORT_WS_ERROR_DICT['1209'] = u'当前api不可用' # -------------------------------------- FUTURES_ERROR_DICT = {} diff --git a/vnpy/api/okex/test.py b/vnpy/api/okex/test.py index 01cfc2dd..64596373 100644 --- a/vnpy/api/okex/test.py +++ b/vnpy/api/okex/test.py @@ -7,7 +7,7 @@ apiKey = '你的apiKey' secretKey = '你的secretKey' # 创建API对象 -api = OkexSpotApi() +api = WsSpotApi() api.connect(apiKey, secretKey, True) diff --git a/vnpy/api/okex/vnokex.py b/vnpy/api/okex/vnokex.py index 9ed9b29c..9c7f5121 100644 --- a/vnpy/api/okex/vnokex.py +++ b/vnpy/api/okex/vnokex.py @@ -12,7 +12,7 @@ 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 +from vnpy.api.okex.okexData import SPOT_TRADE_SIZE_DICT,SPOT_REST_ERROR_DICT, FUTURES_ERROR_DICT # OKEX网站 OKEX_USD_SPOT = 'wss://real.okex.com:10441/websocket' # OKEX (币币交易)现货地址 @@ -27,7 +27,7 @@ SPOT_CURRENCY = ["usdt", "etc", "bch"] -SPOT_SYMBOL = ["ltc_btc", +SPOT_SYMBOL_PAIRS = set(["ltc_btc", "eth_btc", "etc_btc", "bch_btc", @@ -46,8 +46,8 @@ SPOT_SYMBOL = ["ltc_btc", "gas_btc", "qtum_usdt", "hsr_usdt", - "neo_usdt", - "gas_usdt"] + "neo_usdt", + "gas_usdt"]) KLINE_PERIOD = ["1min","3min","5min","15min","30min","1hour","2hour","4hour","6hour","12hour","day","3day","week"] @@ -326,9 +326,15 @@ class WsSpotApi(OkexApi): params = {} params['symbol'] = str(symbol) params['type'] = str(type_) - params['price'] = str(price) - params['amount'] = str(amount) - + + if str(type_) == 'buy' or str(type_) == 'sell': + params['price'] = str(price) + params['amount'] = str(amount) + elif str(type_) == 'buy_market': + params['type'] = str(type_) + elif str(type_) == 'sell_market': + params['amount'] = str(amount) + channel = 'ok_spot_order' self.sendRequest(channel, params) diff --git a/vnpy/trader/gateway/okexGateway/okexGateway.py b/vnpy/trader/gateway/okexGateway/okexGateway.py index 26eb30d0..ba9adac3 100644 --- a/vnpy/trader/gateway/okexGateway/okexGateway.py +++ b/vnpy/trader/gateway/okexGateway/okexGateway.py @@ -17,8 +17,8 @@ from threading import Thread from time import sleep import traceback -from vnpy.api.okex import WsSpotApi, WsFuturesApi, SPOT_SYMBOL, CONTRACT_SYMBOL, CONTRACT_TYPE, SPOT_CURRENCY -from vnpy.api.okex.okexData import SPOT_TRADE_SIZE_DICT, SPOT_ERROR_DICT, FUTURES_ERROR_DICT +from vnpy.api.okex import WsSpotApi, WsFuturesApi, SPOT_SYMBOL_PAIRS, CONTRACT_SYMBOL, CONTRACT_TYPE, SPOT_CURRENCY +from vnpy.api.okex.okexData import SPOT_TRADE_SIZE_DICT, SPOT_REST_ERROR_DICT, SPORT_WS_ERROR_DICT, FUTURES_ERROR_DICT from vnpy.trader.vtGateway import * from vnpy.trader.vtFunction import getJsonPath @@ -68,6 +68,9 @@ class OkexGateway(VtGateway): self.leverage = 0 self.spot_connected = False # 现货交易接口连接状态 + self.use_spot_symbol_pairs = set() # 使用现货合约对(从配置文件读取,减少运算量) + self.auto_subscribe_symbol_pairs = set() # 自动订阅现货合约对清单 + self.futures_connected = False # 期货交易接口连接状态 self.qryCount = 0 # 查询触发倒计时 @@ -82,6 +85,7 @@ class OkexGateway(VtGateway): # 消息调试 self.log_message = False + self.qryFunctionList = [] # ---------------------------------------------------------------------- def connect(self): """连接""" @@ -98,19 +102,34 @@ class OkexGateway(VtGateway): apiKey = str(setting['apiKey']) secretKey = str(setting['secretKey']) trace = setting['trace'] - self.leverage = setting['leverage'] if 'leverage' in setting else 0 + self.leverage = setting.get('leverage', 1) spot_connect = setting['spot_connect'] futures_connect = setting['futures_connect'] - self.log_message = setting['log_message'] if 'log_message' in setting else False + self.log_message = setting.get('log_message', False) + # 若限定使用的合约对 + if "symbol_pairs" in setting.keys(): + self.use_spot_symbol_pairs = set(setting["symbol_pairs"]) + + # 若希望连接后自动订阅 + if 'auto_subscribe' in setting.keys(): + self.auto_subscribe_symbol_pairs = set(setting['auto_subscribe']) + + self.qryEnabled = setting.get('qryEnabled', True) except KeyError: self.writeError(u'OkexGateway.connect:连接配置缺少字段,请检查') return if spot_connect: self.api_spot.active = True + + for symbol_pair in self.auto_subscribe_symbol_pairs: + self.writeLog(u'自动订阅现货合约:{}'.format(symbol_pair)) + self.api_spot.registerSymbolPairArray.add(symbol_pair) + self.api_spot.connect(apiKey, secretKey, trace) self.writeLog(u'connect okex ws spot api') + self.api_spot.setSymbolPairs(self.use_spot_symbol_pairs) if futures_connect: self.api_futures.active = True @@ -126,29 +145,6 @@ class OkexGateway(VtGateway): self.initQuery() self.startQuery() - def writeLog(self, content): - """ - 记录日志文件 - :param content: - :return: - """ - if self.logger: - self.logger.info(content) - - def writeError(self, content, error_id = 0): - """ - 发送错误通知/记录日志文件 - :param content: - :return: - """ - error = VtErrorData() - error.gatewayName = self.gatewayName - error.errorID = error_id - error.errorMsg = content - self.onError(error) - - if self.logger: - self.logger.error(content) def checkStatus(self): return self.spot_connected or self.futures_connected @@ -166,12 +162,12 @@ class OkexGateway(VtGateway): # 提取品种对 eth_usdt symbol_pair = arr[0] - if symbol_pair in SPOT_SYMBOL: + if symbol_pair in SPOT_SYMBOL_PAIRS: if self.api_spot and self.spot_connected: self.api_spot.subscribe(subscribeReq) else: self.writeError(u'现货接口未创建/未连接,无法调用subscribe') - + self.auto_subscribe_symbol_pairs.add(symbol_pair) else: if self.api_futures and self.futures_connected: self.api_futures.subscribe(subscribeReq) @@ -190,7 +186,7 @@ class OkexGateway(VtGateway): order_req_symbol = orderReq.symbol order_req_symbol = order_req_symbol.replace('.{}'.format(EXCHANGE_OKEX),'') - if order_req_symbol in SPOT_SYMBOL: + if order_req_symbol in SPOT_SYMBOL_PAIRS: if self.api_spot and self.spot_connected: return self.api_spot.spotSendOrder(orderReq) else: @@ -205,11 +201,19 @@ class OkexGateway(VtGateway): # ---------------------------------------------------------------------- def cancelOrder(self, cancelOrderReq): """撤单""" - if self.spot_connected: - self.api_spot.spotCancel(cancelOrderReq) - - if self.futures_connected: - self.api_futures.futureCancel(cancelOrderReq) + # btc_usdt.OKEX => btc_usdt + order_req_symbol = cancelOrderReq.symbol + order_req_symbol = order_req_symbol.replace('.{}'.format(EXCHANGE_OKEX), '') + if order_req_symbol in SPOT_SYMBOL_PAIRS: + if self.spot_connected: + self.api_spot.spotCancel(cancelOrderReq) + else: + self.writeError(u'现货接口未创建/连接,无法调用cancelOrder') + else: + if self.futures_connected: + self.api_futures.futureCancel(cancelOrderReq) + else: + self.writeError(u'期货接口未创建/连接,无法调用cancelOrder') # ---------------------------------------------------------------------- def qryAccount(self): @@ -348,12 +352,29 @@ class OkexSpotApi(WsSpotApi): self.tradeID = 0 + # 缺省启动得品种对队列 + self.use_symbol_pairs = set([]) + # 已登记的品种对队列 self.registerSymbolPairArray = set([]) # 初始化回调函数 self.initCallback() + def setSymbolPairs(self, symbol_pairs): + """ + 设置合约对 + :param symbol_pairs: set[] + :return: + """ + if isinstance(symbol_pairs ,list): + self.use_symbol_pairs = set(symbol_pairs) + + elif isinstance(symbol_pairs, set): + self.use_symbol_pairs = symbol_pairs + + self.gateway.writeLog(u'设置合约对:{}'.format(symbol_pairs)) + ''' 登录后,每次订单执行撤销后又这样的 推送。。不知道干啥的。先过滤掉了 {u'binary': 1, u'product': u'spot', u'type': u'order', u'base': u'etc' @@ -416,7 +437,6 @@ class OkexSpotApi(WsSpotApi): self.gateway.writeLog(u'功能订阅请求:{} 成功:'.format(channel_value)) continue - # 其他回调/数据推送 callback = self.cbDict.get(channel_value) if callback: @@ -426,7 +446,7 @@ class OkexSpotApi(WsSpotApi): self.gateway.writeError(u'Spot {}回调函数处理异常,请查日志'.format(channel_value)) self.gateway.writeLog(u'Spot onMessage call back {} exception:{},{}'.format(channel_value, str(ex),traceback.format_exc())) else: - self.gateway.writeError(u'Spot unkonw msg:{}'.format(data)) + self.gateway.writeError(u'Spot unkown msg:{}'.format(data)) # ---------------------------------------------------------------------- def onError(self, ws, evt): @@ -443,7 +463,7 @@ class OkexSpotApi(WsSpotApi): error.gatewayName = self.gatewayName if 'data' in data and 'error_code' in data['data']: error_code =data['data']['error_code'] - error.errorMsg = u'SpotApi 出错:{}'.format(SPOT_ERROR_DICT.get(str(error_code))) + error.errorMsg = u'SpotApi 出错:{}'.format(SPORT_WS_ERROR_DICT.get(str(error_code))) error.errorID = error_code else: error.errorMsg = str(data) @@ -507,8 +527,9 @@ class OkexSpotApi(WsSpotApi): :param symbol:合约(对) :return: """ + self.gateway.writeLog(u'SpotApi.subscribeSingleSymbol({})'.format(symbol)) - if symbol in SPOT_TRADE_SIZE_DICT: + if symbol in SPOT_SYMBOL_PAIRS: # 订阅行情数据 self.subscribeSpotTicker(symbol) # 订阅委托深度 @@ -516,7 +537,7 @@ class OkexSpotApi(WsSpotApi): # 订阅该合约的委托成交回报(所有人,不是你得账号) #self.subscribeSpotDeals(symbol) else: - self.gateway.writeError(u'SpotApi:订阅失败,{}不在SPOT_TRADE_SIZE_DICT中,'.format(symbol)) + self.gateway.writeError(u'SpotApi:订阅失败,{}不在SPOT_SYMBOL_PAIRS中,'.format(symbol)) # ---------------------------------------------------------------------- def spotAllOrders(self): @@ -528,7 +549,7 @@ class OkexSpotApi(WsSpotApi): # 根据已登记的品种对清单,逐一发委托查询 for symbol in self.registerSymbolPairArray: - if symbol in SPOT_TRADE_SIZE_DICT: + if symbol in SPOT_SYMBOL_PAIRS: self.spotOrderInfo(symbol, '-1') # 对已经发送委托,根据orderid,发出查询请求 @@ -554,23 +575,9 @@ class OkexSpotApi(WsSpotApi): # 连接后查询现货账户和委托数据 self.spotUserInfo() - # 尝试订阅一个合约对 - if len(self.registerSymbolPairArray) == 0: - #self.subscribeSingleSymbol("etc_usdt") - #self.subscribeSingleSymbol("btc_usdt") - self.registerSymbolPairArray.add('eth_usdt') - self.registerSymbolPairArray.add('btc_usdt') - self.registerSymbolPairArray.add('ltc_usdt') - - for symbol_pair in self.registerSymbolPairArray: - # 发起品种行情订阅请求 - self.subscribeSingleSymbol(symbol_pair) - # 查询该品种对的订单 - self.spotOrderInfo(symbol_pair, '-1') - self.gateway.writeLog(u'SpotApi初始化合约信息') - - for symbol in SPOT_TRADE_SIZE_DICT: + # 如果有缺省得使用合约对,就仅初始化这些合约对,否则全部初始化 + for symbol in SPOT_SYMBOL_PAIRS if len(self.use_symbol_pairs) == 0 else self.use_symbol_pairs: # self.subscribeSpotTicker(symbol) # self.subscribeSpotDepth5(symbol) # self.subscribeSpotDeals(symbol) @@ -595,6 +602,13 @@ class OkexSpotApi(WsSpotApi): contract.productClass = PRODUCT_SPOT self.gateway.onContract(contract) + # 对所有登记得品种对,发起订阅 + for symbol_pair in self.registerSymbolPairArray: + # 发起品种行情订阅请求 + self.subscribeSingleSymbol(symbol_pair) + # 查询该品种对的订单 + self.spotOrderInfo(symbol_pair, '-1') + ''' [{ "channel":"ok_sub_spot_bch_btc_deals", @@ -618,7 +632,7 @@ class OkexSpotApi(WsSpotApi): :return: """ # USD_SPOT 把每一个币币交易对的回调函数登记在字典中 - for symbol_pair in SPOT_TRADE_SIZE_DICT: + for symbol_pair in SPOT_SYMBOL_PAIRS: self.cbDict["ok_sub_spot_%s_ticker" % symbol_pair] = self.onTicker # 该币对的行情数据回报 self.cbDict["ok_sub_spot_%s_depth_5" % symbol_pair] = self.onDepth # 该币对的委托深度回报 self.cbDict["ok_sub_spot_%s_deals" % symbol_pair] = self.onSpotSubDeals # 该币对的成交记录回报 @@ -1229,8 +1243,13 @@ nel': u'ok_sub_spot_etc_usdt_order'} if 'error_code' in data: error_id = data.get('error_code') - self.gateway.writeError(u'SpotApi.onSpotOrder 委托返回错误:{}'.format(SPOT_ERROR_DICT.get(str(error_id))), error_id=error_id) + self.gateway.writeError(u'SpotApi.onSpotOrder 委托返回错误:{}'.format(SPORT_WS_ERROR_DICT.get(str(error_id))), error_id=error_id) self.gateway.writeLog(ws_data) + + # 特殊处理服务超时得异常 + if str(error_id) == '20100': + return + localNo = self.localNoQueue.get_nowait() self.gateway.writeLog(u'移除本地localNo:{}'.format(localNo)) vtOrderId = '.'.join([self.gatewayName,localNo]) @@ -1238,7 +1257,7 @@ nel': u'ok_sub_spot_etc_usdt_order'} if order is not None: order.status = STATUS_REJECTED order.updateTime = datetime.now().strftime("%H:%M:%S.%f") - self.gateway.writeLog(u'发出OnOrder,拒单,vtOrderId={}'.format(vtOrderId)) + self.gateway.writeLog(u'发出OnOrder,拒单,vtOrderId={},错误:{},error_id:{}'.format(vtOrderId, SPORT_WS_ERROR_DICT.get(str(error_id)), error_id)) # 发送现货委托单(拒单消息)到vtGateway self.gateway.onOrder(order) return @@ -1284,7 +1303,7 @@ nel': u'ok_sub_spot_etc_usdt_order'} if 'error_code' in data: error_id = data.get('error_code') - self.gateway.writeError(u'SpotApi.onSpotCancelOrder 委托返回错误:{}'.format(SPOT_ERROR_DICT.get(str(error_id))), error_id=error_id) + self.gateway.writeError(u'SpotApi.onSpotCancelOrder 委托返回错误:{}'.format(SPORT_WS_ERROR_DICT.get(str(error_id))), error_id=error_id) self.gateway.writeLog(ws_data) return