report = None
trades = None
balances = None
+ options = None
def __init__(self, ccxt_instance, args, **kwargs):
self.args = args
self.balances = BalanceStore(self)
self.processor = Processor(self)
+ self.options = kwargs.get("options", {})
for key in ["user_id", "market_id"]:
setattr(self, key, kwargs.get(key, None))
message="{} disappeared, recreating it".format(order))
new_order = order.trade.prepare_order(
compute_value=order.trade.tick_actions_recreate(tick))
- new_order.run()
- self.report.log_order(order, tick, new_order=new_order)
+ if new_order is not None:
+ new_order.run()
+ self.report.log_order(order, tick, new_order=new_order)
self.report.log_stage("follow_orders_end")
compute_value=compute_value, only=only,
repartition=repartition, available_balance_only=available_balance_only)
- values_in_base = self.balances.in_currency(base_currency,
- compute_value=compute_value)
if available_balance_only:
- balance = self.balances.all.get(base_currency)
- if balance is None:
- total_base_value = portfolio.Amount(base_currency, 0)
- else:
- total_base_value = balance.exchange_free + balance.margin_available
+ repartition, total_base_value, values_in_base = self.balances.available_balances_for_repartition(
+ base_currency=base_currency, liquidity=liquidity,
+ repartition=repartition, compute_value=compute_value)
else:
+ values_in_base = self.balances.in_currency(base_currency,
+ compute_value=compute_value)
total_base_value = sum(values_in_base.values())
new_repartition = self.balances.dispatch_assets(total_base_value,
liquidity=liquidity, repartition=repartition)
if available_balance_only:
for currency, amount in values_in_base.items():
- if currency != base_currency:
- new_repartition.setdefault(currency, portfolio.Amount(base_currency, 0))
- new_repartition[currency] += amount
+ if currency != base_currency and currency not in new_repartition:
+ new_repartition[currency] = amount
self.trades.compute_trades(values_in_base, new_repartition, only=only)
def parse_args(self, action, default_args, kwargs):
method, allowed_arguments = self.method_arguments(action)
- args = {k: v for k, v in {**default_args, **kwargs}.items() if k in allowed_arguments }
+ args = {k: v for k, v in {**default_args, **kwargs, **self.market.options}.items() if k in allowed_arguments }
if "repartition" in args and "base_currency" in args["repartition"]:
r = args["repartition"]