From 844b52e9cbf92ea68412db66f6fb9dcdfc074ca2 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 25 Jan 2018 14:14:08 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86FxcmAp?= =?UTF-8?q?i=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/WebTrader/run.py | 3 ++- vnpy/api/fxcm/demo.py | 6 +++++- vnpy/api/fxcm/vnfxcm.py | 30 ++++++++++++++++++------------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index b48c092c..9e705dd9 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -65,7 +65,7 @@ class Token(Resource): self.parser = reqparse.RequestParser() self.parser.add_argument('username') self.parser.add_argument('password') - super(Gateway, self).__init__() + super(Token, self).__init__() #---------------------------------------------------------------------- def get(self): @@ -554,6 +554,7 @@ class CtaStrategyVar(Resource): # 注册资源 +api.add_resource(Token, '/token') api.add_resource(Gateway, '/gateway') api.add_resource(Order, '/order') api.add_resource(Trade, '/trades') diff --git a/vnpy/api/fxcm/demo.py b/vnpy/api/fxcm/demo.py index f51fa03b..b405f3f3 100644 --- a/vnpy/api/fxcm/demo.py +++ b/vnpy/api/fxcm/demo.py @@ -96,6 +96,8 @@ def on_close(): print ('Websocket closed.') def on_connect(): + + ### Get models status, response = request_processor('/trading/get_model', {'models': list}) if status is True: @@ -128,6 +130,7 @@ def subscribe_prices(symbol): status, response = post_request_processor('/subscribe', {'pairs': symbol}) if status is True: socketIO.on(symbol, on_price_update) + print response else: 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) print (bearer_access_token) socketIO.on('disconnec', on_close) - socketIO.on('connect', on_connect) + socketIO.on('connect', on_connect) + subscribe_prices('EUR/USD') socketIO.wait() diff --git a/vnpy/api/fxcm/vnfxcm.py b/vnpy/api/fxcm/vnfxcm.py index a715b25b..dc47ad90 100644 --- a/vnpy/api/fxcm/vnfxcm.py +++ b/vnpy/api/fxcm/vnfxcm.py @@ -120,7 +120,7 @@ class FxcmApi(object): if method == self.METHOD_GET: resp = requests.get(url, headers=self.headers, params=params) 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: data = resp.json() @@ -158,7 +158,7 @@ class FxcmApi(object): """查询表""" uri = '/trading/get_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 #---------------------------------------------------------------------- @@ -167,7 +167,7 @@ class FxcmApi(object): uri = '/subscribe' params = {'pairs': symbol} reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribe) - self.sio.on(pair, self.onPriceUpdate) + self.sio.on(symbol, self.onPriceUpdate) return reqid #---------------------------------------------------------------------- @@ -179,20 +179,20 @@ class FxcmApi(object): return reqid #---------------------------------------------------------------------- - def subscribeTable(self, model): + def subscribeModel(self, model): """订阅表""" uri = '/trading/subscribe' params = {'models': model} - reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribeTable) - self.sio.on(model, self.onTableUpdate) + reqid = self.sendReq(self.METHOD_POST, uri, params, self.onSubscribeModel) + self.sio.on(model, self.onModelUpdate) return reqid #---------------------------------------------------------------------- - def unsubscribeTable(self, model): + def unsubscribeModel(self, model): """退订表""" uri = '/trading/unsubscribe' 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 #---------------------------------------------------------------------- @@ -289,12 +289,12 @@ class FxcmApi(object): print data, reqid #---------------------------------------------------------------------- - def onSubscribeTable(self, data, reqid): + def onSubscribeModel(self, data, reqid): """订阅表回调""" print data, reqid #---------------------------------------------------------------------- - def onUnsubscribeTable(self, data, reqid): + def onUnsubscribeModel(self, data, reqid): """退订表回调""" print data, reqid @@ -324,7 +324,7 @@ class FxcmApi(object): print data #---------------------------------------------------------------------- - def onTableUpdate(self, data): + def onModelUpdate(self, data): """表推送""" print data @@ -345,7 +345,13 @@ if __name__ == '__main__': api.connect(url, port, token) 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()