td-ameritrade-python-api icon indicating copy to clipboard operation
td-ameritrade-python-api copied to clipboard

Chart History Futures Data

Open Jeffdunham1 opened this issue 5 years ago • 3 comments

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)

Jeffdunham1 avatar Dec 05 '20 07:12 Jeffdunham1

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

areed1192 avatar Dec 10 '20 02:12 areed1192

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.

rickfu415 avatar May 02 '21 15:05 rickfu415

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",
},

ak2k avatar Sep 15 '22 22:09 ak2k