]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - helper.py
Allow dispatch assets to receive liquidity
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / helper.py
index f1aeaf2dbeba2807d29ca632d889761fe647274f..3e39785d4bb1a75d5bde324403161ddc3dcc053a 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
@@ -115,6 +118,14 @@ def print_orders(market, base_currency="BTC"):
         print(balance)
     TradeStore.print_all_with_order()
 
+def print_balances(market, base_currency="BTC"):
+    BalanceStore.fetch_balances(market)
+    for currency, balance in BalanceStore.all.items():
+        print(balance)
+    if base_currency is not None:
+        print("total:")
+        print(sum(BalanceStore.in_currency(base_currency, market).values()))
+
 def process_sell_needed__1_sell(market, base_currency="BTC", debug=False):
     prepare_trades(market, base_currency=base_currency, debug=debug)
     TradeStore.prepare_orders(compute_value="average", only="dispose")