]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - script.py
Fetch assets from market
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / script.py
index 9bc2fe64ac695f7833ec7a9ecd3d0c7e538c506f..b31fd610f88df84a5dfce49a1e8bb46c8db7a321 100644 (file)
--- a/script.py
+++ b/script.py
@@ -9,12 +9,6 @@ def static_var(varname, value):
     return decorate
 
 max_digits = 18
-current_assets = {
-        "ETH":  int(2.00000000 * 10**max_digits),
-        "BTC":  int(1.23000000 * 10**max_digits),
-        "ZEC":  int(2.00000000 * 10**max_digits),
-        "SC" :  int(2.000000000 * 10**max_digits),
-        }
 
 repartition_pertenthousand = {
         "BTC":  2857,
@@ -50,6 +44,14 @@ def get_ticker(c1, c2, market):
             get_ticker.cache[(c1, c2, market.__class__)] = None
     return get_ticker(c1, c2, market)
 
+def fetch_balances(market):
+    balances = {}
+    fetched_balance = market.fetch_balance()
+    for key, value in fetched_balance["total"].items():
+        if value > 0:
+            balances[key] = int(value * 10**max_digits)
+    return balances
+
 def assets_value(assets, market, base_currency="BTC"):
     repartition_in_base_currency = {}
     for currency, asset_value in assets.items():
@@ -107,4 +109,5 @@ def give_orders(current_assets, repartition_pertenthousand, market, base_currenc
     for currency, value in new_repartition.items():
         print("holding {} {}".format(formatted_price(value), currency))
 
+current_assets = fetch_balances(market)
 give_orders(current_assets, repartition_pertenthousand, market)