def action_get_assets(action): if isinstance(action, Trade): return trade_get_assets(action) elif isinstance(action, AssetMovement): return action.asset, None elif isinstance(action, EthereumTransaction): return 'ETH', None elif isinstance(action, dict): if 'btc_profit_loss' in action: return 'BTC', None # else a loan return action['currency'], None else: raise ValueError('Unexpected action type found.')
def action_get_assets( action: TaxableAction, ) -> Tuple[Asset, Optional[Asset]]: if isinstance(action, Trade): return trade_get_assets(action) elif isinstance(action, AssetMovement): return action.asset, None elif isinstance(action, EthereumTransaction): return A_ETH, None elif isinstance(action, MarginPosition): return action.pl_currency, None elif isinstance(action, Loan): return action.currency, None raise AssertionError(f'TaxableAction of unknown type {type(action)} encountered')
def action_get_assets( action: TaxableAction, ) -> Tuple[Asset, Optional[Asset]]: if isinstance(action, Trade): return trade_get_assets(action) elif isinstance(action, AssetMovement): return action.asset, None elif isinstance(action, EthereumTransaction): return S_ETH, None elif isinstance(action, MarginPosition): return action.pl_currency, None elif isinstance(action, dict): # else a loan return action['currency'], None else: raise ValueError('Unexpected action type found.')
def test_trade_get_assets(): trade = Trade( timestamp=1546985746, location='bittrex', pair=TradePair('BTC_ETH'), trade_type=TradeType.BUY, amount=FVal(10), rate=FVal(0.05), fee=FVal(0.001), fee_currency=A_ETH, link='', notes='', ) a1, a2 = trade_get_assets(trade) assert isinstance(a1, Asset) assert a1 == A_BTC assert isinstance(a2, Asset) assert a2 == A_ETH