Procházet zdrojové kódy

see bid and ask price in depot

Eren Yilmaz před 6 roky
rodič
revize
e2baa834f0
2 změnil soubory, kde provedl 19 přidání a 2 odebrání
  1. 6 1
      client_controller.py
  2. 13 1
      model.py

+ 6 - 1
client_controller.py

@@ -136,7 +136,12 @@ def depot():
     response = client_request('depot', {"session_id": connection.session_id})
     success = 'data' in response and 'own_wealth' in response
     if success:
-        print(_my_tabulate(response['data'], headers=['Object', 'Amount', 'Est. Value'], tablefmt="pipe"))
+        data = response['data']
+        for row in data:
+            row.append(row[1] * row[2])
+        print(_my_tabulate(data,
+                           headers=['Object', 'Amount', 'Course', 'Bid', 'Ask', 'Est. Value'],
+                           tablefmt="pipe"))
         print('This corresponds to a wealth of roughly', response['own_wealth'])
     else:
         if 'error_message' in response:

+ 13 - 1
model.py

@@ -283,7 +283,19 @@ def get_user_ownership(user_id):
                   WHERE ownable_id = ownership.ownable_id 
                   ORDER BY dt DESC 
                   LIMIT 1)
-            END, 0) AS value
+            END, 0) AS price, 
+            (SELECT MAX("limit") 
+             FROM orders, ownership o2
+             WHERE o2.rowid = orders.ownership_id
+             AND o2.ownable_id = ownership.ownable_id
+             AND buy
+             AND NOT stop_loss) AS bid, 
+            (SELECT MIN("limit") 
+             FROM orders, ownership o2
+             WHERE o2.rowid = orders.ownership_id
+             AND o2.ownable_id = ownership.ownable_id
+             AND NOT buy
+             AND NOT stop_loss) AS ask
         FROM ownership, ownables
         WHERE user_id = ?
         AND ownership.amount > 0