|
@@ -564,6 +564,17 @@ def delete_order(order_id):
|
|
|
''', (order_id,))
|
|
|
|
|
|
|
|
|
+def current_value(ownable_id):
|
|
|
+ connect()
|
|
|
+ cursor.execute('''SELECT price
|
|
|
+ FROM transactions
|
|
|
+ WHERE ownable_id = ?
|
|
|
+ ORDER BY dt DESC
|
|
|
+ LIMIT 1
|
|
|
+ ''', (ownable_id,))
|
|
|
+ return cursor.fetchone()[0]
|
|
|
+
|
|
|
+
|
|
|
def execute_orders(ownable_id):
|
|
|
connect()
|
|
|
while True:
|
|
@@ -599,12 +610,12 @@ def execute_orders(ownable_id):
|
|
|
break
|
|
|
|
|
|
buy_ownership_id, _, buy_limit, _, buy_order_amount, buy_executed_amount, buy_expiry_dt, \
|
|
|
- sell_ownership_id, _, sell_limit, _, sell_order_amount, sell_executed_amount, sell_expiry_dt, \
|
|
|
- buyer_id, seller_id, buy_order_id, sell_order_id \
|
|
|
+ sell_ownership_id, _, sell_limit, _, sell_order_amount, sell_executed_amount, sell_expiry_dt, \
|
|
|
+ buyer_id, seller_id, buy_order_id, sell_order_id \
|
|
|
= matching_orders
|
|
|
|
|
|
if buy_limit is None and sell_limit is None:
|
|
|
- raise AssertionError() # TODO use last transaction price
|
|
|
+ price = current_value(ownable_id)
|
|
|
elif buy_limit is None:
|
|
|
price = sell_limit
|
|
|
elif sell_limit is None:
|
|
@@ -941,4 +952,4 @@ def delete_ownable(ownable_id):
|
|
|
cursor.execute('''
|
|
|
DELETE FROM ownables
|
|
|
WHERE rowid = ?
|
|
|
- ''', (ownable_id,))
|
|
|
+ ''', (ownable_id,))
|