Skip to content

Instantly share code, notes, and snippets.

@bgachenot
Last active February 11, 2021 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgachenot/0a6f377c8db73d5212e9b235bacbe31a to your computer and use it in GitHub Desktop.
Save bgachenot/0a6f377c8db73d5212e9b235bacbe31a to your computer and use it in GitHub Desktop.
A small Python utility to convert from Probit CSV format to cointracker CSV format
#!/usr/bin/env python3
import sys
from datetime import datetime
def main():
try:
csv_file = open(sys.argv[1], 'r')
except FileNotFoundError:
print("File not found. Exiting now...")
exit(1)
lines = csv_file.readlines()
count = 0
if "trade-history.csv" in csv_file.name:
for line in lines:
if (count == 0):
formated_file_content = "Date,Received Quantity,Received Currency,Sent Quantity,Sent Currency,Fee Amount,Fee Currency,Tag\n"
else:
date = datetime.strptime(line.split(',')[0], '%Y-%m-%d %H:%M:%S').strftime("%m/%d/%Y %H:%M:%S")
if (line.split(',')[4] == 'buy'):
received_quantity = round(float(line.split(',')[6]), 8)
received_currency = line.split(',')[2].split('-')[0]
sent_quantity = round(float(line.split(',')[7]), 8)
sent_currency = line.split(',')[2].split('-')[1]
elif (line.split(',')[4] == 'sell'):
received_quantity = round(float(line.split(',')[7]), 8)
received_currency = line.split(',')[2].split('-')[1]
sent_quantity = round(float(line.split(',')[6]), 8)
sent_currency = line.split(',')[2].split('-')[0]
else:
print("Not sell or buy for line {}\n{}".format(count + 1, line))
fee_amount = round(float(line.split(',')[9]), 8)
fee_currency = line.split(',')[8]
formated_file_content += "{},{},{},{},{},{},{},\n".format(date, received_quantity, received_currency, sent_quantity, sent_currency, fee_amount, fee_currency)
count += 1
export_filename = "export-trade.csv"
elif "transfer-history" in csv_file.name:
for line in lines:
if (count == 0):
formated_file_content = "Date,Received Quantity,Received Currency,Sent Quantity,Sent Currency,Fee Amount,Fee Currency,Tag\n"
else:
date = datetime.strptime(line.split(',')[0], '%Y-%m-%d %H:%M:%S').strftime("%m/%d/%Y %H:%M:%S")
received_quantity = round(float(line.split(',')[5]), 8)
received_currency = line.split(',')[3]
formated_file_content += "{},{},{},,,,\n".format(date, received_quantity, received_currency)
count += 1
export_filename = "export-transfer.csv"
else:
print("Please do not edit csv original filenames (trade-history.csv or transfer-history.csv)")
exit(1)
csv_formated_file = open(export_filename, 'w')
csv_formated_file.write(formated_file_content)
if __name__ == "__main__":
main()
@bgachenot
Copy link
Author

How to use this gist?
Go to probit and export both transaction history and trade history
Put the python file in a folder with your exported csv files and then, allow the script to be executed (chmod +x probit-converter.py)
Execute the script both times as the following:
./probit-converter.py trade-history.csv
./probit-converter.py transfer-history.csv

You have now two files named export-trade.csv and export-transfer.csv which you can directly import on CoinTracker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment