]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - helper.py
Fix move_balance not moving currencies absent from trades
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / helper.py
index 421e8cdc9b7f0adcbe3af64328fe178681a16eed..8ef2d642203252c8d14ab9328ad1fbcb7e59a4d8 100644 (file)
--- a/helper.py
+++ b/helper.py
@@ -4,10 +4,13 @@ from store import *
 
 def move_balances(market, debug=False):
     needed_in_margin = {} 
+    for currency in BalanceStore.all:
+        if BalanceStore.all[currency].margin_free != 0:
+            needed_in_margin[currency] = 0
     for trade in TradeStore.all:
+        if trade.value_to.currency not in needed_in_margin:
+            needed_in_margin[trade.value_to.currency] = 0
         if trade.trade_type == "short":
-            if trade.value_to.currency not in needed_in_margin:
-                needed_in_margin[trade.value_to.currency] = 0
             needed_in_margin[trade.value_to.currency] += abs(trade.value_to)
     for currency, needed in needed_in_margin.items():
         current_balance = BalanceStore.all[currency].margin_free
@@ -109,7 +112,7 @@ def follow_orders(verbose=True, sleep=None):
         print("All orders finished")
 
 def print_orders(market, base_currency="BTC"):
-    prepare_trades(market, base_currency=base_currency, compute_value="average")
+    prepare_trades(market, base_currency=base_currency, compute_value="average", debug=True)
     TradeStore.prepare_orders(compute_value="average")
     for currency, balance in BalanceStore.all.items():
         print(balance)
@@ -127,7 +130,7 @@ def process_sell_needed__1_sell(market, base_currency="BTC", debug=False):
     TradeStore.run_orders()
     follow_orders()
 
-def process_sell_needed__2_sell(market, base_currency="BTC", debug=False):
+def process_sell_needed__2_buy(market, base_currency="BTC", debug=False):
     update_trades(market, base_currency=base_currency, debug=debug, only="acquire")
     TradeStore.prepare_orders(compute_value="average", only="acquire")
     print("------------------")