joshfraser / robinhood-to-csv

Python script to export Robinhood trades to a CSV file
MIT License
259 stars 109 forks source link

in generated csv file, the field name mismatch with value #53

Open Momingjian opened 4 years ago

Momingjian commented 4 years ago

The field name mismatch with its value. For example in my generated file:

executed_notional | execution_state | extended_hours | fees {u'currency_id': u'1072fc76-1862-41ab-82c2-485837590762' | u'amount': u'903.80' | u'currency_code': u'USD'} | completed

jlothringer commented 4 years ago

When the file is read as comma delimited, commas within the executed_notional limit buy/sell field (which is a dictionary) cause that column to be read as three separate columns and this spills over to execution_state and extended_hours. The same is true for the total_notional column.

For a very quick fix, I've added the following snippet at line 74 of csv_export.py:

    if order['executed_notional'] is not None:
        order['executed_notional'] = order['executed_notional']['currency_id']+' | '+order['executed_notional']['amount']+' | '+order['executed_notional']['currency_code']
    if order['total_notional'] is not None:
        order['total_notional'] = order['total_notional']['currency_id']+' | '+order['total_notional']['amount']+' | '+order['total_notional']['currency_code']
DeqingSun commented 3 years ago

When the file is read as comma delimited, commas within the executed_notional limit buy/sell field (which is a dictionary) cause that column to be read as three separate columns and this spills over to execution_state and extended_hours. The same is true for the total_notional column.

For a very quick fix, I've added the following snippet at line 74 of csv_export.py:

    if order['executed_notional'] is not None:
        order['executed_notional'] = order['executed_notional']['currency_id']+' | '+order['executed_notional']['amount']+' | '+order['executed_notional']['currency_code']
    if order['total_notional'] is not None:
        order['total_notional'] = order['total_notional']['currency_id']+' | '+order['total_notional']['amount']+' | '+order['total_notional']['currency_code']

it seems last_trail_price may have the same issue.

        if order['executed_notional'] is not None:
            order['executed_notional'] = order['executed_notional']['currency_id']+' | '+order['executed_notional']['amount']+' | '+order['executed_notional']['currency_code']
        if order['total_notional'] is not None:
            order['total_notional'] = order['total_notional']['currency_id']+' | '+order['total_notional']['amount']+' | '+order['total_notional']['currency_code']
        if order['last_trail_price'] is not None:
            order['last_trail_price'] = order['last_trail_price']['currency_id']+' | '+order['last_trail_price']['amount']+' | '+order['last_trail_price']['currency_code']