]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Augment ticker information to show adjusted bid/ask
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 14 Jan 2018 02:00:29 +0000 (03:00 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 14 Jan 2018 02:01:02 +0000 (03:01 +0100)
script.py

index b31fd610f88df84a5dfce49a1e8bb46c8db7a321..c702be63e8f64e5a39321448aa6294c290878cde 100644 (file)
--- a/script.py
+++ b/script.py
@@ -26,9 +26,19 @@ def formatted_price(value):
 def get_ticker(c1, c2, market):
     def invert(ticker):
         return {
+                "inverted": True,
                 "bid": float(1/ticker["ask"]),
                 "ask": float(1/ticker["bid"]),
+                "bidA": float(1/ticker["askA"]),
+                "askA": float(1/ticker["bidA"]),
                 }
+    def augment_ticker(ticker):
+        # FIXME: need to do better than just a multiplier
+        ticker.update({
+            "inverted": False,
+            "bidA": ticker["bid"] * 0.99,
+            "askA": ticker["ask"] * 1.01,
+            })
 
     if (c1, c2, market.__class__) in get_ticker.cache:
         return get_ticker.cache[(c1, c2, market.__class__)]
@@ -37,9 +47,11 @@ def get_ticker(c1, c2, market):
 
     try:
         get_ticker.cache[(c1, c2, market.__class__)] = market.fetch_ticker("{}/{}".format(c1, c2))
+        augment_ticker(get_ticker.cache[(c1, c2, market.__class__)])
     except ccxt.ExchangeError:
         try:
             get_ticker.cache[(c2, c1, market.__class__)] = market.fetch_ticker("{}/{}".format(c2, c1))
+            augment_ticker(get_ticker.cache[(c2, c1, market.__class__)])
         except ccxt.ExchangeError:
             get_ticker.cache[(c1, c2, market.__class__)] = None
     return get_ticker(c1, c2, market)
@@ -61,7 +73,7 @@ def assets_value(assets, market, base_currency="BTC"):
             asset_ticker = get_ticker(currency, base_currency, market)
             if asset_ticker is None:
                 raise Exception("This asset is not available in the chosen market")
-            repartition_in_base_currency[currency] = int(asset_ticker["bid"] * asset_value)
+            repartition_in_base_currency[currency] = int(asset_ticker["bidA"] * asset_value)
     return repartition_in_base_currency
 
 def dispatch_assets(base_currency_value, repartition_pertenthousand, market, base_currency="BTC"):