1
0

Test with Kraken; seems to work nicely

This commit is contained in:
Jon Michael Aanes 2024-12-22 06:03:47 +01:00
parent 236bca6dd7
commit 0e9ba95545
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

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