|
@@ -13,10 +13,21 @@ def place_order(ownable_id):
|
|
|
:param ownable_id: on which ownable to place the order
|
|
|
:return: True iff a new order was placed
|
|
|
"""
|
|
|
+
|
|
|
best_buy_order, cheapest_sell_order = model.abs_spread(ownable_id)
|
|
|
if best_buy_order is None or cheapest_sell_order is None:
|
|
|
return False
|
|
|
investors_id = model.bank_id()
|
|
|
+ ownership_id = model.get_ownership_id(ownable_id, investors_id)
|
|
|
+
|
|
|
+ if debug: # the bot should only have one order
|
|
|
+ model.cursor.execute('''
|
|
|
+ SELECT COUNT(*) = 0
|
|
|
+ FROM orders
|
|
|
+ WHERE ownership_id = ?
|
|
|
+ ''', (ownership_id,))
|
|
|
+ if not model.cursor.fetchone()[0]:
|
|
|
+ raise AssertionError('The bot should no orders at this point.')
|
|
|
|
|
|
amounts = model.cursor.execute('''
|
|
|
SELECT ordered_amount
|
|
@@ -34,14 +45,14 @@ def place_order(ownable_id):
|
|
|
limit = round(random.uniform(best_buy_order, cheapest_sell_order) * 10000) / 10000
|
|
|
if limit - best_buy_order < cheapest_sell_order - limit:
|
|
|
model.place_order(buy=True,
|
|
|
- ownership_id=model.get_ownership_id(ownable_id, investors_id),
|
|
|
+ ownership_id=ownership_id,
|
|
|
limit=limit,
|
|
|
stop_loss=False,
|
|
|
amount=amount,
|
|
|
expiry=expiry)
|
|
|
else:
|
|
|
model.place_order(buy=False,
|
|
|
- ownership_id=model.get_ownership_id(ownable_id, investors_id),
|
|
|
+ ownership_id=ownership_id,
|
|
|
limit=limit,
|
|
|
stop_loss=False,
|
|
|
amount=amount,
|