INNER CODE UNIT · Python
place_orders
nkaz001/sample-trading-bot · tradingbot/custom_strategy.py:12
async def place_orders(self):
# implement your custom strategy here
order_qty_dollar = 100
threshold = 1000 # need to find an optimal value
depth = 0.05 # need to find an optimal value
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'])
mid = (bid['price'][0] + ask['price'][0]) / 2.0
buy = bid[bid['price'] > mid * (1 - depth)]['size'].sum()
sell = ask[ask['price'] > mid * (1 + depth)]['size'].sum()
alpha = buy - sell
buy_orders = []