aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script.py14
1 files changed, 13 insertions, 1 deletions
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):
26def get_ticker(c1, c2, market): 26def get_ticker(c1, c2, market):
27 def invert(ticker): 27 def invert(ticker):
28 return { 28 return {
29 "inverted": True,
29 "bid": float(1/ticker["ask"]), 30 "bid": float(1/ticker["ask"]),
30 "ask": float(1/ticker["bid"]), 31 "ask": float(1/ticker["bid"]),
32 "bidA": float(1/ticker["askA"]),
33 "askA": float(1/ticker["bidA"]),
31 } 34 }
35 def augment_ticker(ticker):
36 # FIXME: need to do better than just a multiplier
37 ticker.update({
38 "inverted": False,
39 "bidA": ticker["bid"] * 0.99,
40 "askA": ticker["ask"] * 1.01,
41 })
32 42
33 if (c1, c2, market.__class__) in get_ticker.cache: 43 if (c1, c2, market.__class__) in get_ticker.cache:
34 return get_ticker.cache[(c1, c2, market.__class__)] 44 return get_ticker.cache[(c1, c2, market.__class__)]
@@ -37,9 +47,11 @@ def get_ticker(c1, c2, market):
37 47
38 try: 48 try:
39 get_ticker.cache[(c1, c2, market.__class__)] = market.fetch_ticker("{}/{}".format(c1, c2)) 49 get_ticker.cache[(c1, c2, market.__class__)] = market.fetch_ticker("{}/{}".format(c1, c2))
50 augment_ticker(get_ticker.cache[(c1, c2, market.__class__)])
40 except ccxt.ExchangeError: 51 except ccxt.ExchangeError:
41 try: 52 try:
42 get_ticker.cache[(c2, c1, market.__class__)] = market.fetch_ticker("{}/{}".format(c2, c1)) 53 get_ticker.cache[(c2, c1, market.__class__)] = market.fetch_ticker("{}/{}".format(c2, c1))
54 augment_ticker(get_ticker.cache[(c2, c1, market.__class__)])
43 except ccxt.ExchangeError: 55 except ccxt.ExchangeError:
44 get_ticker.cache[(c1, c2, market.__class__)] = None 56 get_ticker.cache[(c1, c2, market.__class__)] = None
45 return get_ticker(c1, c2, market) 57 return get_ticker(c1, c2, market)
@@ -61,7 +73,7 @@ def assets_value(assets, market, base_currency="BTC"):
61 asset_ticker = get_ticker(currency, base_currency, market) 73 asset_ticker = get_ticker(currency, base_currency, market)
62 if asset_ticker is None: 74 if asset_ticker is None:
63 raise Exception("This asset is not available in the chosen market") 75 raise Exception("This asset is not available in the chosen market")
64 repartition_in_base_currency[currency] = int(asset_ticker["bid"] * asset_value) 76 repartition_in_base_currency[currency] = int(asset_ticker["bidA"] * asset_value)
65 return repartition_in_base_currency 77 return repartition_in_base_currency
66 78
67def dispatch_assets(base_currency_value, repartition_pertenthousand, market, base_currency="BTC"): 79def dispatch_assets(base_currency_value, repartition_pertenthousand, market, base_currency="BTC"):