Explorar el Código

Trading bot still bugged

Eren Yilmaz hace 6 años
padre
commit
2a430812ce
Se han modificado 1 ficheros con 12 adiciones y 3 borrados
  1. 12 3
      trading_bot.py

+ 12 - 3
trading_bot.py

@@ -8,9 +8,14 @@ order_expiry = 43200
 
 
 def place_order(ownable_id):
+    """
+    places a new order according to the algorithm described in `assets/follower.py`
+    :param ownable_id: on which ownable to place the order
+    :return: True iff a new order was placed
+    """
     cheapest_buy_order, best_sell_order = model.abs_spread(ownable_id)
     if cheapest_buy_order is None or best_sell_order is None:
-        return
+        return False
     investors_id = model.bank_id()
 
     orders = model.get_ownable_orders(investors_id, ownable_id)
@@ -26,6 +31,7 @@ def place_order(ownable_id):
                       stop_loss=False,
                       amount=amount,
                       expiry=expiry)
+    return True
 
 
 def main():  # TODO testen
@@ -79,6 +85,10 @@ def notify_order_traded(ownable_id):
          -- ORDER BY rowid DESC -- equivalent to ordering by time created
         LIMIT 1
     ''', (ownership_id,))
+    data = model.cursor.fechtall()
+    # TODO Neu überdenken, das geht so nicht, wenn die order schon ausgeführt ist, ist sie nicht mehr in der DB
+    if not data:
+        return place_order(ownable_id)
 
     my_last_order = model.cursor.fechtone()
     last_order_id = my_last_order[0]
@@ -95,7 +105,6 @@ def notify_order_traded(ownable_id):
 
     if model.cursor.fechtone()[0]:
         model.delete_order(last_order_id)
-        place_order(ownable_id)
-        return True
+        return place_order(ownable_id)
 
     return False