INNER CODE UNIT · Python
interval_tick
nkaz001/sample-trading-bot · tradingbot/gridtrading.py:22
interval_tick = int(round(order_interval / tick_size))
max_position = 5000
market_depth = self.binance_futures.depth
bid = map(lambda x: (float(x[0]), x[1]), sorted(filter(lambda x: x[1] > 0, market_depth.items()), key=lambda x: -float(x[0])))
ask = map(lambda x: (float(x[0]), x[1]), sorted(filter(lambda x: x[1] < 0, market_depth.items()), key=lambda x: float(x[0])))
bid = pd.DataFrame(bid, columns=['price', 'size'])
ask = pd.DataFrame(ask, columns=['price', 'size'])
if len(bid) == 0 or len(ask) == 0:
return
mid = (bid['price'][0] + ask['price'][0]) / 2.0
bid_order_begin = min(mid - half_spread, bid['price'][0])
ask_order_begin = max(mid + half_spread, ask['price'][0])
lb_price = mid - price_range
ub_price = mid + price_range
x = float(self.binance_futures.running_qty) * mid / max_position