How to Use the TD Ameritrade Python API Library | Pt. 1

Поделиться
HTML-код
  • Опубликовано: 16 сен 2024

Комментарии • 106

  • @FabledNarrative
    @FabledNarrative 4 года назад +29

    This video literally came out a few hours ago and someone already disliked it?
    This is an INCREDIBLY niche subject, that they took the time to wait for your upload to down vote it.
    Some people are entitled. : /
    Grateful you are providing much needed examples and clarification on the topic, man. :D

    • @retrofutur1st
      @retrofutur1st 3 года назад

      the dislike was prob from someone who can't get their redirect uri to work or json path :P

  • @futurestrad3r307
    @futurestrad3r307 4 года назад +41

    Great content as always. Just a few helpful tips for anyone watching this who downloaded the library recently through pip:
    In the TDClient object, update the following variable names to the ones on the right:
    consumer_id -> client_id
    json_path -> credentials_path
    Luckily, Sigma provided Intellicode snippets in VSCode so this was simple to figure out, buy others may be having trouble authenticating through the client.
    Thanks again!

    • @zezohassan4669
      @zezohassan4669 3 года назад

      Thank you!!! Easy to miss

    • @Bodybuilder900ml
      @Bodybuilder900ml 3 года назад

      bossman brotherman brotherman

    • @mattg8844
      @mattg8844 3 года назад

      Thank you!!!!!!!!

    • @mateostyle
      @mateostyle 2 года назад +1

      Got stumped and your comment was the life line!

  • @dillondriskill6403
    @dillondriskill6403 3 года назад +3

    This is such a niche subject, this is so awesome that you took the time to go through the (piss poor) documentation and made a REALLY functional library. If i've got a problem with the library its really easy for me to go into the code and look at the section im trying to use and see how its supposed to be used because you have made such well documented code, and made it so readable.
    Seriously, thank you.

  • @TRUSTMEN
    @TRUSTMEN Год назад +2

    OMG! Thanks for making this video! This video is so detailed for newbies like me. Very helpful! Every other video just says, "Download this and download that," and I'm like, "Download to where and how do you download it?"

  • @dominickmuniz
    @dominickmuniz 4 года назад +2

    This is the most under rated channel on RUclips. You should have way more views. We appreciate you. Thank you for your content!!!!! 💝

  • @CarlosLopez-ce9uo
    @CarlosLopez-ce9uo Год назад +1

    Muchas Gracias Panita!!! realmente aprecio mucho la información que nos regalas aquí, tan bien explicada!!

  • @mxbao1690
    @mxbao1690 4 года назад +2

    Great Video. Waiting for the streaming data part!

  • @keitharroyo4822
    @keitharroyo4822 2 года назад

    Thanks so much. Some parameters have changed since you posted, but able to figure it out. Working great so far!

  • @brettalanlistens3035
    @brettalanlistens3035 3 года назад +1

    I embed videos in notion so that I can take effective notes on the same page as the video. I think you should allow people to embed your videos.

  • @retrofutur1st
    @retrofutur1st 3 года назад

    So easy to understand! Thank you thank you thank you!

  • @thomasrichardson4402
    @thomasrichardson4402 3 года назад +2

    How do you fix the "no module named 'td' error?

  • @tyrellmccurbin8045
    @tyrellmccurbin8045 3 года назад +2

    Thanks for sharing! I have an app with hundreds of users and I can't afford to take the app down every 90 days. How can I automate the token renewal process?

  • @tommyhegarty97
    @tommyhegarty97 3 года назад +3

    Has anyone had any difficulties with calling the TDClient() instance? Apparently consumer_id and redirect_uri don't exist? Would love some help here, thanks!

  • @drnotebook
    @drnotebook 3 года назад +1

    The example files in github have changed a LOT since this video was made. I wish the videos matched the source code more. I have trouble mapping your terminology to the terminology of Tim Paine, Alex Golec, and the TD Ameritrade APIs themselves. Different terms are used to refer to the same things, like access_token, refresh_token, client_id, and so on. Could someone please provide a terminology mapping table for these different TDA API wrappers?

  • @thomasmacdonald2027
    @thomasmacdonald2027 3 года назад +1

    Hello
    Incredible video. I am building my first api with an extremly knowledgeable programmer. He is concerned about security abd would prefer if we made the API read only. For my purpose that is ok because I still want to trade in the TD ap or web or tos. So my question is there a read only key for TD? Or is there a view only username? Or is the streaming api read only ?

  • @umeshy
    @umeshy 4 года назад +1

    I like your videos, I want a confirmation is TD Ameritrade not support the OrderPlace request in WebSocket(faster way to send a request)?

  • @travislockman
    @travislockman 3 года назад

    Fantastic video good sir.

  • @dakotamacmillan8531
    @dakotamacmillan8531 3 года назад +1

    little confused on the callback url I am not tech savy and just wanted to follow along with this project

  • @krustyjonez7249
    @krustyjonez7249 3 года назад +1

    Hello. Thank you for the video. A single question. I have change consumer_id -> client and json_path -> credentials. On line 134 of client.py changed init to _init_ but getting an error that states:
    Traceback (most recent call last):
    File "d:/Users/b/hello/td/using_td_library.py", line 9, in
    td_client = TDClient.login()
    TypeError: login() missing 1 required positional argument: 'self'
    Any thoughts?

  • @chaddsmith3354
    @chaddsmith3354 Год назад

    Thank you for the video. They seem to have changed the login process. It keeps directing me to a login help screen that I can’t get past.

  • @robnotaro8584
    @robnotaro8584 3 года назад

    Excellent video and a new sub

  • @edmonddhyne5111
    @edmonddhyne5111 2 года назад

    The blue & red is a little hard to read on my screen. Where can I find the source code to your stock app?

  • @jnantes0
    @jnantes0 Год назад

    Great, once I decide to follow up this tutorial the Ameritrade API doesn't allow new registers due to charles schwab integration.

  • @behzadmehrdad
    @behzadmehrdad 4 года назад

    Hi, Thanks a lot for your videos!! Much appreciate it!

  • @cindycheung2282
    @cindycheung2282 3 года назад

    Hi, Alex! In this video, the process to login and get the access token is still fairly manual, but earlier videos already show an automated process for getting tokens. Why is it not used here?

  • @colestecyk9957
    @colestecyk9957 4 года назад

    Excellent, thanks!

  • @danielminchev4173
    @danielminchev4173 3 года назад

    Man you the best!

  • @sammorgan31
    @sammorgan31 2 года назад

    24:38 isn't working for me. I'm getting
    C:\Users\Sam>C:\Users\Sam\OptionBot\TDAmeritrade\SP500Bot.py
    Traceback (most recent call last):
    File "C:\Users\Sam\OptionBot\TDAmeritrade\SP500Bot.py", line 2, in
    from td.client import TDClient
    ModuleNotFoundError: No module named 'td.client'

  • @mr.r5058
    @mr.r5058 3 года назад

    Got a question: from td.client import TDClient
    Where is the td.client? Because my VSC says: import could not be resolved.

  • @oluade2068
    @oluade2068 2 года назад

    I'm having an error code "no module named config". What should I do?

  • @zemetor
    @zemetor 3 года назад +1

    How do you get a quote on options on futures (bid/ask)? can't get that through the quote method...

    • @SigmaCoding
      @SigmaCoding  3 года назад +1

      So with Futures Options, I was never able to get that one to work. It doesn't appear that it is supported.

  • @zezohassan4669
    @zezohassan4669 3 года назад

    Thank you so much for this! I have a couple of questions:
    1) I tried to use my paper trading account number but it didn't work for 'get positions and orders' and 'get transactions' part. Is there a way to connect the paper trading account? It'd be great to test out strategies.
    2) When I change the TD_ACCOUNT variable from my paper account to my real account, everything runs smooth except the 'get transactions' part, I get this error message:
    File "C:\Python39\lib\site-packages\td\client.py", line 1239, in get_transactions
    return self._make_request(method='get', endpoint=endpoint, params=params)
    File "C:\Python39\lib\site-packages\td\client.py", line 621, in _make_request
    raise ForbidError(message=response.text)
    td.exceptions.ForbidError: {
    "error" : "You don't have permission to access this resource."

  • @mikembs6927
    @mikembs6927 3 года назад +1

    Does this code still work w/ the latest library? one thing i noticed is that when creating a TDClient, what you refer to as consumer_id is now client_id, and i think json_path must now be credentials_path (not sure). Also, after creating the TDClient, calling the login method results in an exception for me: "Exception has occurred: OSError
    [Errno 22] Invalid argument"

    • @maxzaki7666
      @maxzaki7666 2 года назад +1

      Thanks for pointing that out, Mike. When I changed consumer_id to client_id, and json_path to credentials_path, it worked.

  • @jemyzhu9293
    @jemyzhu9293 2 года назад

    Can the thinkorswim account use on develop td-american?

  • @dereklane367
    @dereklane367 3 года назад +1

    When I run it I get an exception thrown at td_client.login() is
    "error" : "invalid_grant"
    any idea why that is?

    • @SigmaCoding
      @SigmaCoding  3 года назад

      Is this the first time you've logged in using the library? It'll help me isolate the possible issue.

  • @conraddcruz
    @conraddcruz 4 года назад +1

    Very nice and Thanks for the detailed video. I keep getting the pip error you got when trying to install td-ameritrade-python-api. This is the error: "ERROR: Could not find a version that satisfies the requirement td-ameritrade-python-api (from versions: none) ERROR: No matching distribution found for td-ameritrade-python-api". I have the latest pip installed and latest wheel and setuptools. Anyone else have that issue and if so, what did you do to solve it? Thanks.

    • @SigmaCoding
      @SigmaCoding  4 года назад +1

      Are you installing it using Anaconda? If you are keep in mind it's not hosted on Anaconda, so you won't be able to install it from there. Instead, you need to install it from PyPi.
      Here is the command to install it from PyPi:
      *pip install td-ameritrade-python-api*

    • @conraddcruz
      @conraddcruz 4 года назад

      @@SigmaCoding I have anaconda installed but was using that command (pip install td-ameritrade-python-api) from the windows command prompt (not the anaconda prompt). I will try again today.

  • @shawnlee8135
    @shawnlee8135 4 года назад

    Hi, thanks for the helpful video. is there a way to retrieve the token details without requiring the user to copy and paste the full redirect link ?

  • @santoshkudva5537
    @santoshkudva5537 3 года назад

    Am new to this. I am following the video...have the 3 statements...it is giving an error on the 3rd
    from td_config import CONSUMER_KEY, REDIRECT_URI, JSON_PATH
    from td_acct import ACCOUNT_NUMBER
    from td.client import TDClient
    Traceback (most recent call last):
    File "C:\Users\santo\PycharmProjects\pythonProject\td_get_historical.py", line 3, in
    from td.client import TDClient
    ModuleNotFoundError: No module named 'td'
    Appreciate any guidance.

  • @jameskerivan7005
    @jameskerivan7005 4 года назад

    Hi do you know why I would be seeing a permission denied in the library?
    PermissionError: [Errno 13] Permission denied: 'C:\\Users\\me\\.virtualenvs\\app-gRPm7x1S\\lib\\site-packages\\td'

  • @austinpatton3771
    @austinpatton3771 3 года назад

    I'm trying to create the JSON file that holds the access information but I'm not having any success. td_client.login() is returning true and td_client.authorized=true but td_client.logged_in=false after I successfully login through the link that it gives to authorize your account and paste the link back into the command prompt. I know the json file doesn't exist in a different folder than what I'm specifying because every single time I run the program it has me attempt to recreate the json file that holds the access information again. And then afterwards when I try to use td_client.get_quotes(), it throws an exception stating that I'm not authorized. Would you happen to know what I am doing wrong?
    EDIT: For some reason when I was running the Python script through the debugger in Visual Studio it wasn't generating the JSON file. But when I ran the script outside of Visual Studio through the command prompt it was able to generate the JSON file. The script functions normally otherwise within Visual Studio, so I have no idea why this is happening. If anyone has insight into why this would occur it would be greatly appreciated if you could share it with me.

  • @cmrncrick
    @cmrncrick Год назад

    Has anyone else ever gotten this error?
    ModuleNotFoundError: No module named 'td.utils.user_preferences'; 'td.utils' is not a package
    How have you resolved it? Thanks!

    • @cmrncrick
      @cmrncrick Год назад

      @Afshin Zarechian not really. It’s really funky for me. Sometimes it’ll work then sometimes it’ll give me some really whacky errors. Not sure why it does it.

  • @mykesmyth2082
    @mykesmyth2082 2 года назад

    is "td.client" not working for anybody else? im 3 lines in and stuff isnt working.

  • @ignacioa3698
    @ignacioa3698 4 года назад

    At the 24:36 mark right before commencing the 'authorization', it was not clear when you right-clicked. Did you just simply ran the program? If so, I tried doing and got the following error below. I also previously successfully installed the "pip install td-ameritrade-python-api
    " command under the terminal screen. I'm using Pycharm.
    Error messg:
    File "C:/Users/ignc/PycharmProjects/TDAmeritrade/using_td_library.py", line 1
    pip install td-ameritrade-python-api
    ^
    SyntaxError: invalid syntax

    • @SigmaCoding
      @SigmaCoding  4 года назад

      So, I don't use PyCharm but when you call pip install, do you need to lead it with "python pip install"? In Windows, I sometimes must do that.

    • @ignacioa3698
      @ignacioa3698 4 года назад

      @@SigmaCoding Thank you. Will try that as well.

  • @sebtaciak
    @sebtaciak 4 года назад

    Hi, in this video i can get all the way to the JSON creation after authentication but i am getting the following error
    IsADirectoryError: [Errno 21] Is a directory: '/Users/sebtac/Documents/AutoTrader/td-ameritrade'
    and it does not create the JSON nor does it allow me to do subsequent steps (returns "Validation was unsuccessful.")
    any idea why? i am on MAC if it makes a difference. (i tried different folders including just "" too.

    • @sebtaciak
      @sebtaciak 4 года назад +2

      ok solved!; learning for other viewers, the JSON_PATH is not just a PATH but also needs to specify the JSON file itself - this worked: JSON_PATH = "/Users/sebtac/Documents/AutoTrader/td-ameritrade/td_state.json"

  • @yardbirdmd
    @yardbirdmd 4 года назад

    Are there any pros/cons to using environment variables instead of a config file?

    • @abrahamkingsley9306
      @abrahamkingsley9306 4 года назад

      Basically I just want to testify about Mr Franklin, He is an account manager with differences, I have been trading with him for much longer than i can say and he has turned my life around, when I was about to loose my house to the bank, he introduced me to a strategy and software that helped me to make over $50,000 in forex market, I can boast with earnings from Mr Franklin trading experience, I don't depend on my salary anymore and I'm living the comfortable life, contact him on Franklinhambj11@gmail.com if you need help!

  • @r4mpy
    @r4mpy 4 года назад

    Hey, how does your VS code autocomplete all the various functions for your API?

    • @r4mpy
      @r4mpy 4 года назад

      Ah never mind, installing pylance over microsoft's own language server helped out. Thanks anyways :)

  • @mehulthakkar1410
    @mehulthakkar1410 4 года назад

    Hi,
    I am following your code but when I run the code, it does not create the json file. Any ways to fix this?
    Thanks

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Did you specify a file path in your TDClient object?

  • @rajyadav5484
    @rajyadav5484 4 года назад

    Hi, while installing it through pip on my terminal it throws the following error in pycharm.
    '''Could not find a version that satisfies the requirement td-ameritrade-python-api (from versions: )
    No matching distribution found for td-ameritrade-python-api'''

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Well that's odd, what was the full command you wrote?

    • @icdev2dev222
      @icdev2dev222 4 года назад

      You likely do not have the correct python version...>3.7

  • @dakotamacmillan8531
    @dakotamacmillan8531 3 года назад

    hi I know this is an older video but just started coding was wondering if you could help me out

  • @Alex-fd6hs
    @Alex-fd6hs 4 года назад

    I keep getting status code 403 when following along the video at the point where you attempt to get orders & positions using the get_accounts
    "error" : "You don't have permission to access this resource."
    I have checked the td_state.json and it appears to be creating that correctly & populating it. It seems to have no issue getting quotes & using the other APIs that don't require authentication.
    Any suggestions?

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Is the account number you're passing through match what is on your TD profile?

    • @Alex-fd6hs
      @Alex-fd6hs 4 года назад

      @@SigmaCoding It was an issue with my old Scottrade Account # vs TDAmeritrade Account #

  • @the4guysareback
    @the4guysareback 4 года назад

    TD seems to be blocking the url used for activation. Is this a new issue?

    • @abrahamkingsley9306
      @abrahamkingsley9306 4 года назад

      Basically I just want to testify about Mr Franklin, He is an account manager with differences, I have been trading with him for much longer than i can say and he has turned my life around, when I was about to loose my house to the bank, he introduced me to a strategy and software that helped me to make over $50,000 in forex market, I can boast with earnings from Mr Franklin trading experience, I don't depend on my salary anymore and I'm living the comfortable life, contact him on Franklinhambj11@gmail.com if you need help!

  • @_malik
    @_malik 4 года назад

    Hey can you help me out?
    After installing and running, I get this error:
    Traceback (most recent call last):
    File "/Users/me/Desktop/Projects/API Project/td_ameritrade.py", line 2, in
    from td.client import TDClient
    ImportError: No module named td.client
    I saw the other comment of the guy with the same issue but I don't understand how he fixed it.

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Did you install it to the right location? Sometimes when you run pip install it will install it in a different version of python. I've had that happen with people who have multiple versions of python installed.

    • @aaronlewitinn1940
      @aaronlewitinn1940 3 года назад +1

      @@SigmaCoding Can you be more clear in your answer ? What 's the right location ? What ' s the right version of python here ?

  • @yoonkit
    @yoonkit 4 года назад

    Hi, Thanks for the video. However after installing with pip (pip install td-ameritrade-python-api),
    When trying to import TDClient ( from td.client import TDClient
    ), I have this error:
    ===
    ---------------------------------------------------------------------------
    ModuleNotFoundError Traceback (most recent call last)
    in
    1 TD_ACCOUNT = "D-17784975"
    2
    ----> 3 from td.client import TDClient
    4 TDClient
    5
    C:\ProgramData\Anaconda3\lib\site-packages\td\client.py in
    18 from td.fields import VALID_CHART_VALUES
    19 from td.fields import ENDPOINT_ARGUMENTS
    ---> 20 from td.app.auth import FlaskTDAuth
    21 from td.oauth import run
    22 from td.oauth import shutdown
    ModuleNotFoundError: No module named 'td.app'
    ===
    Am I missing something?
    yk

    • @SigmaCoding
      @SigmaCoding  4 года назад +1

      Update it to version 0.2.8 this was a bug in my latest update.

    • @yoonkit
      @yoonkit 4 года назад

      @@SigmaCoding -
      Thanks for the info.
      I 'pip uninstall td-ameritrade-python-api'
      and 'pip --no-cache-dir install td-ameritrade-python-api'
      And it works. Well I thought I could get away without having to set a json file.
      Will work through this.

  • @MrFifths7
    @MrFifths7 4 года назад

    I keep getting the "invalid_grant" error response when simply trying to do the login method. The API documentation says that this is due to requesting an access code when you already have one or a refresh code when you don't have an access code. The other reasoning they give is that the auth code is not decoded properly. When I take the code from the URL and decode it and put all the same info on the web API, I get a good access token and refresh token. Can someone confirm that the auth code gets decoded before being posted to the API URL? I'm also using PyCharm and a virtual environment. Don't know if that matters, all the dependencies should have installed.

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Yes, the Authorization Code that's returned to you needs to be decoded before you make a request for the access token. Have you recently installed the latest library? That one has made some changes that should resolve that access token endpoints.

    • @MrFifths7
      @MrFifths7 4 года назад

      @@SigmaCoding I just got it to work properly in VS Code. It looks like it was a virtual env error with PyCharm and Anaconda. Thanks for this great work, can't wait for the trading algo videos!

    • @chaysemcmillan7962
      @chaysemcmillan7962 3 года назад +1

      If anyone ever see's this, I was pointing the JSON file to a misspelled directory. The link this program generates is only valid once per runtime. Don't copy the contents from the previous run and paste for the response. Double checking the json files final location (shouldnt need to exist), then pasting the redirect from the current runtime, I was able to successfully create the JSON file. Only took me a couple hours --- **facepalm**

    • @chaysemcmillan7962
      @chaysemcmillan7962 3 года назад

      this was for the "invalid_grant" response

  • @EmpowerVibes015
    @EmpowerVibes015 2 года назад

    how can i speak whit you please?

  • @kuntazulu
    @kuntazulu 4 года назад

    After installing the api successfully I get the following:
    using_td_library.py", line 7, in
    from td.client import TDClient
    ModuleNotFoundError: No module named 'td'

    • @SigmaCoding
      @SigmaCoding  4 года назад

      Did you install it to the right environment?

    • @kuntazulu
      @kuntazulu 4 года назад

      @@SigmaCoding I had a Python conflict between conda and brew installation, explicitly using conda version to resolve issue. Thanks. Now it runs, but one question. Can I skip the login and give the API key as a parameter? Somehow I get stuck at the login prompt to enter
      Please go to URL provided authorize your account: auth.tdameritrade.com/auth/?response_type=code&redirect_uri=https%3A%2F%2Flocalhost&client_id=xxxxxxxxxxxxxxxxxx%40AMER.OAUTHAP
      Paste the full URL redirect here:
      No matter what I paste it doesn't do anything...
      Last but not least it seems the API has evolved since you recorded this. I had to rename some of the login params. Please advise on best API version to use for this example.
      Thanks

    • @SigmaCoding
      @SigmaCoding  4 года назад

      @@kuntazulu If you're on Mac there is a bug with pasting the URL into the terminal in VS Code. For whatever reason, if it's over 1024 characters, it won't take it. There are a few ways around this. Run the script outside of VS Code or run the code multiple times until you get a redirect code that is less than 1024 characters.
      Regarding the code itself, yet it is changed dramatically since I made this video. If you go to the GitHub repo you'll see the latest version. If you want to install the latest version then do the following command
      pip install td-ameritrade-python-api==0.2.8

    • @kuntazulu
      @kuntazulu 4 года назад

      @@SigmaCoding I love you man! Ping me when you in DC area post covid. I owe you lunch. Thanks a bunch.

    • @aaronlewitinn1940
      @aaronlewitinn1940 3 года назад

      @@kuntazulu @Sigma Coding, where is td.client coming from ?

  • @Bodybuilder900ml
    @Bodybuilder900ml 3 года назад

    We got a NEGATIVE NANCY here with the "dislike". Don't be that guy!

  • @skimdt1
    @skimdt1 4 года назад

    When I try to run this:
    transactions = td_client.get_transactions(account = 'all', transaction_type='BUY_ONLY', symbol='MSFT', start_date = '2020-01-01', end_date = '2020-04-01'),
    I get this error output:
    {'error': "You don't have permission to access this resource."}
    Does something need to be enabled in the account?
    Note: Everything else seems to work fine.

    • @skimdt1
      @skimdt1 4 года назад

      Figured it out. Need to put in an account number for the account argument. 'all' doesn't seem to work.

    • @WakaFlacka
      @WakaFlacka 4 года назад

      @@skimdt1 I think 'ALL' is also trying to access your forex account. I was getting the same thing.

    • @SigmaCoding
      @SigmaCoding  4 года назад +1

      For the `get_transactions` endpoint, you can't use the `all` argument. That's only for the `get_accounts` endpoint. I'll probably have to add a new argument called `all` which is a boolen. That way it doesn't confuse people.

  • @jeremyclarkson6035
    @jeremyclarkson6035 3 года назад

    Wait a second... you start this series of videos with notes that say "At this point, we should have a pretty clear understanding of how the TD Ameritrade API works, how the library was built, and the different things the library can do"
    At what point this is video number one, shouldn't you put those notes on video number three or four etc?