Skip to content

Instantly share code, notes, and snippets.

@jhodges10
Last active April 9, 2018 03:48
Show Gist options
  • Save jhodges10/760a196275e6599a1d056258cc72f82c to your computer and use it in GitHub Desktop.
Save jhodges10/760a196275e6599a1d056258cc72f82c to your computer and use it in GitHub Desktop.
Export Liqui trades via the API to a Bitcoin Tax compatible CSV
from liqui import Liqui # https://pypi.python.org/pypi/liqui
import datetime
import pandas as pd
api_key = 'YOUR_API_KEY'
api_secret = 'YOU_API_SECRET'
csv_filename = 'liqui_tx.csv'
def convert_timestamp_to_day(timestamp):
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
def fetch_tx_history():
liqui = Liqui(api_key,api_secret)
tx_history = liqui.trade_history()
return tx_history
def pair_converter(pair):
pair_in, pair_out = pair.split('_')
return pair_in, pair_out
def clean_tx_history(tx_hisory_ugly):
c_tx_h = []
for tx in tx_hisory_ugly:
tx_info = tx_hisory_ugly[tx]
pair_in, pair_out = pair_converter(tx_info['pair'])
c_tx_h.append({
'symbol': pair_in,
'type': tx_info['type'],
'amount': tx_info['amount'],
'rate': tx_info['rate'],
'currency': pair_out,
'timestamp': tx_info['timestamp'],
'date': convert_timestamp_to_day(tx_info['timestamp'])
})
return c_tx_h
def dump_to_csv(cleaned_tx_list):
pd.DataFrame(cleaned_tx_list).to_csv(csv_filename, header=True, index=False)
return True
ugly_tx = fetch_tx_history()
clean_tx = clean_tx_history(ugly_tx)
for line in clean_tx:
print(line)
dump_to_csv(clean_tx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment