Skip to content

Instantly share code, notes, and snippets.

@llllvvuu
Created March 21, 2021 02:48
Embed
What would you like to do?
Convert FTX's transactions CSV format to CoinTracker's upload format for taxes
# 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