瀏覽代碼

fix expiration times

Eren Yilmaz 6 年之前
父節點
當前提交
9e0a68fa6b
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      client_controller.py

+ 14 - 2
client_controller.py

@@ -226,7 +226,7 @@ def buy(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
         else:
             limit = None
             stop_loss = None
-    if limit is not None and stop_loss == '':
+    if limit != '' and stop_loss == '':
         stop_loss = yn_dialog('Is this a stop-loss limit?')
     if limit is not None and \
             float(limit) <= 0 and \
@@ -240,7 +240,7 @@ def buy(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
         if expiry == '':
             expiry = 43200
     try:
-        float(expiry)
+        expiry = float(expiry)
     except ValueError:
         print('Invalid expiration time.')
         return
@@ -275,11 +275,23 @@ def sell(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
             stop_loss = None
     if limit != '' and stop_loss == '':
         stop_loss = yn_dialog('Is this a stop-loss limit?')
+    if limit is not None and \
+            float(limit) <= 0 and \
+            input(input('Are you sure you want to use such a low limit (limit=' + str(
+            limit) + '? (type in "yes" or something else):') != 'yes'):
+        print('Order was not placed.')
+        return
 
     if expiry is None:
         expiry = input('Time until order expires (minutes, default 43200):')
         if expiry == '':
             expiry = 43200
+    try:
+        expiry = float(expiry)
+    except ValueError:
+        print('Invalid expiration time.')
+        return
+
     fake_loading_bar('Loading Data', duration=1.3)
     response = client_request('order', {"buy": False,
                                         "session_id": connection.session_id,