vn.py官网
开源量化社区
Member
加入于:
帖子: 7
声望: 1

binance_gateway中,订阅合约的逻辑如下,造成每次订阅都会重新连接websocket。感觉没有必要这样订阅,直接发送订阅请求不可以吗?

`

def subscribe(self, req: SubscribeRequest):
    """"""
    if req.symbol not in symbol_name_map:
        self.gateway.write_log(f"找不到该合约代码{req.symbol}")
        return

    # Create tick buf data
    tick = TickData(
        symbol=req.symbol,
        name=symbol_name_map.get(req.symbol, ""),
        exchange=Exchange.BINANCE,
        datetime=datetime.now(CHINA_TZ),
        gateway_name=self.gateway_name,
    )
    self.ticks[req.symbol] = tick

    # Close previous connection
    if self._active:
        self.stop()
        self.join()

    # Create new connection
    channels = []
    for ws_symbol in self.ticks.keys():
        channels.append(ws_symbol + "@ticker")
        channels.append(ws_symbol + "@depth5")

    url = WEBSOCKET_DATA_HOST + "/".join(channels)
    self.init(url, self.proxy_host, self.proxy_port)
    self.start()

`

Administrator
avatar
加入于:
帖子: 4985
声望: 291

不行,币安接口就这么设计的,比较奇葩

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号