[bug fix] 支持多个CTP账号同时连接

This commit is contained in:
msincenselee 2020-02-06 16:28:47 +08:00
parent 7f372c88df
commit 4b0bdc4e9f
2 changed files with 9 additions and 4 deletions

View File

@ -177,9 +177,9 @@ class CtpGateway(BaseGateway):
# }
exchanges = list(EXCHANGE_CTP2VT.values())
def __init__(self, event_engine):
def __init__(self, event_engine, gateway_name="CTP"):
"""Constructor"""
super().__init__(event_engine, "CTP")
super().__init__(event_engine, gateway_name)
self.td_api = None
self.md_api = None

View File

@ -72,9 +72,14 @@ class MainEngine:
"""
Add gateway.
"""
gateway = gateway_class(self.event_engine)
if gateway_name is None:
if gateway_name:
# 使用指定的gateway_name 可以区分相同接口不同账号的gateway同时接入
gateway = gateway_class(self.event_engine, gateway_name=gateway_name)
else:
# 缺省使用了接口自己定义的gateway_name
gateway = gateway_class(self.event_engine)
gateway_name = gateway.gateway_name
self.gateways[gateway_name] = gateway
# Add gateway supported exchanges into engine