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