[Mod]火币接口移除代理支持,增加自动订阅行情

This commit is contained in:
vn.py 2018-06-10 15:00:39 +08:00
parent bbabd742ff
commit 8cdfcef62b
3 changed files with 24 additions and 38 deletions

View File

@ -9,12 +9,12 @@
"darkStyle": true, "darkStyle": true,
"language": "chinese", "language": "chinese",
"logActive": true, "logActive": false,
"logLevel": "debug", "logLevel": "debug",
"logConsole": true, "logConsole": true,
"logFile": true, "logFile": true,
"tdPenalty": ["IF", "IH", "IC"], "tdPenalty": [],
"maxDecimal": 4 "maxDecimal": 10
} }

View File

@ -504,8 +504,6 @@ class DataApi(object):
self.subDict = {} self.subDict = {}
self.url = '' self.url = ''
self.proxyHost = ''
self.proxyPort = 0
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def run(self): def run(self):
@ -532,12 +530,7 @@ class DataApi(object):
def reconnect(self): def reconnect(self):
"""重连""" """重连"""
try: try:
if not self.proxyHost: self.ws = create_connection(self.url)
self.ws = create_connection(self.url)
else:
self.ws = create_connection(self.url,
http_proxy_host=self.proxyHost,
http_proxy_port=self.proxyPort)
return True return True
except: except:
msg = traceback.format_exc() msg = traceback.format_exc()
@ -553,20 +546,12 @@ class DataApi(object):
self.subTopic(topic) self.subTopic(topic)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connect(self, url, proxyHost='', proxyPort=0): def connect(self, url):
"""连接""" """连接"""
self.url = url self.url = url
self.proxyHost = proxyHost
self.proxyPort = proxyPort
try: try:
if not self.proxyHost: self.ws = create_connection(self.url)
self.ws = create_connection(self.url)
else:
self.ws = create_connection(self.url,
http_proxy_host=self.proxyHost,
http_proxy_port=self.proxyPort)
self.active = True self.active = True
self.thread.start() self.thread.start()

View File

@ -75,8 +75,6 @@ class HuobiGateway(VtGateway):
accessKey = str(setting['accessKey']) accessKey = str(setting['accessKey'])
secretKey = str(setting['secretKey']) secretKey = str(setting['secretKey'])
symbols = setting['symbols'] symbols = setting['symbols']
proxyHost = str(setting['proxyHost'])
proxyPort = int(setting['proxyPort'])
except KeyError: except KeyError:
log = VtLogData() log = VtLogData()
log.gatewayName = self.gatewayName log.gatewayName = self.gatewayName
@ -85,7 +83,7 @@ class HuobiGateway(VtGateway):
return return
# 创建行情和交易接口对象 # 创建行情和交易接口对象
self.dataApi.connect(exchange, proxyHost, proxyPort) self.dataApi.connect(exchange, symbols)
self.tradeApi.connect(exchange, accessKey, secretKey, symbols) self.tradeApi.connect(exchange, accessKey, secretKey, symbols)
# 初始化并启动查询 # 初始化并启动查询
@ -94,7 +92,8 @@ class HuobiGateway(VtGateway):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def subscribe(self, subscribeReq): def subscribe(self, subscribeReq):
"""订阅行情""" """订阅行情"""
self.dataApi.subscribe(subscribeReq) pass
#self.dataApi.subscribe(subscribeReq)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def sendOrder(self, orderReq): def sendOrder(self, orderReq):
@ -179,38 +178,40 @@ class HuobiDataApi(DataApi):
self.tickDict = {} self.tickDict = {}
self.subscribeDict = {} #self.subscribeDict = {}
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connect(self, exchange, proxyHost, proxyPort): def connect(self, exchange, symbols):
"""连接服务器""" """连接服务器"""
if exchange == 'huobi': if exchange == 'huobi':
url = 'wss://api.huobi.pro/ws' url = 'wss://api.huobi.pro/ws'
else: else:
url = 'wss://api.hadax.com/ws' url = 'wss://api.hadax.com/ws'
self.symbols = symbols
if proxyHost: self.connectionStatus = super(HuobiDataApi, self).connect(url)
self.connectionStatus = super(HuobiDataApi, self).connect(url, proxyHost, proxyPort)
else:
self.connectionStatus = super(HuobiDataApi, self).connect(url)
self.gateway.mdConnected = True self.gateway.mdConnected = True
if self.connectionStatus: if self.connectionStatus:
self.writeLog(u'行情服务器连接成功') self.writeLog(u'行情服务器连接成功')
for symbol in self.symbols:
self.subscribe(symbol)
# 订阅所有之前订阅过的行情 # 订阅所有之前订阅过的行情
for req in self.subscribeDict.values(): #for req in self.subscribeDict.values():
self.subscribe(req) # self.subscribe(req)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def subscribe(self, subscribeReq): def subscribe(self, symbol):
"""订阅合约""" """订阅合约"""
self.subscribeDict[subscribeReq.symbol] = subscribeReq #self.subscribeDict[subscribeReq.symbol] = subscribeReq
if not self.connectionStatus: if not self.connectionStatus:
return return
symbol = subscribeReq.symbol #symbol = subscribeReq.symbol
if symbol in self.tickDict: if symbol in self.tickDict:
return return
@ -354,7 +355,7 @@ class HuobiTradeApi(TradeApi):
#self.activeOrderSet = set() # 活动委托集合 #self.activeOrderSet = set() # 活动委托集合
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connect(self, exchange, accessKey, secretKey, symbols=''): def connect(self, exchange, symbols, accessKey, secretKey):
"""初始化连接""" """初始化连接"""
if not self.connectionStatus: if not self.connectionStatus:
self.symbols = symbols self.symbols = symbols