[Mod]火币接口移除代理支持,增加自动订阅行情
This commit is contained in:
parent
bbabd742ff
commit
8cdfcef62b
@ -9,12 +9,12 @@
|
||||
"darkStyle": true,
|
||||
"language": "chinese",
|
||||
|
||||
"logActive": true,
|
||||
"logActive": false,
|
||||
"logLevel": "debug",
|
||||
"logConsole": true,
|
||||
"logFile": true,
|
||||
|
||||
"tdPenalty": ["IF", "IH", "IC"],
|
||||
"tdPenalty": [],
|
||||
|
||||
"maxDecimal": 4
|
||||
"maxDecimal": 10
|
||||
}
|
@ -504,8 +504,6 @@ class DataApi(object):
|
||||
self.subDict = {}
|
||||
|
||||
self.url = ''
|
||||
self.proxyHost = ''
|
||||
self.proxyPort = 0
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def run(self):
|
||||
@ -532,12 +530,7 @@ class DataApi(object):
|
||||
def reconnect(self):
|
||||
"""重连"""
|
||||
try:
|
||||
if not self.proxyHost:
|
||||
self.ws = create_connection(self.url)
|
||||
else:
|
||||
self.ws = create_connection(self.url,
|
||||
http_proxy_host=self.proxyHost,
|
||||
http_proxy_port=self.proxyPort)
|
||||
self.ws = create_connection(self.url)
|
||||
return True
|
||||
except:
|
||||
msg = traceback.format_exc()
|
||||
@ -553,20 +546,12 @@ class DataApi(object):
|
||||
self.subTopic(topic)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connect(self, url, proxyHost='', proxyPort=0):
|
||||
def connect(self, url):
|
||||
"""连接"""
|
||||
self.url = url
|
||||
self.proxyHost = proxyHost
|
||||
self.proxyPort = proxyPort
|
||||
|
||||
try:
|
||||
if not self.proxyHost:
|
||||
self.ws = create_connection(self.url)
|
||||
else:
|
||||
self.ws = create_connection(self.url,
|
||||
http_proxy_host=self.proxyHost,
|
||||
http_proxy_port=self.proxyPort)
|
||||
|
||||
self.ws = create_connection(self.url)
|
||||
self.active = True
|
||||
self.thread.start()
|
||||
|
||||
|
@ -75,8 +75,6 @@ class HuobiGateway(VtGateway):
|
||||
accessKey = str(setting['accessKey'])
|
||||
secretKey = str(setting['secretKey'])
|
||||
symbols = setting['symbols']
|
||||
proxyHost = str(setting['proxyHost'])
|
||||
proxyPort = int(setting['proxyPort'])
|
||||
except KeyError:
|
||||
log = VtLogData()
|
||||
log.gatewayName = self.gatewayName
|
||||
@ -85,7 +83,7 @@ class HuobiGateway(VtGateway):
|
||||
return
|
||||
|
||||
# 创建行情和交易接口对象
|
||||
self.dataApi.connect(exchange, proxyHost, proxyPort)
|
||||
self.dataApi.connect(exchange, symbols)
|
||||
self.tradeApi.connect(exchange, accessKey, secretKey, symbols)
|
||||
|
||||
# 初始化并启动查询
|
||||
@ -94,7 +92,8 @@ class HuobiGateway(VtGateway):
|
||||
#----------------------------------------------------------------------
|
||||
def subscribe(self, subscribeReq):
|
||||
"""订阅行情"""
|
||||
self.dataApi.subscribe(subscribeReq)
|
||||
pass
|
||||
#self.dataApi.subscribe(subscribeReq)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def sendOrder(self, orderReq):
|
||||
@ -179,38 +178,40 @@ class HuobiDataApi(DataApi):
|
||||
|
||||
self.tickDict = {}
|
||||
|
||||
self.subscribeDict = {}
|
||||
#self.subscribeDict = {}
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connect(self, exchange, proxyHost, proxyPort):
|
||||
def connect(self, exchange, symbols):
|
||||
"""连接服务器"""
|
||||
if exchange == 'huobi':
|
||||
url = 'wss://api.huobi.pro/ws'
|
||||
else:
|
||||
url = 'wss://api.hadax.com/ws'
|
||||
|
||||
if proxyHost:
|
||||
self.connectionStatus = super(HuobiDataApi, self).connect(url, proxyHost, proxyPort)
|
||||
else:
|
||||
self.connectionStatus = super(HuobiDataApi, self).connect(url)
|
||||
self.symbols = symbols
|
||||
|
||||
self.connectionStatus = super(HuobiDataApi, self).connect(url)
|
||||
self.gateway.mdConnected = True
|
||||
|
||||
if self.connectionStatus:
|
||||
self.writeLog(u'行情服务器连接成功')
|
||||
|
||||
for symbol in self.symbols:
|
||||
self.subscribe(symbol)
|
||||
# 订阅所有之前订阅过的行情
|
||||
for req in self.subscribeDict.values():
|
||||
self.subscribe(req)
|
||||
#for req in self.subscribeDict.values():
|
||||
# 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:
|
||||
return
|
||||
|
||||
symbol = subscribeReq.symbol
|
||||
#symbol = subscribeReq.symbol
|
||||
if symbol in self.tickDict:
|
||||
return
|
||||
|
||||
@ -354,7 +355,7 @@ class HuobiTradeApi(TradeApi):
|
||||
#self.activeOrderSet = set() # 活动委托集合
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connect(self, exchange, accessKey, secretKey, symbols=''):
|
||||
def connect(self, exchange, symbols, accessKey, secretKey):
|
||||
"""初始化连接"""
|
||||
if not self.connectionStatus:
|
||||
self.symbols = symbols
|
||||
|
Loading…
Reference in New Issue
Block a user