Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kraken: Action Types in CSV Exports #100

Merged
merged 26 commits into from
Mar 19, 2022
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ad3563d
updated Kraken mapping
Griffsano Jan 2, 2022
75e027d
different way of handling Kraken exports
Griffsano Jan 2, 2022
7cef9ac
removed trailing whitespace
Griffsano Jan 2, 2022
d49bd63
try inverse pair if Kraken pair is invalid
Griffsano Jan 3, 2022
fbf0609
reduce number of margin trading warnings
Griffsano Jan 3, 2022
9f377f3
allow future timestamp for virtual sells
Griffsano Jan 3, 2022
c71d9e1
address review comments - WIP
Griffsano Jan 4, 2022
e9d809d
reworked Kraken API warnings/errors
Griffsano Jan 5, 2022
1b78544
throw error for margin trades
Griffsano Jan 6, 2022
883c3e5
updated handling of Kraken deposits/withdrawals
Griffsano Jan 15, 2022
4722b63
updated Kraken API handling of latest trade prices
Griffsano Jan 16, 2022
5870134
updated type annotation
Griffsano Jan 23, 2022
c03b90f
added Optional[str] to str conversion
Griffsano Jan 23, 2022
31cba9a
stake rewarded coins
Griffsano Jan 26, 2022
1870cd1
UPDATE Specify error message when refid parameters doe not match
provinzio Feb 5, 2022
ca11a5d
UPDATE autoformat
provinzio Feb 5, 2022
adb45e4
UPDATE deposit logic, ADD comment for staking rewards
Griffsano Feb 6, 2022
e250176
REFACTOR store invalid API Kraken pairs in list and don't try them again
Griffsano Feb 19, 2022
f002f02
REFACTOR handling of Kraken deposits/withdrawals
Griffsano Feb 19, 2022
2385dfe
ADD create_operation and append_created_operation
Griffsano Feb 20, 2022
f461f5f
REFACTOR handling of deposits/withdrawals based on stored operation c…
Griffsano Feb 20, 2022
99baef5
REFACTOR create_operation, append_operation
Griffsano Feb 20, 2022
09817ed
AUTOFORMAT book
provinzio Mar 19, 2022
7a05a50
FIX typo
provinzio Mar 19, 2022
20d521d
CHANGE raise TypeError instead of RuntimeError for wrong type
provinzio Mar 19, 2022
6ccfdc0
UPDATE shorten comment to fit into line
provinzio Mar 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions src/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,6 @@ def _read_kraken_ledgers(self, file_path: Path) -> None:
assert coin
assert change

# append all operations to main list per default
# will be overwritten for deposits / withdrawals
append_operation = True

# Skip duplicate entries for deposits / withdrawals and additional
# deposit / withdrawal lines for staking / unstaking / staking reward
# actions.
Expand All @@ -612,44 +608,66 @@ def _read_kraken_ledgers(self, file_path: Path) -> None:
# The "appended" flag stores if an operation for a given refid has
# already been appended to the operations list:
# == None: Initial value, this is the first occurence
# == False: No operation has been appended, this is the second occurene
# == False: No operation has been appended, this is the second occurence
# == True: Operation has already been appended, this should not happen
if operation in ["Deposit", "Withdrawal"]:
# First, create the operations
op = self.create_operation(
operation, utc_time, platform, change, coin, row, file_path
)
op_fee = None
if fee != 0:
op_fee = self.create_operation(
"Fee", utc_time, platform, fee, coin, row, file_path
)
# If this is the first occurence, set the "appended" flag to false
# and don't append the operation to the list. Instead, store the
# data for verifying or appending it later.
if self.kraken_held_ops[refid]["appended"] is None:
append_operation = False
self.kraken_held_ops[refid]["appended"] = False
self.kraken_held_ops[refid]["operation"] = operation
self.kraken_held_ops[refid]["utc_time"] = utc_time
self.kraken_held_ops[refid]["platform"] = platform
self.kraken_held_ops[refid]["change"] = change
self.kraken_held_ops[refid]["coin"] = coin
self.kraken_held_ops[refid]["row"] = row
self.kraken_held_ops[refid]["file_path"] = file_path
self.kraken_held_ops[refid]["fee"] = fee
self.kraken_held_ops[refid]["operation"] = op
self.kraken_held_ops[refid]["operation_fee"] = op_fee
# If this is the second occurence, append a new operation, set the
# "appended" flag to True and assert that the data of this operation
# agrees with the data of the first occurence.
elif self.kraken_held_ops[refid]["appended"] is False:
append_operation = True
self.kraken_held_ops[refid]["appended"] = True
try:
assert (
operation == self.kraken_held_ops[refid]["operation"]
isinstance(
type(op),
type(self.kraken_held_ops[refid]["operation"])
)
), "operation"
assert (
change == self.kraken_held_ops[refid]["change"]
op.change == \
self.kraken_held_ops[refid]["operation"].change
), "change"
assert coin == self.kraken_held_ops[refid]["coin"], "coin"
assert (
op.coin == \
self.kraken_held_ops[refid]["operation"].coin
), "coin"
except AssertionError as e:
log.error(
f"{file_path} row {row}: Parameters for refid {refid} "
f"({operation}) do not agree: {e}. "
"Please create an Issue or PR."
)
raise RuntimeError
# For deposits, this is all we need to do before appending the
# operation. For withdrawals, we need to append the first
# withdrawal as soon as the second withdrawal occurs. Therefore,
# overwrite the operation with the stored first withdrawal.
if operation == "Withdrawal":
op = self.kraken_held_ops[refid]["operation"]
op_fee = self.kraken_held_ops[refid]["operation_fee"]
# Finally, append the operations and delete the stored
# operations to reduce memory consumption
self.append_created_operation(op)
if op_fee:
self.append_created_operation(op_fee)
self.kraken_held_ops[refid]["operation"] = None
self.kraken_held_ops[refid]["operation_fee"] = None
Griffsano marked this conversation as resolved.
Show resolved Hide resolved
# If an operation with the same refid has been already appended,
# this is the third occurence. Throw an error if this happens.
elif self.kraken_held_ops[refid]["appended"] is True:
Expand All @@ -668,22 +686,8 @@ def _read_kraken_ledgers(self, file_path: Path) -> None:
)
raise RuntimeError

# For deposits, this is all we need to do.
# For withdrawals, we need to append the first withdrawal as soon as
# the second withdrawal occurs. Therefore, overwrite the variables
# with the data of the first withdrawal and append it.
if append_operation and operation == "Withdrawal":
# required for type annotation: convert Optional[str] to str
operation = str(self.kraken_held_ops[refid]["operation"])
utc_time = self.kraken_held_ops[refid]["utc_time"]
platform = self.kraken_held_ops[refid]["platform"]
change = self.kraken_held_ops[refid]["change"]
coin = self.kraken_held_ops[refid]["coin"]
row = self.kraken_held_ops[refid]["row"]
file_path = self.kraken_held_ops[refid]["file_path"]
fee = self.kraken_held_ops[refid]["fee"]

if append_operation:
# for all other operation types
else:
self.append_operation(
operation, utc_time, platform, change, coin, row, file_path
)
Expand Down