Convert FTX's transactions CSV format to CoinTracker's upload format for taxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3.7+ | |
# Usage: Download `trades.csv` from FTX.US, run this, and upload `cointracker.csv` to CoinTracker. | |
if __name__ == '__main__': | |
import csv | |
from datetime import datetime | |
trades = [] | |
with open('trades.csv') as f: | |
reader = csv.DictReader(f) | |
for row in reader: | |
trade = {} | |
trade['Date'] = datetime.fromisoformat(row['time']).strftime("%m/%d/%Y %H:%M:%S") | |
trade['Fee Amount'] = row['fee'] | |
trade['Fee Currency'] = row['feeCurrency'] | |
pair = row['market'].split('/') | |
amounts = row['size'], float(row['price']) * float(row['size']) | |
if row['side'] == 'sell': | |
trade['Sent Currency'], trade['Received Currency'] = pair | |
trade['Sent Quantity'], trade['Received Quantity'] = amounts | |
else: | |
trade['Received Currency'], trade['Sent Currency'] = pair | |
trade['Received Quantity'], trade['Sent Quantity'] = amounts | |
trades.append(trade) | |
with open('cointracker.csv', 'w') as f: | |
writer = csv.DictWriter(f, ['Date', 'Received Quantity', 'Received Currency', | |
'Sent Quantity', 'Sent Currency', 'Fee Amount', 'Fee Currency']) | |
writer.writeheader() | |
writer.writerows(trades) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment