[Add]增加火币交易接口的代理功能
This commit is contained in:
parent
f43c4b010c
commit
99e6c4d6fc
@ -93,6 +93,8 @@ class TradeApi(object):
|
||||
if mode:
|
||||
self.mode = mode
|
||||
|
||||
self.proxies = {}
|
||||
|
||||
return True
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -250,7 +252,7 @@ class TradeApi(object):
|
||||
path = '/v1/common/timestamp'
|
||||
params = {}
|
||||
func = self.apiGet
|
||||
callback = self.onGetCurrencys
|
||||
callback = self.onGetTimestamp
|
||||
|
||||
return self.addReq(path, params, func, callback)
|
||||
|
||||
@ -512,12 +514,17 @@ class DataApi(object):
|
||||
break
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connect(self, url):
|
||||
def connect(self, url, proxyHost='', proxyPort=0):
|
||||
"""连接"""
|
||||
self.url = url
|
||||
|
||||
try:
|
||||
if not proxyHost:
|
||||
self.ws = create_connection(self.url)
|
||||
else:
|
||||
self.ws = create_connection(self.url,
|
||||
http_proxy_host=proxyHost,
|
||||
http_proxy_port=proxyPort)
|
||||
|
||||
self.active = True
|
||||
self.thread.start()
|
||||
|
@ -2,5 +2,7 @@
|
||||
"exchange": "hadax",
|
||||
"accessKey": "请在火币申请",
|
||||
"secretKey": "请在火币申请",
|
||||
"symbols": ["aaceth"]
|
||||
"symbols": ["aaceth"],
|
||||
"proxyHost": "127.0.0.1",
|
||||
"proxyPort": 1080
|
||||
}
|
@ -75,6 +75,8 @@ 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
|
||||
@ -83,7 +85,7 @@ class HuobiGateway(VtGateway):
|
||||
return
|
||||
|
||||
# 创建行情和交易接口对象
|
||||
self.dataApi.connect(exchange)
|
||||
self.dataApi.connect(exchange, proxyHost, proxyPort)
|
||||
self.tradeApi.connect(exchange, accessKey, secretKey, symbols)
|
||||
|
||||
# 初始化并启动查询
|
||||
@ -180,13 +182,16 @@ class HuobiDataApi(DataApi):
|
||||
self.subscribeDict = {}
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connect(self, exchange):
|
||||
def connect(self, exchange, proxyHost, proxyPort):
|
||||
"""连接服务器"""
|
||||
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.gateway.mdConnected = True
|
||||
|
||||
@ -360,6 +365,7 @@ class HuobiTradeApi(TradeApi):
|
||||
self.start()
|
||||
self.writeLog(u'交易服务器连接成功')
|
||||
|
||||
self.getTimestamp()
|
||||
self.getSymbols()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -473,7 +479,9 @@ class HuobiTradeApi(TradeApi):
|
||||
#----------------------------------------------------------------------
|
||||
def onGetTimestamp(self, data, reqid):
|
||||
"""查询时间回调"""
|
||||
print reqid, data
|
||||
event = Event(EVENT_LOG+'Time')
|
||||
event.dict_['data'] = datetime.fromtimestamp(data/1000)
|
||||
self.gateway.eventEngine.put(event)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onGetAccounts(self, data, reqid):
|
||||
|
Loading…
Reference in New Issue
Block a user