BitMEX/sample-market-maker

Can't understand the code in get_price_offset

Opened this issue · 1 comments

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.

(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