import random from datetime import timedelta, datetime from math import log2, ceil import model def place_order(ownable_id): cheapest_buy_order, best_sell_order = model.abs_spread(ownable_id) if cheapest_buy_order is None or best_sell_order is None: return investors_id = model.bank_id() orders = model.get_ownable_orders(investors_id, ownable_id) orders = [random.choice(orders) for _ in range(int(ceil(log2(len(orders)))))] amounts = [order[3] for order in orders] amount = sum(amounts) / len(amounts) expiry = datetime.strptime(model.current_db_time(), '%Y-%m-%d %H:%M:%S') + timedelta(minutes=43200) model.place_order(buy=bool(random.getrandbits(1)), ownership_id=model.get_ownership_id(ownable_id, investors_id), limit=random.uniform(cheapest_buy_order, best_sell_order), stop_loss=False, amount=amount, expiry=expiry)