[Mod]修改okexGateway部分实现

This commit is contained in:
vn.py 2017-12-18 09:38:10 +08:00
parent 680c0dd535
commit 7a255ae4cf

View File

@ -1,10 +1,10 @@
# encoding: UTF-8 # encoding: UTF-8
''' '''
vn.okex的gateway接入 vnpy.api.okex的gateway接入
注意 注意
1. 前仅支持USD 现货交易以及usd的期货交易 1. 前仅支持USD现货交易
''' '''
import os import os
@ -17,7 +17,7 @@ from Queue import Queue
from threading import Thread from threading import Thread
from time import sleep from time import sleep
from vnpy.api.okex import OKEX_Sub_Spot_Api , OKEX_Contract_Api , okex_all_symbol_pairs , okex_all_contract_symbol , okex_all_symbol_type from vnpy.api.okex import OkexSpotApi, CONTRACT_SYMBOL, SPOT_CURRENCY
from vnpy.trader.vtGateway import * from vnpy.trader.vtGateway import *
from vnpy.trader.vtFunction import getJsonPath from vnpy.trader.vtFunction import getJsonPath
@ -40,13 +40,15 @@ statusMap[4] = STATUS_UNKNOWN
######################################################################## ########################################################################
class okexGateway(VtGateway): class OkexGateway(VtGateway):
"""OKEX交易接口"""
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def __init__(self, eventEngine, gatewayName='OKEX'): def __init__(self, eventEngine, gatewayName='OKEX'):
"""Constructor""" """Constructor"""
super(okexGateway, self).__init__(eventEngine, gatewayName) super(OkexGateway, self).__init__(eventEngine, gatewayName)
self.api_spot = Api_Spot(self) self.api_spot = SpotApi(self)
# self.api_contract = Api_contract(self) # self.api_contract = Api_contract(self)
self.leverage = 0 self.leverage = 0
@ -85,9 +87,8 @@ class okexGateway(VtGateway):
# 初始化接口 # 初始化接口
self.leverage = leverage self.leverage = leverage
self.api_spot.active = True self.api_spot.active = True
self.api_spot.connect_Subpot( apiKey, secretKey, trace) self.api_spot.connect(apiKey, secretKey, trace)
log = VtLogData() log = VtLogData()
log.gatewayName = self.gatewayName log.gatewayName = self.gatewayName
@ -107,6 +108,7 @@ class okexGateway(VtGateway):
def sendOrder(self, orderReq): def sendOrder(self, orderReq):
"""发单""" """发单"""
return self.api_spot.spotSendOrder(orderReq) return self.api_spot.spotSendOrder(orderReq)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def cancelOrder(self, cancelOrderReq): def cancelOrder(self, cancelOrderReq):
"""撤单""" """撤单"""
@ -116,6 +118,7 @@ class okexGateway(VtGateway):
def qryAccount(self): def qryAccount(self):
"""查询账户资金""" """查询账户资金"""
self.api_spot.spotUserInfo() self.api_spot.spotUserInfo()
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def qryOrderInfo(self): def qryOrderInfo(self):
self.api_spot.spotAllOrders() self.api_spot.spotAllOrders()
@ -176,18 +179,16 @@ class okexGateway(VtGateway):
######################################################################## ########################################################################
class Api_Spot(OKEX_Sub_Spot_Api): class SpotApi(OkexSpotApi):
"""okex的API实现""" """okex的API实现"""
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def __init__(self, gateway): def __init__(self, gateway):
"""Constructor""" """Constructor"""
super(Api_Spot, self).__init__() super(SpotApi, self).__init__()
self.gateway = gateway # gateway对象 self.gateway = gateway # gateway对象
self.gatewayName = gateway.gatewayName # gateway对象名称 self.gatewayName = gateway.gatewayName # gateway对象名称
self.active = False # 若为True则会在断线后自动重连 self.active = False # 若为True则会在断线后自动重连
self.cbDict = {} self.cbDict = {}
@ -572,7 +573,7 @@ etc': u'0', u'act': u'0', u'eth': u'0', u'ltc': u'0', u'bcs': u'0'}, u'free': {u
# 持仓信息 # 持仓信息
#for symbol in ['btc', 'ltc','eth', self.currency]: #for symbol in ['btc', 'ltc','eth', self.currency]:
for symbol in okex_all_symbol_type: for symbol in :
if symbol in funds['free']: if symbol in funds['free']:
pos = VtPositionData() pos = VtPositionData()
pos.gatewayName = self.gatewayName pos.gatewayName = self.gatewayName
@ -608,7 +609,7 @@ etc': u'0', u'act': u'0', u'eth': u'0', u'ltc': u'0', u'bcs': u'0'}, u'free': {u
# 持仓信息 # 持仓信息
#for symbol in ['btc', 'ltc','eth', self.currency]: #for symbol in ['btc', 'ltc','eth', self.currency]:
for symbol in okex_all_symbol_type: for symbol in SPOT_CURRENCY:
if symbol in info['free']: if symbol in info['free']:
pos = VtPositionData() pos = VtPositionData()
pos.gatewayName = self.gatewayName pos.gatewayName = self.gatewayName