【问题标题】:How to receive real time data through Bitmex Websocket Api on python?如何通过 Python 上的 Bitmex Websocket Api 接收实时数据?
【发布时间】:2020-09-30 21:08:52
【问题描述】:

我知道我可以使用“while true”并调用“get_ticker”方法来获取产品的最新价格,但这来自 python 而不是市场本身。我想知道随着 BitMEX 网站的变化,是否有办法获得最新价格。谢谢

【问题讨论】:

    标签: python websocket bitmex


    【解决方案1】:

    查看我的bitmex项目,有你的问题的解决方案:bitmex-supervisor

    基本代码片段:

    __init__():

    self.last_price = 0
    self._min_price = float('inf')
    self._max_price = -1
    
    self.initial_price = float('nan')
    
    self.tracking = False
    

    方法:

    @property
    def min_price(self):
        return self._min_price
    
    @min_price.setter
    def min_price(self, value):
        if value < self.initial_price:
            self.callback_price_decreased()  # here you can do some stuff
        self._min_price = value
    
    @property
    def max_price(self):
        return self._max_price
    
    @max_price.setter
    def max_price(self, value):
        if value > self.initial_price:
            self.callback_price_increased()  # here you can do some stuff
        self._max_price = value
    
    def stop_trailing(self):
        self.tracking = False
    
    def start_trailing(self, initial_price: float):
        """
        :param initial_price: the price after reaching which order will be moving
        """
    
        self._max_price = -1
        self._min_price = float('inf')
        self.initial_price = initial_price
        self.tracking = True
    

    __on_message():

    instrument = self.get_instrument(symbol=self.order.symbol)
        if instrument is not None:
            self.last_price = instrument['lastPrice']
            if self.tracking:
                if self.last_price > self.max_price and self.order.side == 'Sell':
                    self.max_price = self.last_price
                elif self.last_price < self.min_price and self.order.side == 'Buy':
                    self.min_price = self.last_price
    

    【讨论】:

      猜你喜欢
      • 2019-07-25
      • 1970-01-01
      • 2020-05-19
      • 2020-09-28
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 2015-04-01
      相关资源
      最近更新 更多