X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=store.py;h=841a0fc9e4f581ad468a2c3e8664507b003b4232;hb=5a72ded790f8b5e7c9b38a3cc91c12fbfb6cb97a;hp=4e46878928d940522beceae46c9d08f37f40c636;hpb=6ca5a1ec669593fa915a2824efca068c975f9caa;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/store.py b/store.py index 4e46878..841a0fc 100644 --- a/store.py +++ b/store.py @@ -53,22 +53,27 @@ class TradeStore: continue value_from = values_in_base.get(currency, portfolio.Amount(base_currency, 0)) value_to = new_repartition.get(currency, portfolio.Amount(base_currency, 0)) + if value_from.value * value_to.value < 0: - trade_1 = portfolio.Trade(value_from, portfolio.Amount(base_currency, 0), currency, market=market) - if only is None or trade_1.action == only: - cls.all.append(trade_1) - trade_2 = portfolio.Trade(portfolio.Amount(base_currency, 0), value_to, currency, market=market) - if only is None or trade_2.action == only: - cls.all.append(trade_2) + cls.add_trade_if_matching( + value_from, portfolio.Amount(base_currency, 0), + currency, only=only, market=market) + cls.add_trade_if_matching( + portfolio.Amount(base_currency, 0), value_to, + currency, only=only, market=market) else: - trade = portfolio.Trade( - value_from, - value_to, - currency, - market=market - ) - if only is None or trade.action == only: - cls.all.append(trade) + cls.add_trade_if_matching(value_from, value_to, + currency, only=only, market=market) + + @classmethod + def add_trade_if_matching(cls, value_from, value_to, currency, + only=None, market=None): + trade = portfolio.Trade(value_from, value_to, currency, + market=market) + if only is None or trade.action == only: + cls.all.append(trade) + return True + return False @classmethod def prepare_orders(cls, only=None, compute_value="default"):