diff --git a/crypto_tax/__main__.py b/crypto_tax/__main__.py index 34233c1..8c22c01 100644 --- a/crypto_tax/__main__.py +++ b/crypto_tax/__main__.py @@ -15,6 +15,11 @@ KUCOIN_CLIENT = fin_depo.defi_kucoin.KucoinDepoFetcher( secrets.KUCOIN_PASS, ) +KRAKEN_CLIENT = fin_depo.defi_kraken.KrakenDepoFetcher( + secrets.KRAKEN_KEY, + secrets.KRAKEN_SECRET, +) + @dataclasses.dataclass class BoughtAndSold: @@ -29,15 +34,20 @@ class BoughtAndNotYetSold: def compute_tax(transfers: list): + transfers.sort(key=lambda t:t.executed_time) + + bought_and_sold_for: list[BoughtAndSold] = [] + bought_and_spent_for: list[BoughtAndSold] = [] prices_bought_for: dict[Asset, deque[BoughtAndNotYetSold]] = {} - prices_bought_for[MPC] = deque() - prices_bought_for[MPC].append(BoughtAndNotYetSold(AssetAmount(MPC, Decimal(100)), datetime.datetime(2000, 1,1,1,1,1,1))) - prices_bought_for[USDT] = deque() - prices_bought_for[USDT].append(BoughtAndNotYetSold(AssetAmount(USDT, Decimal(100)), datetime.datetime(2000, 1,1,1,1,1,1))) + if False: + prices_bought_for[MPC] = deque() + prices_bought_for[MPC].append(BoughtAndNotYetSold(AssetAmount(MPC, Decimal(100)), datetime.datetime(2000, 1,1,1,1,1,1))) + prices_bought_for[USDT] = deque() + prices_bought_for[USDT].append(BoughtAndNotYetSold(AssetAmount(USDT, Decimal(100)), datetime.datetime(2000, 1,1,1,1,1,1))) - def sell(amount: AssetAmount, executed_time: datetime.datetime): + def sell(amount: AssetAmount, executed_time: datetime.datetime, spent=False): print(f'Selling: {amount}') while amount.amount > 0: if len(prices_bought_for[amount.asset]) == 0: @@ -60,10 +70,16 @@ def compute_tax(transfers: list): del new_partial # Add FIFO like - bought_and_sold_for.append(BoughtAndSold(amount_covered_by_partial, partial.time_bought, executed_time)) + if spent: + bought_and_spent_for.append(BoughtAndSold(amount_covered_by_partial, partial.time_bought, executed_time)) + else: + bought_and_sold_for.append(BoughtAndSold(amount_covered_by_partial, partial.time_bought, executed_time)) del partial, amount_covered_by_partial + def spend(amount: AssetAmount, executed_time: datetime.datetime): + print(f'Spending: {amount}') + sell(amount, executed_time, spent=True) for transfer in transfers: print(transfer) @@ -79,7 +95,12 @@ def compute_tax(transfers: list): if _input := transfer.input: print('Sell') sell(_input, transfer.executed_time) - del transfer, _input + del _input + + if fee := transfer.fee: + print('Sell') + spend(fee, transfer.executed_time) + del transfer, fee if True: print('Bought for:') @@ -108,7 +129,10 @@ def compute_tax(transfers: list): def main(): """Main function.""" - TRANSFERS = list(KUCOIN_CLIENT._get_double_registers()) + TRANSFERS = list(KRAKEN_CLIENT._get_double_registers()) + for k in TRANSFERS: + print(k) + #TRANSFERS += list(KUCOIN_CLIENT._get_double_registers()) compute_tax(TRANSFERS)