]> 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 f1aeaf2dbeba2807d29ca632d889761fe647274f..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