|
@@ -3,6 +3,7 @@ from datetime import timedelta, datetime
|
|
|
from math import log2, ceil
|
|
|
|
|
|
import model
|
|
|
+from debug import debug
|
|
|
|
|
|
order_expiry = 43200
|
|
|
|
|
@@ -77,12 +78,22 @@ def notify_order_traded(ownable_id):
|
|
|
return False
|
|
|
ownership_id = model.get_ownership_id(ownable_id, model.bank_id())
|
|
|
|
|
|
+ if debug: # the bot should only have one order
|
|
|
+ model.cursor.execute('''
|
|
|
+ SELECT COUNT(*) <= 1
|
|
|
+ FROM orders
|
|
|
+ WHERE ownership_id = ?
|
|
|
+ ''', (ownership_id,))
|
|
|
+ if not model.cursor.fetchone()[0]:
|
|
|
+ raise AssertionError('The bot should have at most one order.')
|
|
|
+
|
|
|
model.cursor.execute('''
|
|
|
SELECT rowid, amount, expiry
|
|
|
FROM orders
|
|
|
WHERE ownership_id = ?
|
|
|
-- no need for ORDER since the bot should have only one order
|
|
|
-- ORDER BY rowid DESC -- equivalent to ordering by time created
|
|
|
+ -- LIMIT might still improve performance
|
|
|
LIMIT 1
|
|
|
''', (ownership_id,))
|
|
|
data = model.cursor.fechtall()
|