Skip to content

Instantly share code, notes, and snippets.

@BlinkyStitt
Created June 8, 2017 00:12
Show Gist options
  • Select an option

  • Save BlinkyStitt/2ebc8b542529bbc50d4e161b84e704a9 to your computer and use it in GitHub Desktop.

Select an option

Save BlinkyStitt/2ebc8b542529bbc50d4e161b84e704a9 to your computer and use it in GitHub Desktop.
"""Click script to handle exports from the crypto-only exchange, Poloniex."""
import csv
import click
@click.command()
@click.argument(
'loan_export',
type=click.File('rt'),
)
@click.argument(
'taxes_export',
type=click.File('wt'),
)
def loans2taxes(loan_export, taxes_export):
"""Convert Poloniex export to bitcoin.tax compatible csv."""
loan_reader = csv.DictReader(loan_export)
tax_writer = csv.writer(
taxes_export,
)
tax_writer.writerow(['Date', 'Action', 'Memo', 'Source', 'Symbol', 'Volume'])
for row in loan_reader:
tax_writer.writerow([
row['Close'],
'INCOME',
'{volume} {symbol} @ {rate:.2f}% on {date}'.format(
volume=row['Amount'],
symbol=row['Currency'],
rate=float(row['Rate']) * 100,
date=row['Open'],
),
'Poloniex Lending',
row['Currency'],
row['Earned'], # TODO: eventually smartlend will take a fee
])
if __name__ == '__main__':
loans2taxes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment