From 48bedc24dc34159fdf0ddaa5daaa055596c11d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 14 Jan 2018 03:00:29 +0100 Subject: Augment ticker information to show adjusted bid/ask --- script.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'script.py') diff --git a/script.py b/script.py index b31fd61..c702be6 100644 --- 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"): -- cgit v1.2.3