[Mod] 将Enum改为普通的object
[Mod] onFailed增加一个errorCode参数
This commit is contained in:
parent
8c971c7d81
commit
4878b3291b
@ -1,5 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
from enum import Enum
|
||||
from typing import Any, Callable, List, Union
|
||||
|
||||
from vnpy.api.okexfuture.vnokexFuture import OkexFutureRestBase
|
||||
@ -16,7 +15,7 @@ class _OkexFutureCustomExtra(object):
|
||||
|
||||
|
||||
########################################################################
|
||||
class OkexFutureSymbol(Enum):
|
||||
class OkexFutureSymbol(object):
|
||||
BTC = 'btc_usd'
|
||||
LTC = 'ltc_usd'
|
||||
ETH = 'eth_usd'
|
||||
@ -25,20 +24,20 @@ class OkexFutureSymbol(Enum):
|
||||
|
||||
|
||||
########################################################################
|
||||
class OkexFuturePriceType(Enum):
|
||||
class OkexFuturePriceType(object):
|
||||
Buy = 'buy'
|
||||
Sell = 'sell'
|
||||
|
||||
|
||||
########################################################################
|
||||
class OkexFutureContractType(Enum):
|
||||
class OkexFutureContractType(object):
|
||||
ThisWeek = 'this_week'
|
||||
NextWeek = 'next_week'
|
||||
Quarter = 'quarter'
|
||||
|
||||
|
||||
########################################################################
|
||||
class OkexFutureOrderType(Enum):
|
||||
class OkexFutureOrderType(object):
|
||||
OpenLong = '1'
|
||||
OpenShort = '2'
|
||||
CloseLong = '3'
|
||||
@ -46,7 +45,7 @@ class OkexFutureOrderType(Enum):
|
||||
|
||||
|
||||
########################################################################
|
||||
class OkexFutureOrderStatus(Enum):
|
||||
class OkexFutureOrderStatus(object):
|
||||
NotFinished = '1'
|
||||
Finished = '2'
|
||||
|
||||
@ -143,7 +142,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
def sendOrder(self, symbol, contractType, orderType, volume,
|
||||
onSuccess, onFailed=None,
|
||||
price=None, useMarketPrice=False, leverRate=None,
|
||||
extra=None): # type:(str, OkexFutureContractType, OkexFutureOrderType, float, Callable[[int, Any], Any], Callable[[Any], Any], float, bool, Union[int, None], Any)->Request
|
||||
extra=None): # type:(str, OkexFutureContractType, OkexFutureOrderType, float, Callable[[int, Any], Any], Callable[[int, Any], Any], float, bool, Union[int, None], Any)->Request
|
||||
"""
|
||||
:param symbol: str
|
||||
:param contractType: OkexFutureContractType
|
||||
@ -181,7 +180,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def cancelOrder(self, symbol, contractType, orderId, onSuccess, onFailed=None,
|
||||
extra=None): # type: (str, OkexFutureContractType, str, Callable[[object], Any], Callable[[Any], Any], Any)->Request
|
||||
extra=None): # type: (str, OkexFutureContractType, str, Callable[[object], Any], Callable[[int, Any], Any], Any)->Request
|
||||
"""
|
||||
:param symbol: str
|
||||
:param contractType: OkexFutureContractType
|
||||
@ -204,7 +203,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def queryOrder(self, symbol, contractType, orderId, onSuccess, onFailed=None,
|
||||
extra=None): # type: (str, OkexFutureContractType, str, Callable[[OkexFutureOrder, Any], Any], Callable[[Any], Any], Any)->Request
|
||||
extra=None): # type: (str, OkexFutureContractType, str, Callable[[OkexFutureOrder, Any], Any], Callable[[int, Any], Any], Any)->Request
|
||||
"""
|
||||
:param symbol: str
|
||||
:param contractType: OkexFutureContractType
|
||||
@ -229,7 +228,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
def queryOrders(self, symbol, contractType, status,
|
||||
onSuccess, onFailed=None,
|
||||
pageIndex=None, pageLength=50,
|
||||
extra=None): # type: (str, OkexFutureContractType, OkexFutureOrderStatus, Callable[[OkexFutureOrder, Any], Any], Callable[[Any], Any], int, int, Any)->Request
|
||||
extra=None): # type: (str, OkexFutureContractType, OkexFutureOrderStatus, Callable[[OkexFutureOrder, Any], Any], Callable[[int, Any], Any], int, int, Any)->Request
|
||||
"""
|
||||
:param symbol: str
|
||||
:param contractType: OkexFutureContractType
|
||||
@ -257,7 +256,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def queryUserInfo(self, onSuccess, onFailed=None,
|
||||
extra=None): # type: (Callable[[List[OkexFutureUserInfo], Any], Any], Callable[[Any], Any], Any)->Request
|
||||
extra=None): # type: (Callable[[List[OkexFutureUserInfo], Any], Any], Callable[[int, Any], Any], Any)->Request
|
||||
"""
|
||||
查询用户信息
|
||||
:param onSuccess: (userInfos: List[OkexFutureUserInfo], extra: Any)->Any
|
||||
@ -273,7 +272,7 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
#----------------------------------------------------------------------
|
||||
def queryPosition(self, symbol, contractType,
|
||||
onSuccess, onFailed=None,
|
||||
extra=None): # type: (str, OkexFutureContractType, Callable[[OkexFuturePosition, Any], Any], Callable[[Any], Any], Any)->Request
|
||||
extra=None): # type: (str, OkexFutureContractType, Callable[[OkexFuturePosition, Any], Any], Callable[[int, Any], Any], Any)->Request
|
||||
data = {
|
||||
'symbol': symbol,
|
||||
'contractType': contractType
|
||||
@ -296,7 +295,10 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
extra.onSuccess(remoteId, extra.extra)
|
||||
else:
|
||||
if extra.onFailed:
|
||||
extra.onFailed(extra.extra)
|
||||
code = 0
|
||||
if 'error_code' in data:
|
||||
code = data['error_code']
|
||||
extra.onFailed(code, extra.extra)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@staticmethod
|
||||
@ -310,7 +312,10 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
extra.onSuccess(extra.extra)
|
||||
else:
|
||||
if extra.onFailed:
|
||||
extra.onFailed(extra.extra)
|
||||
code = 0
|
||||
if 'error_code' in data:
|
||||
code = data['error_code']
|
||||
extra.onFailed(code, extra.extra)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@staticmethod
|
||||
@ -338,7 +343,10 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
extra.onSuccess(okexOrder, extra.extra)
|
||||
else:
|
||||
if extra.onFailed:
|
||||
extra.onFailed(extra.extra)
|
||||
code = 0
|
||||
if 'error_code' in data:
|
||||
code = data['error_code']
|
||||
extra.onFailed(code, extra.extra)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@staticmethod
|
||||
@ -359,7 +367,10 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
extra.onSuccess(uis, extra.extra)
|
||||
else:
|
||||
if extra.onFailed:
|
||||
extra.onFailed(extra.extra)
|
||||
code = 0
|
||||
if 'error_code' in data:
|
||||
code = data['error_code']
|
||||
extra.onFailed(code, extra.extra)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@staticmethod
|
||||
@ -390,4 +401,60 @@ class OkexFutureRestClient(OkexFutureRestBase):
|
||||
extra.onSuccess(pos, extra.extra)
|
||||
else:
|
||||
if extra.onFailed:
|
||||
extra.onFailed(extra.extra)
|
||||
code = 0
|
||||
if 'error_code' in data:
|
||||
code = data['error_code']
|
||||
extra.onFailed(code, extra.extra)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@staticmethod
|
||||
def errorCode2String(code):
|
||||
assert code in errorCodeMap
|
||||
return errorCodeMap[code]
|
||||
|
||||
|
||||
errorCodeMap = {
|
||||
0: '远程服务器并未给出错误代码',
|
||||
|
||||
20001: '用户不存在',
|
||||
20002: '用户被冻结',
|
||||
20003: '用户被爆仓冻结',
|
||||
20004: '合约账户被冻结',
|
||||
20005: '用户合约账户不存在',
|
||||
20006: '必填参数为空',
|
||||
20007: '参数错误',
|
||||
20008: '合约账户余额为空',
|
||||
20009: '虚拟合约状态错误',
|
||||
20010: '合约风险率信息不存在',
|
||||
20011: '10倍/20倍杠杆开BTC前保证金率低于90%/80%,10倍/20倍杠杆开LTC前保证金率低于80%/60%',
|
||||
20012: '10倍/20倍杠杆开BTC后保证金率低于90%/80%,10倍/20倍杠杆开LTC后保证金率低于80%/60%',
|
||||
20013: '暂无对手价',
|
||||
20014: '系统错误',
|
||||
20015: '订单信息不存在',
|
||||
20016: '平仓数量是否大于同方向可用持仓数量',
|
||||
20017: '非本人操作',
|
||||
20018: '下单价格高于前一分钟的103%或低于97%',
|
||||
20019: '该IP限制不能请求该资源',
|
||||
20020: '密钥不存在',
|
||||
20021: '指数信息不存在',
|
||||
20022: '接口调用错误(全仓模式调用全仓接口,逐仓模式调用逐仓接口)',
|
||||
20023: '逐仓用户',
|
||||
20024: 'sign签名不匹配',
|
||||
20025: '杠杆比率错误',
|
||||
20026: 'API鉴权错误',
|
||||
20027: '无交易记录',
|
||||
20028: '合约不存在',
|
||||
20029: '转出金额大于可转金额',
|
||||
20030: '账户存在借款',
|
||||
20038: '根据相关法律,您所在的国家或地区不能使用该功能。',
|
||||
20049: '用户请求接口过于频繁',
|
||||
20061: '合约相同方向只支持一个杠杆,若有10倍多单,就不能再下20倍多单',
|
||||
21005: '请求接口失败,请您重试',
|
||||
21020: '合约交割中,无法下单',
|
||||
21021: '合约清算中,无法下单',
|
||||
21023: '当前全仓方向仓位已超过最大可开张数',
|
||||
21024: '当前逐仓方向仓位已超过最大可开张数',
|
||||
21025: '下单后保证金率小于对应档位要求的最低保证金率',
|
||||
21026: '您的账户已被限制开仓操作',
|
||||
20119: '接口已下线或无法使用',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user