|
@@ -8,6 +8,7 @@ from math import floor
|
|
|
from passlib.handlers.sha2_crypt import sha256_crypt
|
|
|
|
|
|
import db_setup
|
|
|
+import trading_bot
|
|
|
from debug import debug
|
|
|
from game import CURRENCY_NAME
|
|
|
from util import random_chars, salt
|
|
@@ -302,7 +303,7 @@ def activate_key(key, user_id):
|
|
|
AND key = ?
|
|
|
''', (user_id, key,))
|
|
|
|
|
|
- send_ownable(bank_id(), user_id, CURRENCY_NAME, 1000)
|
|
|
+ send_ownable(bank_id(), user_id, currency_id(), 1000)
|
|
|
|
|
|
|
|
|
def bank_id():
|
|
@@ -653,11 +654,16 @@ def execute_orders(ownable_id):
|
|
|
# user_id,user_id,rowid,rowid)
|
|
|
|
|
|
if not matching_orders:
|
|
|
- break
|
|
|
+ # check if the trading bot has any new offers to make
|
|
|
+ new_order_was_placed = trading_bot.notify_order_traded(ownable_id)
|
|
|
+ if new_order_was_placed:
|
|
|
+ continue
|
|
|
+ else:
|
|
|
+ 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:
|
|
@@ -697,32 +703,8 @@ def execute_orders(ownable_id):
|
|
|
return AssertionError()
|
|
|
|
|
|
# actually execute the order, but the bank does not send or receive anything
|
|
|
- if buyer_id != bank_id(): # buyer pays
|
|
|
- cursor.execute('''
|
|
|
- UPDATE ownership
|
|
|
- SET amount = amount - ?
|
|
|
- WHERE user_id = ?
|
|
|
- AND ownable_id = ?
|
|
|
- ''', (price * amount, buyer_id, currency_id()))
|
|
|
- if seller_id != bank_id(): # seller pays
|
|
|
- cursor.execute('''
|
|
|
- UPDATE ownership
|
|
|
- SET amount = amount - ?
|
|
|
- WHERE rowid = ?
|
|
|
- ''', (amount, sell_ownership_id))
|
|
|
- if buyer_id != bank_id(): # buyer receives
|
|
|
- cursor.execute('''
|
|
|
- UPDATE ownership
|
|
|
- SET amount = amount + ?
|
|
|
- WHERE rowid = ?
|
|
|
- ''', (amount, buy_ownership_id))
|
|
|
- if seller_id != bank_id(): # seller receives
|
|
|
- cursor.execute('''
|
|
|
- UPDATE ownership
|
|
|
- SET amount = amount + ?
|
|
|
- WHERE user_id = ?
|
|
|
- AND ownable_id = ?
|
|
|
- ''', (price * amount, seller_id, currency_id()))
|
|
|
+ send_ownable(buyer_id, seller_id, ownable_id, price * amount)
|
|
|
+ send_ownable(seller_id, buyer_id, ownable_id, amount)
|
|
|
|
|
|
# update order execution state
|
|
|
cursor.execute('''
|
|
@@ -850,12 +832,19 @@ def trades(user_id, limit):
|
|
|
def drop_expired_orders():
|
|
|
connect()
|
|
|
|
|
|
+ cursor.execute('''
|
|
|
+ SELECT rowid, * FROM orders
|
|
|
+ WHERE expiry_dt < DATETIME('now')
|
|
|
+ ''')
|
|
|
+
|
|
|
+ data = cursor.fetchall()
|
|
|
+
|
|
|
cursor.execute('''
|
|
|
DELETE FROM orders
|
|
|
WHERE expiry_dt < DATETIME('now')
|
|
|
''')
|
|
|
|
|
|
- return cursor.fetchall()
|
|
|
+ return data
|
|
|
|
|
|
|
|
|
def generate_keys(count=1):
|