问题描述
我知道我可以使用“ while true”并调用“ get_ticker”方法来获取产品的最后价格,但这是从python而不是市场本身驱动的。我想知道随着BitMEX网站的改变,是否有办法获得最后的价格。谢谢
解决方法
检查我的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