- @classmethod
- def dispatch_assets(cls, amount, repartition=None):
- if repartition is None:
- repartition = Portfolio.repartition()
- sum_ratio = sum([v[0] for k, v in repartition.items()])
- amounts = {}
- for currency, (ptt, trade_type) in repartition.items():
- amounts[currency] = ptt * amount / sum_ratio
- if currency not in cls.known_balances:
- cls.known_balances[currency] = cls(currency, 0, 0, 0)
- return amounts
-
- @classmethod
- def dispatch_trade_types(cls, repartition=None):
- if repartition is None:
- repartition = Portfolio.repartition()
- trade_types = {}
- for currency, (ptt, trade_type) in repartition.items():
- trade_types[currency] = trade_type
- return trade_types
- # FIXME: once we know the repartition and sold everything, we can move
- # the necessary part to the margin account
-
- @classmethod
- def prepare_trades(cls, market, base_currency="BTC", compute_value="average"):
- cls.fetch_balances(market)
- values_in_base = cls.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = cls.dispatch_assets(total_base_value)
- trade_types = cls.dispatch_trade_types()
- # Recompute it in case we have new currencies
- values_in_base = cls.in_currency(base_currency, market, compute_value=compute_value)
- Trade.compute_trades(values_in_base, new_repartition, trade_types, market=market)
-
- @classmethod
- def update_trades(cls, market, base_currency="BTC", compute_value="average", only=None):
- cls.fetch_balances(market)
- values_in_base = cls.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = cls.dispatch_assets(total_base_value)
- trade_types = cls.dispatch_trade_types()
- Trade.compute_trades(values_in_base, new_repartition, trade_types, only=only, market=market)
-
- @classmethod
- def prepare_trades_to_sell_all(cls, market, base_currency="BTC", compute_value="average"):
- cls.fetch_balances(market)
- values_in_base = cls.in_currency(base_currency, market, compute_value=compute_value)
- total_base_value = sum(values_in_base.values())
- new_repartition = cls.dispatch_assets(total_base_value, repartition={ base_currency: (1, "long") })
- trade_types = cls.dispatch_trade_types()
- Trade.compute_trades(values_in_base, new_repartition, trade_types, market=market)
+ if self.margin_total > 0:
+ if self.margin_free != 0 and self.margin_borrowed != 0:
+ margin = " Margin: [✔{} + borrowed {} = {}]".format(str(self.margin_free), str(self.margin_borrowed), str(self.margin_total))
+ elif self.margin_free != 0:
+ margin = " Margin: [✔{}]".format(str(self.margin_free))
+ else:
+ margin = " Margin: [borrowed {}]".format(str(self.margin_borrowed))
+ elif self.margin_total < 0:
+ margin = " Margin: [{} @@ {}/{}]".format(str(self.margin_total),
+ str(self.margin_borrowed_base_price),
+ str(self.margin_lending_fees))
+ else:
+ margin = ""