diff --git a/vnpy/gateway/ctp/ctp_gateway.py b/vnpy/gateway/ctp/ctp_gateway.py index c3edddd8..362d1fbc 100644 --- a/vnpy/gateway/ctp/ctp_gateway.py +++ b/vnpy/gateway/ctp/ctp_gateway.py @@ -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 diff --git a/vnpy/trader/engine.py b/vnpy/trader/engine.py index c4695669..861df830 100644 --- a/vnpy/trader/engine.py +++ b/vnpy/trader/engine.py @@ -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