def estimate(self, quote:Quote, quantity:int = None):
# quantity is only used for direction
quantity = copysign(1, quantity)
if quote.bid is None or quote.ask is None or quote.bid == 0.0 or quote.ask == 0.0:
raise Exception(
'SlippageEstimator.estimate: Cannot estimate a price if the bid or ask are None or 0.0')
if quantity is None or quantity == 0:
raise Exception(
'SlippageEstimator.estimate: Must provide a signed quantity to buy or sell.')
spread = (quote.ask - quote.bid) / 2
midpoint = quote.bid + spread
if quantity > 0:
return midpoint - spread * self.slippage
else:
return midpoint + spread * self.slippage
评论列表
文章目录