areed1192 / td-ameritrade-python-api

Unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard API and allows users to build data pipelines for the Streaming API.
MIT License
684 stars 252 forks source link

Chart History Futures Data #132

Open Jeffdunham1 opened 3 years ago

Jeffdunham1 commented 3 years ago

Hi, I ran the code below and when it writes the data to a csv this is the output

CHART_HISTORY_FUTURES | key | symbol | /MES CHART_HISTORY_FUTURES | 0 | key | 1 CHART_HISTORY_FUTURES | 1 | chart-time | 0 CHART_HISTORY_FUTURES | 2 | open-price | 6465 CHART_HISTORY_FUTURES | 0 | key | 1.61E+12 CHART_HISTORY_FUTURES | 1 | chart-time | 3619.75 CHART_HISTORY_FUTURES | 2 | open-price | 3620.75 CHART_HISTORY_FUTURES | 3 | high-price | 3619.5 *CHART_HISTORY_FUTURES | 4 | low-price | 3620.25 CHART_HISTORY_FUTURES | 5 | close-price | 194

For every low price and high price they seem to be swapped, close prices and open prices aren't recorded right. I am a novice so there must be something I am missing or is this just an error? I did run this after market hours or globex for futures so this might influence it. My best guess is that I open the .csv files in excel which might affect it.

//Import the client, import session information import datetime from config import client_id, redirect_uri from td.client import TDClient

//Create a new session, credentials path is optional. TDSession = TDClient( client_id=client_id, redirect_uri=redirect_uri, )

//Login to the session TDSession.login()

//Create a streaming client TDStreamingClient = TDSession.create_streaming_session()

//Set the data dump location. TDStreamingClient.write_behavior( write='csv', file_path="D:/ALPHA Test/Data/raw_data.csv", append_mode=True ) //Grab Chart History for the past 5 days TDStreamingClient.chart_history_futures( symbol=['/MES'], frequency='m1', period='d5' //Tried to use calculated epoch time, start_time, and end_time doesn't work though //start_time='1586304000000', //end_time='1586329200000' )

//Output the stream TDStreamingClient.stream(print_to_console=True)

areed1192 commented 3 years ago

Hey, @Jeffdunham1 thanks for bringing this to my attention I'll try to address it before the next release.

rickfu415 commented 3 years ago

i had a 'dirty' fix: 1, comment out line 189, file stream.py, all_data.append(data) 2, change the "CHART_HISTORY_FUTURES" numbering, from line 717 to 722.

ak2k commented 2 years ago

Hi @areed1192, When running against latest src, the above field mapping issue still exists. Just documenting in case others come across this.

revising the CSV_FIELD_KEYS structure's CHART_HISTORY_FUTURES block in the https://github.com/areed1192/td-ameritrade-python-api/blob/master/td/enums.py file as the below seems to clean it up, but I'm still testing:

"CHART_HISTORY_FUTURES": {
    "seq": "chart-sequence",
    "key": "symbol",
    "0": "chart-time",
    "1": "open-price",
    "2": "high-price",
    "3": "low-price",
    "4": "close-price",
    "5": "volume",
},