[Mod]修改部分FxcmApi函数
This commit is contained in:
parent
22b1401d62
commit
844b52e9cb
@ -65,7 +65,7 @@ class Token(Resource):
|
|||||||
self.parser = reqparse.RequestParser()
|
self.parser = reqparse.RequestParser()
|
||||||
self.parser.add_argument('username')
|
self.parser.add_argument('username')
|
||||||
self.parser.add_argument('password')
|
self.parser.add_argument('password')
|
||||||
super(Gateway, self).__init__()
|
super(Token, self).__init__()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -554,6 +554,7 @@ class CtaStrategyVar(Resource):
|
|||||||
|
|
||||||
|
|
||||||
# 注册资源
|
# 注册资源
|
||||||
|
api.add_resource(Token, '/token')
|
||||||
api.add_resource(Gateway, '/gateway')
|
api.add_resource(Gateway, '/gateway')
|
||||||
api.add_resource(Order, '/order')
|
api.add_resource(Order, '/order')
|
||||||
api.add_resource(Trade, '/trades')
|
api.add_resource(Trade, '/trades')
|
||||||
|
@ -96,6 +96,8 @@ def on_close():
|
|||||||
print ('Websocket closed.')
|
print ('Websocket closed.')
|
||||||
|
|
||||||
def on_connect():
|
def on_connect():
|
||||||
|
|
||||||
|
|
||||||
### Get models
|
### Get models
|
||||||
status, response = request_processor('/trading/get_model', {'models': list})
|
status, response = request_processor('/trading/get_model', {'models': list})
|
||||||
if status is True:
|
if status is True:
|
||||||
@ -128,6 +130,7 @@ def subscribe_prices(symbol):
|
|||||||
status, response = post_request_processor('/subscribe', {'pairs': symbol})
|
status, response = post_request_processor('/subscribe', {'pairs': symbol})
|
||||||
if status is True:
|
if status is True:
|
||||||
socketIO.on(symbol, on_price_update)
|
socketIO.on(symbol, on_price_update)
|
||||||
|
print response
|
||||||
else:
|
else:
|
||||||
print ("Error processing request: /subscribe: " + response)
|
print ("Error processing request: /subscribe: " + response)
|
||||||
|
|
||||||
@ -421,5 +424,6 @@ if __name__ == '__main__':
|
|||||||
bearer_access_token = create_bearer_token(ACCESS_TOKEN, socketIO._engineIO_session.id)
|
bearer_access_token = create_bearer_token(ACCESS_TOKEN, socketIO._engineIO_session.id)
|
||||||
print (bearer_access_token)
|
print (bearer_access_token)
|
||||||
socketIO.on('disconnec', on_close)
|
socketIO.on('disconnec', on_close)
|
||||||
socketIO.on('connect', on_connect)
|
socketIO.on('connect', on_connect)
|
||||||
|
subscribe_prices('EUR/USD')
|
||||||
socketIO.wait()
|
socketIO.wait()
|
||||||
|
@ -120,7 +120,7 @@ class FxcmApi(object):
|
|||||||
if method == self.METHOD_GET:
|
if method == self.METHOD_GET:
|
||||||
resp = requests.get(url, headers=self.headers, params=params)
|
resp = requests.get(url, headers=self.headers, params=params)
|
||||||
elif method == self.METHOD_POST:
|
elif method == self.METHOD_POST:
|
||||||
resp = requests.post(url, headers=self.headers, params=params)
|
resp = requests.post(url, headers=self.headers, data=params)
|
||||||
|
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
@ -158,7 +158,7 @@ class FxcmApi(object):
|
|||||||
"""查询表"""
|
"""查询表"""
|
||||||
uri = '/trading/get_model'
|
uri = '/trading/get_model'
|
||||||
params = {'models': model}
|
params = {'models': model}
|
||||||
reqid = self.sendReq(self.METHOD_GET, uri, params, self.onGetModel)
|
reqid = self.sendReq(self.METHOD_GET, uri, params, self.onGetTable)
|
||||||
return reqid
|
return reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -167,7 +167,7 @@ class FxcmApi(object):
|
|||||||
uri = '/subscribe'
|
uri = '/subscribe'
|
||||||
params = {'pairs': symbol}
|
params = {'pairs': symbol}
|
||||||
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribe)
|
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribe)
|
||||||
self.sio.on(pair, self.onPriceUpdate)
|
self.sio.on(symbol, self.onPriceUpdate)
|
||||||
return reqid
|
return reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -179,20 +179,20 @@ class FxcmApi(object):
|
|||||||
return reqid
|
return reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def subscribeTable(self, model):
|
def subscribeModel(self, model):
|
||||||
"""订阅表"""
|
"""订阅表"""
|
||||||
uri = '/trading/subscribe'
|
uri = '/trading/subscribe'
|
||||||
params = {'models': model}
|
params = {'models': model}
|
||||||
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribeTable)
|
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribeModel)
|
||||||
self.sio.on(model, self.onTableUpdate)
|
self.sio.on(model, self.onModelUpdate)
|
||||||
return reqid
|
return reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def unsubscribeTable(self, model):
|
def unsubscribeModel(self, model):
|
||||||
"""退订表"""
|
"""退订表"""
|
||||||
uri = '/trading/unsubscribe'
|
uri = '/trading/unsubscribe'
|
||||||
params = {'models': model}
|
params = {'models': model}
|
||||||
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onUnsubscribeTable)
|
reqid = self.sendReq(self.METHOD_POST, uri, params, self.onUnsubscribeModel)
|
||||||
return reqid
|
return reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -289,12 +289,12 @@ class FxcmApi(object):
|
|||||||
print data, reqid
|
print data, reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onSubscribeTable(self, data, reqid):
|
def onSubscribeModel(self, data, reqid):
|
||||||
"""订阅表回调"""
|
"""订阅表回调"""
|
||||||
print data, reqid
|
print data, reqid
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onUnsubscribeTable(self, data, reqid):
|
def onUnsubscribeModel(self, data, reqid):
|
||||||
"""退订表回调"""
|
"""退订表回调"""
|
||||||
print data, reqid
|
print data, reqid
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ class FxcmApi(object):
|
|||||||
print data
|
print data
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTableUpdate(self, data):
|
def onModelUpdate(self, data):
|
||||||
"""表推送"""
|
"""表推送"""
|
||||||
print data
|
print data
|
||||||
|
|
||||||
@ -345,7 +345,13 @@ if __name__ == '__main__':
|
|||||||
api.connect(url, port, token)
|
api.connect(url, port, token)
|
||||||
print api.bearer
|
print api.bearer
|
||||||
|
|
||||||
api.getInstruments()
|
#api.getInstruments()
|
||||||
|
|
||||||
|
api.subscribe('EUR/USD')
|
||||||
|
#api.subscribe(u'USD')
|
||||||
|
#api.subscribe(u'eurusd')
|
||||||
|
#api.getModel('Summary')
|
||||||
|
#api.subscribeModel('Summary')
|
||||||
|
|
||||||
input()
|
input()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user