Skip to content

Commit

Permalink
added coinledger cryptotradertax csv format
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgerpodger committed Mar 10, 2022
1 parent d33cb94 commit 105b9e5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/common/Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def export_format(self, format, csvpath):
self.export_zenledger_csv(csvpath)
elif format == et.FORMAT_TAXBIT:
self.export_taxbit_csv(csvpath)
elif format == et.FORMAT_COINLEDGER:
self.export_coinledger_csv(csvpath)
return csvpath

def export_default_csv(self, csvpath=None, truncate=0):
Expand Down Expand Up @@ -456,6 +458,61 @@ def export_cointracker_csv(self, csvpath):

logging.info("Wrote to %s", csvpath)

def export_coinledger_csv(self, csvpath):
""" Write CSV, suitable for import into CoinLedger (cryptotrader.tax) """
tags = {
et.TX_TYPE_AIRDROP: "Airdrop",
et.TX_TYPE_STAKING: "Staking",
et.TX_TYPE_TRADE: "",
et.TX_TYPE_TRANSFER: "Transfer",
et.TX_TYPE_INCOME: "Income",
et.TX_TYPE_SPEND: "Gift Sent",
et.TX_TYPE_BORROW: "Transfer",
et.TX_TYPE_REPAY: "Transfer",
}
rows = self._rows_export(et.FORMAT_COINLEDGER)

with open(csvpath, 'w', newline='', encoding='utf-8') as f:
mywriter = csv.writer(f)

# header row
mywriter.writerow(et.CL_FIELDS)

# data rows
for row in rows:
tag = tags[row.tx_type]
if tag == "Transfer":
if row.received_amount and not row.sent_amount:
tag = "Deposit"
if row.sent_amount and not row.received_amount:
tag = "Withdrawal"

line = [
self._coinledger_timestamp(row.timestamp), # Date (UTC)
"{}_blockchain".format(self.ticker.lower()), # Platform (Optional)
self._coinledger_code(row.sent_currency), # Asset Sent
row.sent_amount, # Amount Sent
self._coinledger_code(row.received_currency), # Asset Received
row.received_amount, # Amount Received
self._coinledger_code(row.fee_currency), # Fee Currency (Optional)"
row.fee, # Fee Amount (Optional)"
tag, # Type
row.comment, # Description (Optional)
row.txid # TxHash (Optional)
]
mywriter.writerow(line)

logging.info("Wrote to %s", csvpath)

def _coinledger_timestamp(self, ts):
# Convert "2021-08-04 15:25:43" to "08/14/2021 15:25:43"
dt = datetime.strptime(ts, "%Y-%m-%d %H:%M:%S")

return dt.strftime("%m/%d/%Y %H:%M:%S")

def _coinledger_code(self, currency):
return currency

def export_koinly_csv(self, csvpath):
""" Write CSV, suitable for import into Koinly """
NullMap.load(self.use_cache)
Expand Down
19 changes: 19 additions & 0 deletions src/common/ExporterTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FORMAT_DEFAULT = "default"
FORMAT_BALANCES = "balances"
FORMAT_ACCOINTING = "accointing"
FORMAT_COINLEDGER = "coinledger"
FORMAT_COINTRACKING = "cointracking"
FORMAT_COINTRACKER = "cointracker"
FORMAT_CRYPTOTAXCALCULATOR = "cryptotaxcalculator"
Expand All @@ -13,6 +14,7 @@
FORMAT_DEFAULT,
FORMAT_BALANCES,
FORMAT_ACCOINTING,
FORMAT_COINLEDGER,
FORMAT_COINTRACKING,
FORMAT_COINTRACKER,
FORMAT_CRYPTOTAXCALCULATOR,
Expand Down Expand Up @@ -229,6 +231,23 @@
CR_FIELD_FEE_CURRENCY, CR_FIELD_TAG, CR_FIELD_TRANSACTION_ID
]

# coinledger format
CL_FIELD_DATE = "Date (UTC)"
CL_FIELD_PLATFORM = "Platform (Optional)"
CL_FIELD_ASSET_SENT = "Asset Sent"
CL_FIELD_AMOUNT_SENT = "Amount Sent"
CL_FIELD_ASSET_RECEIVED = "Asset Received"
CL_FIELD_AMOUNT_RECEIVED = "Amount Received"
CL_FEE_CURRENCY = "Fee Currency (Optional)"
CL_FEE_AMOUNT = "Fee Amount (Optional)"
CL_TYPE = "Type"
CL_DESCRIPTION = "Description (Optional)"
CL_TXHASH = "TxHash (Optional)"
CL_FIELDS = [
CL_FIELD_DATE, CL_FIELD_PLATFORM, CL_FIELD_ASSET_SENT, CL_FIELD_AMOUNT_SENT, CL_FIELD_ASSET_RECEIVED,
CL_FIELD_AMOUNT_RECEIVED, CL_FEE_CURRENCY, CL_FEE_AMOUNT, CL_TYPE, CL_DESCRIPTION, CL_TXHASH
]

# koinly format
KOINLY_FIELD_DATE = "Date"
KOINLY_FIELD_SENT_AMOUNT = "Sent Amount"
Expand Down

0 comments on commit 105b9e5

Please sign in to comment.