单台行情服务器,有出现Tick丢失的情况,这个策略有一定的 影响,可以通过增加多台行情服务器的方法,解决问题

from collections import deque
from vnpy.gateway.ctp.ctp_gateway import *

class CtpGatewayDouble(CtpGateway):
    default_setting = {
        "用户名": "",
        "密码": "",
        "经纪商代码": "",
        "交易服务器": "",
        "主行情服务器": "",
        "次行情服务器": "",
        "产品名称": "",
        "授权编码": "",
        "产品信息": "",
    }

    def __init__(self, event_engine):
        super(CtpGateway, self).__init__(event_engine, "Double")
        self.td_api = CtpTdApi(self)
        # 主行情
        self.md_api = CtpMdApi(self)
        # 备用行情
        self.sub_md_api = CtpMdApi(self)
        # 缓存
        self.tick_buffer = deque(maxlen=100_000)

    def connect(self, setting: dict):
        """"""
        userid = setting["用户名"]
        password = setting["密码"]
        brokerid = setting["经纪商代码"]
        td_address = setting["交易服务器"]
        md_address = setting["主行情服务器"]
        sub_md_address = setting["次行情服务器"]
        appid = setting["产品名称"]
        auth_code = setting["授权编码"]
        product_info = setting["产品信息"]

        if (not td_address.startswith("tcp://")) and (
            not td_address.startswith("ssl://")
        ):
            td_address = "tcp://" + td_address

        if (not md_address.startswith("tcp://")) and (
            not md_address.startswith("ssl://")
        ):
            md_address = "tcp://" + md_address

        if (not sub_md_address.startswith("tcp://")) and (
            not sub_md_address.startswith("ssl://")
        ):
            sub_md_address = "tcp://" + sub_md_address

        self.td_api.connect(
            td_address, userid, password, brokerid, auth_code, appid, product_info
        )
        self.md_api.connect(md_address, userid, password, brokerid)
        self.sub_md_api.connect(sub_md_address, userid, password, brokerid)

        self.init_query()

    def subscribe(self, req: SubscribeRequest):
        """"""
        self.md_api.subscribe(req)
        self.sub_md_api.subscribe(req)

    def close(self):
        """"""
        self.td_api.close()
        self.md_api.close()
        self.sub_md_api.close()

    def on_tick(self, tick):
        tick_hash = hash(tick)
        if tick_hash not in self.tick_buffer:
            self.tick_buffer.append(tick_hash)
            super().on_tick(tick)