From 7682749bbae68926b89c6837401f757d061c163c Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 22 Jun 2019 23:34:53 +0800 Subject: [PATCH] [Fix] bug when close TapGateway --- examples/vn_trader/run.py | 8 ++++---- vnpy/gateway/tap/tap_gateway.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/vn_trader/run.py b/examples/vn_trader/run.py index 2ac64511..c7cd65c5 100644 --- a/examples/vn_trader/run.py +++ b/examples/vn_trader/run.py @@ -11,7 +11,7 @@ from vnpy.gateway.ctp import CtpGateway # from vnpy.gateway.ctptest import CtptestGateway from vnpy.gateway.femas import FemasGateway from vnpy.gateway.tiger import TigerGateway -from vnpy.gateway.oes import OesGateway +# from vnpy.gateway.oes import OesGateway from vnpy.gateway.okex import OkexGateway from vnpy.gateway.huobi import HuobiGateway from vnpy.gateway.bitfinex import BitfinexGateway @@ -19,7 +19,7 @@ from vnpy.gateway.onetoken import OnetokenGateway from vnpy.gateway.okexf import OkexfGateway # from vnpy.gateway.xtp import XtpGateway from vnpy.gateway.hbdm import HbdmGateway -# from vnpy.gateway.tap import TapGateway +from vnpy.gateway.tap import TapGateway from vnpy.app.cta_strategy import CtaStrategyApp from vnpy.app.csv_loader import CsvLoaderApp @@ -45,7 +45,7 @@ def main(): main_engine.add_gateway(FutuGateway) main_engine.add_gateway(BitmexGateway) main_engine.add_gateway(TigerGateway) - main_engine.add_gateway(OesGateway) + # main_engine.add_gateway(OesGateway) main_engine.add_gateway(OkexGateway) main_engine.add_gateway(HuobiGateway) main_engine.add_gateway(BitfinexGateway) @@ -53,7 +53,7 @@ def main(): main_engine.add_gateway(OkexfGateway) main_engine.add_gateway(HbdmGateway) # main_engine.add_gateway(XtpGateway) - # main_engine.add_gateway(TapGateway) + main_engine.add_gateway(TapGateway) main_engine.add_app(CtaStrategyApp) main_engine.add_app(CtaBacktesterApp) diff --git a/vnpy/gateway/tap/tap_gateway.py b/vnpy/gateway/tap/tap_gateway.py index 9a348787..7ba6ed99 100644 --- a/vnpy/gateway/tap/tap_gateway.py +++ b/vnpy/gateway/tap/tap_gateway.py @@ -336,9 +336,10 @@ class QuoteApi(ITapQuoteAPINotify): """ Release TAP API resources. """ - self.api.SetAPINotify(None) - FreeTapQuoteAPI(self.api) - self.api = None + if self.api: + self.api.SetAPINotify(None) + FreeTapQuoteAPI(self.api) + self.api = None def subscribe(self, req: SubscribeRequest): """ @@ -813,9 +814,10 @@ class TradeApi(ITapTradeAPINotify): """ Release TAP API resources. """ - self.api.SetAPINotify(None) - FreeITapTradeAPI(self.api) - self.api = None + if self.api: + self.api.SetAPINotify(None) + FreeITapTradeAPI(self.api) + self.api = None def parse_datetime(dt_str: str):