BitMEX / sample-market-maker

Sample BitMEX Market Making Bot
Apache License 2.0
1.7k stars 758 forks source link

Can't understand the code in get_price_offset #199

Open Jay54520 opened 5 years ago

Jay54520 commented 5 years ago

The code is return math.toNearest(start_position * (1 + settings.INTERVAL) ** index, self.instrument['tickSize']) in get_price_offset.

image

Why there are different results?

  1. start_position * (1 + settings.INTERVAL) ** 0 = 9522.6475
  2. 9570.260737499999 ** 0 = 1.

We know that ** means pow in Python, so 2 is expected but not 1.

kicksent commented 4 years ago

(1 + settings.INTERVAL) ** 0 evaluates to 1 before being multiplied with start_position because the order of operations in python is pow before mult.

If you put parenthesis around the first part it will evaluate the same: (start_position * (1 + settings.INTERVAL)) ** 0