def add_sell( self, location: Location, selling_asset: Asset, rate_in_profit_currency: FVal, total_fee_in_profit_currency: Fee, gain_in_profit_currency: FVal, selling_amount: FVal, receiving_asset: Optional[Asset], receiving_amount: Optional[FVal], receiving_asset_rate_in_profit_currency: FVal, taxable_amount: FVal, taxable_bought_cost: FVal, timestamp: Timestamp, is_virtual: bool, ) -> None: if not self.create_csv: return processed_receiving_asset: Union[EmptyStr, Asset] = ( EmptyStr('') if receiving_asset is None else receiving_asset) exported_receiving_asset = '' if receiving_asset is None else receiving_asset.identifier processed_receiving_amount = FVal( 0) if not receiving_amount else receiving_amount exchange_rate_key = f'exchanged_asset_{self.profit_currency.identifier}_exchange_rate' taxable_profit_received = taxable_gain_for_sell( taxable_amount=taxable_amount, rate_in_profit_currency=rate_in_profit_currency, total_fee_in_profit_currency=total_fee_in_profit_currency, selling_amount=selling_amount, ) row = len(self.trades_csv) + 2 taxable_profit_formula = '=IF(H{}=0,0,L{}-K{})'.format(row, row, row) self.trades_csv.append({ 'type': 'sell', 'location': str(location), 'asset': selling_asset.identifier, f'price_in_{self.profit_currency.identifier}': rate_in_profit_currency, f'fee_in_{self.profit_currency.identifier}': total_fee_in_profit_currency, f'gained_or_invested_{self.profit_currency.identifier}': gain_in_profit_currency, 'amount': selling_amount, 'taxable_amount': taxable_amount, 'exchanged_for': exported_receiving_asset, exchange_rate_key: receiving_asset_rate_in_profit_currency, f'taxable_bought_cost_in_{self.profit_currency.identifier}': taxable_bought_cost, f'taxable_gain_in_{self.profit_currency.identifier}': taxable_profit_received, f'taxable_profit_loss_in_{self.profit_currency.identifier}': taxable_profit_formula, 'time': timestamp_to_date(timestamp, formatstr='%d/%m/%Y %H:%M:%S'), 'is_virtual': is_virtual, }) paid_in_profit_currency = ZERO self.add_to_allevents( event_type=EV_SELL, location=location, paid_in_profit_currency=paid_in_profit_currency, paid_asset=selling_asset, paid_in_asset=selling_amount, received_asset=processed_receiving_asset, received_in_asset=processed_receiving_amount, taxable_received_in_profit_currency=taxable_profit_received, timestamp=timestamp, is_virtual=is_virtual, taxable_amount=taxable_amount, taxable_bought_cost=taxable_bought_cost, )
from rotkehlchen.fval import FVal from rotkehlchen.typing import EmptyStr, EventType S_EMPTYSTR = EmptyStr('') EV_BUY = EventType('buy') EV_SELL = EventType('sell') EV_TX_GAS_COST = EventType('tx_gas_cost') EV_ASSET_MOVE = EventType('asset_movement') EV_LOAN_SETTLE = EventType('loan_settlement') EV_INTEREST_PAYMENT = EventType('interest_rate_payment') EV_MARGIN_CLOSE = EventType('margin_position_close') EV_DEFI = EventType('defi_event') EV_LEDGER_ACTION = EventType('ledger_action') CURRENCYCONVERTER_API_KEY = '7ad371210f296db27c19' ZERO = FVal(0) ONE = FVal(1) # API URLS KRAKEN_BASE_URL = 'https://api.kraken.com' KRAKEN_API_VERSION = '0' BINANCE_BASE_URL = 'binance.com/' BINANCE_US_BASE_URL = 'binance.us/' # KRAKEN_BASE_URL = 'http://localhost:5001/kraken' # KRAKEN_API_VERSION = 'mock' # BINANCE_BASE_URL = 'http://localhost:5001/binance/api/'
def add_sell( self, location: Location, selling_asset: Asset, rate_in_profit_currency: FVal, total_fee_in_profit_currency: Fee, gain_in_profit_currency: FVal, selling_amount: FVal, receiving_asset: Optional[Asset], receiving_amount: Optional[FVal], receiving_asset_rate_in_profit_currency: FVal, taxable_amount: FVal, taxable_bought_cost: FVal, timestamp: Timestamp, is_virtual: bool, cost_basis_info: 'CostBasisInfo', total_bought_cost: FVal, ) -> None: if not self.create_csv: return processed_receiving_asset: Union[EmptyStr, Asset] = ( EmptyStr('') if receiving_asset is None else receiving_asset ) exported_receiving_asset = '' if receiving_asset is None else str(receiving_asset) processed_receiving_amount = ZERO if not receiving_amount else receiving_amount exchange_rate_key = f'exchanged_asset_{self.profit_currency.symbol}_exchange_rate' taxable_profit_received = taxable_gain_for_sell( taxable_amount=taxable_amount, rate_in_profit_currency=rate_in_profit_currency, total_fee_in_profit_currency=total_fee_in_profit_currency, selling_amount=selling_amount, ) row = len(self.trades_csv) + 2 taxable_profit_formula = f'=IF(H{row}=0,0,L{row}-K{row})' self.trades_csv.append({ 'type': 'sell', 'location': str(location), 'asset': str(selling_asset), f'price_in_{self.profit_currency.symbol}': rate_in_profit_currency, f'fee_in_{self.profit_currency.symbol}': total_fee_in_profit_currency, f'gained_or_invested_{self.profit_currency.symbol}': gain_in_profit_currency, 'amount': selling_amount, 'taxable_amount': taxable_amount, 'exchanged_for': exported_receiving_asset, exchange_rate_key: receiving_asset_rate_in_profit_currency, f'taxable_bought_cost_in_{self.profit_currency.symbol}': taxable_bought_cost, f'taxable_gain_in_{self.profit_currency.symbol}': taxable_profit_received, f'taxable_profit_loss_in_{self.profit_currency.symbol}': taxable_profit_formula, 'time': self.timestamp_to_date(timestamp), 'cost_basis': cost_basis_info.to_string(self.timestamp_to_date), 'is_virtual': is_virtual, f'total_bought_cost_in_{self.profit_currency.symbol}': total_bought_cost, }) paid_in_profit_currency = ZERO self.add_to_allevents( event_type=EV_SELL, location=location, paid_in_profit_currency=paid_in_profit_currency, paid_asset=selling_asset, paid_in_asset=selling_amount, received_asset=processed_receiving_asset, received_in_asset=processed_receiving_amount, taxable_received_in_profit_currency=taxable_profit_received, total_received_in_profit_currency=gain_in_profit_currency, timestamp=timestamp, is_virtual=is_virtual, taxable_amount=taxable_amount, taxable_bought_cost=taxable_bought_cost, total_bought_cost=total_bought_cost, cost_basis_info=cost_basis_info, )