- ticker_cache[(c1, c2, market.__class__)] = market.fetch_ticker("{}/{}".format(c1, c2))
- augment_ticker(ticker_cache[(c1, c2, market.__class__)])
- except ExchangeError:
- try:
- ticker_cache[(c2, c1, market.__class__)] = market.fetch_ticker("{}/{}".format(c2, c1))
- augment_ticker(ticker_cache[(c2, c1, market.__class__)])
- except ExchangeError:
- ticker_cache[(c1, c2, market.__class__)] = None
- return get_ticker(c1, c2, market)
-
-fees_cache = {}
-def fetch_fees(market):
- global fees_cache
- if market.__class__ not in fees_cache:
- fees_cache[market.__class__] = market.fetch_fees()
- return fees_cache[market.__class__]
-
-def prepare_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", debug=False):
- ReportStore.log_stage("prepare_trades")
- values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity)
- # Recompute it in case we have new currencies
- values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value)
- TradeStore.compute_trades(values_in_base, new_repartition, market=market, debug=debug)
-
-def update_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", only=None, debug=False):
- ReportStore.log_stage("update_trades")
- values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity)
- TradeStore.compute_trades(values_in_base, new_repartition, only=only, market=market, debug=debug)
-
-def prepare_trades_to_sell_all(market, base_currency="BTC", compute_value="average", debug=False):
- ReportStore.log_stage("prepare_trades_to_sell_all")
- values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = BalanceStore.dispatch_assets(total_base_value, repartition={ base_currency: (1, "long") })
- TradeStore.compute_trades(values_in_base, new_repartition, market=market, debug=debug)
-
-def follow_orders(sleep=None):
- if sleep is None:
- sleep = 7 if TradeStore.debug else 30
- if TradeStore.debug:
- ReportStore.log_debug_action("Set follow_orders tick to {}s".format(sleep))
- tick = 0
- ReportStore.log_stage("follow_orders_begin")
- while len(TradeStore.all_orders(state="open")) > 0:
- time.sleep(sleep)
- tick += 1
- open_orders = TradeStore.all_orders(state="open")
- ReportStore.log_stage("follow_orders_tick_{}".format(tick))
- ReportStore.log_orders(open_orders, tick=tick)
- for order in open_orders:
- if order.get_status() != "open":
- ReportStore.log_order(order, tick, finished=True)
- else:
- order.trade.update_order(order, tick)
- ReportStore.log_stage("follow_orders_end")