Kaynağa Gözat

limit transactions

Eren Yilmaz 6 yıl önce
ebeveyn
işleme
c5dbe6f9c8
3 değiştirilmiş dosya ile 10 ekleme ve 6 silme
  1. 5 2
      client_controller.py
  2. 3 2
      model.py
  3. 2 2
      server_controller.py

+ 5 - 2
client_controller.py

@@ -373,11 +373,14 @@ def news():
             print('Order access failed.')
 
 
-def transactions(obj_name=None):
+def transactions(obj_name=None, limit=5):
+    limit = float(limit)
     if obj_name is None:  # TODO list some available objects
         obj_name = input('Name of object to check: ')
     fake_loading_bar('Loading Data', duration=1.3)
-    response = client_request('transactions', {"session_id": connection.session_id, "ownable": obj_name})
+    response = client_request('transactions', {"session_id": connection.session_id,
+                                               "ownable": obj_name,
+                                               "limit": limit})
     success = 'data' in response
     if success:
         print(_my_tabulate(response['data'],

+ 3 - 2
model.py

@@ -834,7 +834,7 @@ def place_order(buy, ownership_id, limit, stop_loss, amount, time_until_expirati
     return True
 
 
-def transactions(ownable_id):
+def transactions(ownable_id, limit):
     connect()
 
     cursor.execute('''
@@ -842,7 +842,8 @@ def transactions(ownable_id):
         FROM transactions
         WHERE ownable_id = ?
         ORDER BY rowid DESC -- equivalent to order by dt
-        ''', (ownable_id,))
+        LIMIT ?
+        ''', (ownable_id, limit,))
 
     return cursor.fetchall()
 

+ 2 - 2
server_controller.py

@@ -202,12 +202,12 @@ def news():
 
 
 def transactions():
-    missing = missing_attributes(['session_id', 'ownable'])
+    missing = missing_attributes(['session_id', 'ownable', 'limit'])
     if missing:
         return bad_request(missing)
     if not model.ownable_name_exists(request.json['ownable']):
         return bad_request('This kind of object can not have transactions.')
-    return {'data': model.transactions(model.ownable_id_by_name(request.json['ownable']))}
+    return {'data': model.transactions(model.ownable_id_by_name(request.json['ownable']), request.json['limit'])}
 
 
 def leaderboard():