Selaa lähdekoodia

improve tables

Eren Yilmaz 6 vuotta sitten
vanhempi
commit
1476eb4aef
4 muutettua tiedostoa jossa 12 lisäystä ja 10 poistoa
  1. 7 4
      client_controller.py
  2. 2 3
      model.py
  3. 2 2
      run_client.py
  4. 1 1
      server_controller.py

+ 7 - 4
client_controller.py

@@ -5,7 +5,7 @@ from inspect import signature
 import connection
 from run_client import allowed_commands, fake_loading_bar
 from connection import client_request
-from tabulate import tabulate
+import tabulate
 
 from debug import debug
 
@@ -128,7 +128,8 @@ def help():
 def _my_tabulate(data, **params):
     if data == [] and 'headers' in params:
         data = [(None for _ in params['headers'])]
-    return tabulate(data, **params)
+    tabulate.MIN_PADDING = 0
+    return tabulate.tabulate(data, **params)
 
 
 def depot():
@@ -206,6 +207,7 @@ def buy(amount=None, object_name=None, limit='', stop_loss='', time_until_expira
         time_until_expiration = input('Time until order expires (minutes, default 1440):')
         if time_until_expiration == '':
             time_until_expiration = 1440
+    fake_loading_bar('Loading Data', duration=1.3)
     response = client_request('order', {"buy": True,
                                         "session_id": connection.session_id,
                                         "amount": amount,
@@ -240,6 +242,7 @@ def sell(amount=None, object_name=None, limit='', stop_loss='', time_until_expir
         time_until_expiration = input('Time until order expires (minutes, default 1440):')
         if time_until_expiration == '':
             time_until_expiration = 1440
+    fake_loading_bar('Loading Data', duration=1.3)
     response = client_request('order', {"buy": False,
                                         "session_id": connection.session_id,
                                         "amount": amount,
@@ -260,7 +263,7 @@ def orders():
     success = 'data' in response
     if success:
         print(_my_tabulate(response['data'],
-                           headers=['Buy?', 'Name', 'Amount', 'Limit', 'Stop Loss?', 'Orig. Size', 'Expires', 'No.'],
+                           headers=['Buy?', 'Name', 'Amount', 'Limit', 'stop-loss', 'Expires', 'No.'],
                            tablefmt="pipe"))
     else:
         if 'error_message' in response:
@@ -277,7 +280,7 @@ def orders_on(object_name=None):
     success = 'data' in response
     if success:
         print(_my_tabulate(response['data'],
-                           headers=['Buy?', 'Name', 'Amount', 'Limit', 'Stop Loss?', 'Expires', 'No.'],
+                           headers=['Buy?', 'Name', 'Amount', 'Limit', 'stop-loss', 'Expires', 'No.'],
                            tablefmt="pipe"))
     else:
         if 'error_message' in response:

+ 2 - 3
model.py

@@ -354,14 +354,13 @@ def get_user_orders(user_id):
                 ELSE 'Sell'
             END,
             ownables.name, 
-            orders.ordered_amount - orders.executed_amount, 
+            (orders.ordered_amount - orders.executed_amount) || '/' || orders.ordered_amount, 
             orders."limit", 
             CASE 
                 WHEN orders."limit" IS NULL THEN NULL 
                 WHEN orders.stop_loss THEN 'Yes'
                 ELSE 'No'
             END, 
-            orders.ordered_amount,
             datetime(orders.expiry_dt),
             orders.rowid
         FROM orders, ownables, ownership
@@ -702,7 +701,7 @@ def execute_orders(ownable_id):
                 VALUES(?, ?, ?)
                 ''', (price, ownable_id, amount,))
 
-        # trigger stop loss orders
+        # trigger stop-loss orders
         if buyer_id != seller_id:
             cursor.execute('''
                 UPDATE orders

+ 2 - 2
run_client.py

@@ -8,12 +8,12 @@ from debug import debug
 
 
 def fake_loading_bar(msg, duration=5.):
-    if len(msg) >= 50:
+    if len(msg) >= 60:
         raise AssertionError('Loading bar label too large')
     msg += ': '
     print(msg, end='')
     sys.stdout.flush()
-    bar_length = 78 - len(msg)
+    bar_length = 80 - len(msg)
     for _ in range(bar_length):
         if not debug:
             time.sleep(duration / bar_length)

+ 1 - 1
server_controller.py

@@ -112,7 +112,7 @@ def order():
         else:
             stop_loss = 'stop_loss' in request.json and request.json['stop_loss']
         if stop_loss is not None and limit is None:
-            return bad_request('Can only set stop loss for limit orders')
+            return bad_request('Can only set stop-loss for limit orders')
     except KeyError:  # for example when stop_loss was not specified
         stop_loss = None