Bohr1005 / xcrypto

quant,trading system,crypto,async
MIT License
287 stars 83 forks source link

spot和usdt同时打开时区分信息源 #12

Closed benjzyq closed 1 week ago

benjzyq commented 1 week ago

你好,就是当spot和usdt通道都打开的时候,我该如何去区分我现在subscribe的货币对是什么?比如说我subscribe dogeusdt,我如何能区分这个信息是来自于usdt还是来自于spot通道?有没有可能可以设置一种区分方式比如说spot用小写 usdt用大写?谢谢

Bohr1005 commented 1 week ago

假设你的spot程序跑在8000端口,usdt跑在8001端口,可以这么区分不同的标的


class Strategy:
    """"""
    def __init__(self,spot:DepthSubscription,usdt:DepthSubscription):
        self.spot = spot
        self.usdt = usdt

        self.spot = self.on_spot
        self.usdt = self.on_usdt

    def on_spot(self,depth:Depth):
        # todo

    def on_usdt(self,depth:Depth):
        # todo

if __name__ == "__main__":
    eng = Engine(0.001)
    spot_session = eng.make_session(
        addr="ws://localhost:8000", session_id=1, name="test", trading=True
    )
    usdt_session = eng.make_session(
        addr="ws://localhost:8001", session_id=1, name="test", trading=True
    )

    spot = spot_session.subscribe("dogeusdt", "depth")
    usdt = usdt_session.subscribe("dogeusdt", "depth")
    strategy = Strategy(spot, usdt)
    eng.run()