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

the order status from api is wrong #188

Open weiguang-zz opened 3 years ago

weiguang-zz commented 3 years ago

Has anyone encountered this problem?The order status synchronized from the api is different from the order status on thinkorswim.

for example: Below is the order status of thinkorswim image

the status from the get order api: image

It seems that the API has a high latency.

looking forward to you reply, thank you.

duncanmcdonald commented 3 years ago

Did you authenticate using an access token or just the apikey? Using an apikey will have a delayed response.

weiguang-zz commented 3 years ago

I have used the access token

Dro92 commented 3 years ago

The API doesn't ingest data from Thinkorswim, it ingests it directly from TD. Try comparing the order flow data you are getting to that from TD, as there may be a slight delta.

While they "should" be the same, there are noticeable occassions where TD data is different than Thinkorswim data. Example being options chain values.

Alanavai commented 3 years ago

@Dro92 Could you help me out with the credentials_path? When I run the script, I get the follow error: 'The credential file does not contain expiration times for your tokens, please go through the oAuth process.' Because my json file is never created.

Dro92 commented 3 years ago

@Dro92 Could you help me out with the credentials_path? When I run the script, I get the follow error: 'The credential file does not contain expiration times for your tokens, please go through the oAuth process.' Because my json file is never created.

Might want to take this discussion off this ticket and make a new one, but try verifying that your config.py is proper. It should have a field JSON_PATH = 'your/path'

Alanavai commented 3 years ago

@Dro92 It started working when I used a new callback URL. Thanks

Jmarks199 commented 3 years ago

I can confirm unusual order status values received from the API, but it's unrelated to this library and I don't see a way to fix it. Orders that I clearly cancelled and even received the cancelled callback for are still showing status = 'QUEUED' even the next day when I request the order details. Seems like a TD bug unfortunately.

weiguang-zz commented 3 years ago

@Jmarks199 I have send emails to api@tdameritrade.com and find the reasons: The messaging delays are more than likely related to having advanced features enabled on your account. The solution is: send email to api@tdameritrade.com to turn off the advanced features of thinkorswim.

areed1192 commented 3 years ago

Yeah, you have to be careful when trying to compare operations using the API and operations in Thinkorswim. They are two different servers and have two different APIs, so you'll often find that information doesn't match.