The Github is now a pypi package, the installation is detailed in the readme. The next video on streaming also shows a short introduction on the usage of the new package: ua-cam.com/video/t7F2dUecgWc/v-deo.html
Downloaded your Git files, installed Python 3.12 and Visual Studio Code, got my app approved by Schwab, and was able to make the connection to Account Details
There are many people teaching programming on youtube, you are by far, the most comprehensive when making sure the listener understands where lines of code go back to or functions. We need websockets for RTD :)
Thank you for creating this video! I was needing to switch my python code from my TDA api app to Schwab and the authentication is much different. I also use pycharm. This is great as I had several formatting issues I found. Your video helped me fix them and now I was able to get price histories. Now I need to look at implementing the refresh token so I can extend the use time.
Thank you for the Github repo as well. One suggestion I have is to use a Python code formatter like black to reformat your code. That way your code will be much more readable and easier to follow.
Ok, I have been using the TDA API in Google Sheets to pull option prices, and to do that I only had to add a parameter to my request url for an apikey. I cannot figure out how to do that simple thing with the Schwab api. Any suggestions? Why do they make you jump through all the oAuth crap just to pull market data? I am not creating a trading bot or entering orders. I just want to analyze option price data in Google Sheets.
Thank you for posting this, very helpful! Do you have to re-authentic every 7 days if just getting market data or is that just for account specific data? Do you have Git files for one that just goes after market data? Thanks again for putting this out here. I’ve subscribed and look forward to more videos.
Tyler, First, thank you, thank you, thank you -- very helpful information. Second, when you login (you pull your login screen off to the side - which I appreciate) are you logging into a Schwab account or a TDA account? Thank you, Paul Gundersen
Great stuff - Please keep it coming - When you have time, please provide fully automated syntax examples on things like getting account balance, placing trades based on percentage of account balance, looping and getting a stock price every second, and a couple basic trading strategy examples on things like buying/selling based on sma
@@robertcameron4288 Life is about getting views though so he would be dumb not to do what his viewers are requesting. If not him than I or someone else will do it and get all the big bucks from youtube!
Thank you very much, that's excellent work!. I completely agreed with the very annoying change for the refresh token expiration from 90 days down to 7.... We now have no choice but to automate this process, hopefully Schwab can fix that. Logging in manually is just NOT something I enjoy doing weekly while using multiple machines. Please let us know if you have follow up on that news or automation for the refresh token. THANKS
@@tylerebowers hopefully this happen sooner than later. At the mean time, I’ll checkout playwright and see if I can work around it for now. I heard some user have successfully automated this process. I am still waiting for my pending approval… lol
@tylerbowers I followed the steps and got all the way to the end where you got a link (at 13:34 minutes into the recording) but I got an error saying "we were unable to complete your request. Please contact customer support for further assistance" any thought or any idea who I need to contact?
I cannot get the authorize request to work. If I use the "AppKey" it fails with "There was an unexpected error (type=Internal Server Error, status=500)." I found a client_id when using the app request page and by watching the traffic... it lets me log in and returns back to the test page but at no point do I see the "code"
Hey @tylerebowers - thanks for the video! This is really helpful. I am unable to get real time data for index using this API. is there any additional configuration that needs to happen to fetch pull real time data?
Thank you so so so so much. I really love the content! Is there a way to send authentication to my phone once the refresh token is about to expire? This way, I can authenticate with my phone again using something like face ID and the refresh token is refreshed.
Hey Tyler I still use the TDA API, but now trying to convert to Schwab I am following your tutorial, however i do not understand how do you refresh the access token with the refresh token. Do you have the request headers and payload data scheme.
This is great! thanks! so how do you refresh the token or use the refresh token? It seems like once the original token expires, you have to do the whole login thing again
Access token expires in 30 mins, refresh in 7 days. The GitHub program refreshes automatically. Schwab is working on a way to make it easier to deal with the refresh token so that you don’t have to manually authenticate every 7 days.
hello sir!! on the Schwab API, I could not find API to get a list of my current open positions, for example the list of stocks and options that i currently hold, am I missing something?
@@prakashparasuram7088 in the GitHub docs/ folder I have every api call possible documented as well as additional documentation for the client and streamer etc…
For the refresh token there is currently no way to automate it that wouldn’t go against Schwab’s policy. Since I have a public package I do not want to implement anything that would do that. I have also heard that their login page blocks attempts at automated logins and I believe that someone have gotten banned. So it’s quite the risk to do so.
Tyler, thanks a lot for the video. Question - when logging in to get the redirect url, do you log in with the developer ID? If I remember it correctly, they forced that to be an email address. I tried that ID but it says invalid ID/password. My TD brokerage accounts are not migrated to Schwab yet. However, I have created the developer account and registered an app in Schwab and I was hoping I could test the authentication. Do I need to wait for the accounts to migrate over?
Hey Tyler, great tutorial, thanks for making it! It was a lot of help. Quick question - have you received any real data from the order requests? I'm sending the correct parameters like to/from entered time, status, etc..., and the status_code is coming back 200, but the array is empty even though I have order data of status and in time frame on my Schwab account.
You can get the order ID of the successful order like this: "orderID = resp.headers.get('location', '/').split('/')[-1]" This example is also in the github main.py.
@@tylerebowers I'm just wondering if you're getting actual data back from like a simple '/orders' request. I'm able to get data from '/accounts' requests, but 'orders' and 'transactions' data returns an empty array, even though I know I have data in my Schwab account in my specified parameters.
Anyone knows if the developer account can be different than the Schwab account with Trading Accounts ? I have developer login that is different than trading account logins and when I try to get the initial token and have the code open. browser, I can't login using developer account there. But when I log in using credentials for Schwab account with Trading accounts, then I can sign in and select the accounts but it stops short of giving me the token/access_token and fails.
Yes, as far as I am aware they can be different. The developer account is for the app, and the broker account is the one that you link to the app when you sign in.
Thank you Tyler. This and the github helps a lot. I am using now for the access to ameritrade api session instead of requests. I am not sure if this difference impacts performance. What do you think?
@@tylerebowers Apparently YT blocks my response if it includes links. I access TDAmeritrade api hundreds of times a day. So, I use sessions. I copy the comment I wanted to show to you: "The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3‘s connection pooling. So if you’re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase"
@@danielfutterweit4182 I see, I’m not sure how well that would work with Schwab. I think using sessions does violate REST but it really depends on the implementation. You shouldn’t really need to make a ton of api calls once websocket streaming comes out from Schwab.
Many thanks for this. I wonder whether anyone else is having the same login problem I'm having. I created the app on the Schwab developer site so I have the app key and app secret. When I execute the code I go to the login page, then the page where I accept the agreements. Up to that point it's just as it appears in the video. However, the next page that comes up in the video is a page where the user selects which account to link to, which then goes to a blank page with the URL to be copied. For me, after I accept the agreements the next page is just the generic Schwab login page. If I enter the login information again, it just keeps going through the same loop. I'm using a Schwab account, not a TD account. Any thoughts on what might be happening and how I can correct it would be greatly appreciated.
Good work on this. really helped me a lot in converting from td to schwab. but place trade isn't working for me. As soon as it is placed it is getting cancelled. any params missing on it?
@@tylerebowers yeah. i am using the github code # place an order (uncomment to test) i am getting 201 response but schwab immediately cancel the trade.
Hi Tyler, Thanks for the great video. I am having issue with "from modules import terminal". I have just the same project structure as your git version, but can't recognize 'terminal'. What I'm doing wrong? Thanks
@@tylerebowers terminal.py is there, still getting unresolved reference for modules and terminal Sorry. After reviewing this, I think it may be because I included your project as a directory into an existing project. I just want to use your re-authentication part in my project. Can I just add those functions?
@@tylerebowers Now, I'm using your original git version, running from main.py. Its only authenticated first time. Subsequent run an gives me errors like below: [INFO]: Access token last updated: 2024-05-17 21:26:53 (expires in -41562 seconds) [INFO]: Refresh token last updated: 2024-05-17 21:26:53 (expires in 7 days) [INFO]: The access token has expired, updating automatically. [ERROR]: Could not get new access token. [INFO]: Filling account number and account hash -> Error [ERROR]: Could not get account numbers and account hash. [ERROR]: Please make sure that your app status is "Ready For Use" and that the app key and app secret are valid. [ERROR]: {'errors': [{'id': 'd0d9----- ....', 'status': 401, 'title': 'Unauthorized', 'detail': 'Client not authorized'}]} ... ... What I'm doing wrong? Thanks so much for your time.
i had the same problem on windows. i just renamed the modules folder to "utilities" and in the code. my python was resolving to another package that had the same name.
Thanks for posting, as official Schwab documentation is clearly lacking. In your code, I see an orderObject, but can't find the class. What is the format for placing orders? Also do you know if you can use a virtual/paper account?
@@enriquehoja9767 The tab is currently missing from the dev website, normally you would go here: API Products -> Accounts and Trading Production -> Documentation tab
[ERROR]: Error in reading/writing token file, creating new token file. Any ideas on how to fix this? I don't know what it is supposed to contain, but it isn't creating/can't find it.
@@tylerebowers Thanks! Mac seems to need one less folder or one more. For anyone else, the fix was just remove the folder. Instead of modules/tokens.txt, it looks like taking out modules, and just having tokens.txt allows it to run.
I am trying to place the order, order does get through with success code 201 but if I go to Schwab UI, I see it as cancelled. Do you know why? It never gets executed.
@@amrit0975 It should be commented out if you don't want to cancel the order. If you mistyped that then the order could also be canceled because it is in an invalid format, you could try placing it within market hours.
Schwab will eventually make something so you only have to authenticate once. I am looking into a quick solution for now, but paused on significant development until next Friday since I am busy.
@@FabrizioGiordano I know as much as you so I cannot be sure about anything. I hope they will release it soon. There are currently ways to get the stream working but it’s not official yet. I will post a video when they release it.
@@tylerebowers thank you for the quick response. can you elaborate or give hint on "There are currently ways to get the stream working but it’s not official yet. " :)
Hi Tyler. Thank you so much for this. running into an issue when i try and get movers if you can help: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 971, in json return complexjson.loads(self.text, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 3 column 9 (char 22) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/nolannosike/projects.nosike/Wager/Schwab-API-Python-main/main.py", line 92, in main() #call the user code above ^^^^^^ File "/Users/nolannosike/projects.nosike/Wager/Schwab-API-Python-main/main.py", line 70, in main print(api.movers.getMovers("$DIJ").json()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 3 column 9 (char 22) nolannosike@nolans-mbp projects.nosike % I added the .json() to your print(api.movers.getMovers("$DIJ"), lmk if that was incorrect, I get a 404 when its not there. Not sure what the issue is, when i try schwabs website it seems to be working. the decoder is too complex for my nooby brain to understand, not sure how to see the raw data either so i'm not sure what exactly its saying
The 404 code means there was some error in what you sent in the call. (A code around 200 is good). Because of the 404 error no json data is returned. 404 may indicate that the api link is invalid.
Hi Tyler, thank you very much for posting this. This is really helpful. I am trying this with R on mac m1. I have been receiving this error code. Would you happen to know what's causing this? $error [1] "unsupported_token_type" $error_description [1] "400 Bad Request: \"{\"error_description\":\"Bad authorization code: AuthorizationCode has expired,expiration=1712366963920,now=1712366966062 \",\"error\":\"invalid_request\"}\""
It says authorizationcode has expired but I just got the code in the browser address bar and it expired within the few seconds I transferred it from the address bar to RStudio?
@@kyawp i had the same error. It was because I didn't URL decode prior to making the request. However, this error seems to their genetic error repones even when it is the server error.
The Github is now a pypi package, the installation is detailed in the readme. The next video on streaming also shows a short introduction on the usage of the new package: ua-cam.com/video/t7F2dUecgWc/v-deo.html
Downloaded your Git files, installed Python 3.12 and Visual Studio Code, got my app approved by Schwab, and was able to make the connection to Account Details
your the goat I was frustrated couldn't find a tut for schwab api
There are many people teaching programming on youtube, you are by far, the most comprehensive when making sure the listener understands where lines of code go back to or functions. We need websockets for RTD :)
Awesome, thank you very much Tyler. Great stuff. Longtime Schwab user and glad they’re making the APIs publicly available.
Thank you for creating this video! I was needing to switch my python code from my TDA api app to Schwab and the authentication is much different. I also use pycharm. This is great as I had several formatting issues I found. Your video helped me fix them and now I was able to get price histories. Now I need to look at implementing the refresh token so I can extend the use time.
thanks Tyler for making this transition from TD Ameritrade a lot easier
I had been waiting for this for months, I found out thanks to your video, I look forward to the continuation, thanks for the content
Same here
Love what you’re doing Tyler, very undervalued content. Thank you 🙂
@@cameronburnham4536 thanks!😊
Thank you for creating this vid, helped me get set up on Schwab after they bought TD
Thank you so much, Tyler for this video and extra help on Discord. I am one step closer to my auto trading, yeah!
Thank you for posting this instruction video.
Thank you for the Github repo as well. One suggestion I have is to use a Python code formatter like black to reformat your code. That way your code will be much more readable and easier to follow.
Thanks Tyler. Your video was helpful.
I also have another video on streaming that I recently published
Thanks a lot! They should have put this in their user guide...
Let’s go!!! thanks Tyler!
Tyler - this is awesome! Especially with the change from TD to Schwab. Our TD apps will stop working.
Ok, I have been using the TDA API in Google Sheets to pull option prices, and to do that I only had to add a parameter to my request url for an apikey. I cannot figure out how to do that simple thing with the Schwab api. Any suggestions? Why do they make you jump through all the oAuth crap just to pull market data? I am not creating a trading bot or entering orders. I just want to analyze option price data in Google Sheets.
Thank you for posting this, very helpful! Do you have to re-authentic every 7 days if just getting market data or is that just for account specific data? Do you have Git files for one that just goes after market data? Thanks again for putting this out here. I’ve subscribed and look forward to more videos.
Tyler,
First, thank you, thank you, thank you -- very helpful information.
Second, when you login (you pull your login screen off to the side - which I appreciate) are you logging into a Schwab account or a TDA account?
Thank you, Paul Gundersen
I am using a Schwab account.
I wish Schwab itself would do tutorials on this stuff for its customers.
Thank you. This is very helpful. You're a genius.
Great stuff - Please keep it coming - When you have time, please provide fully automated syntax examples on things like getting account balance, placing trades based on percentage of account balance, looping and getting a stock price every second, and a couple basic trading strategy examples on things like buying/selling based on sma
😂😂life isn’t about spoon feeding pal do your own due diligence
@@robertcameron4288 Life is about getting views though so he would be dumb not to do what his viewers are requesting. If not him than I or someone else will do it and get all the big bucks from youtube!
Great video, thanks a lot! Could you give an example about place order? Specifically what should the orderObject look like when call the POST API?
Great work! Thanks for doing this!
Thank you very much, that's excellent work!. I completely agreed with the very annoying change for the refresh token expiration from 90 days down to 7.... We now have no choice but to automate this process, hopefully Schwab can fix that. Logging in manually is just NOT something I enjoy doing weekly while using multiple machines.
Please let us know if you have follow up on that news or automation for the refresh token. THANKS
Schwab has said that it will eventually support updating the refresh token from an api call.
@@tylerebowers hopefully this happen sooner than later. At the mean time, I’ll checkout playwright and see if I can work around it for now. I heard some user have successfully automated this process. I am still waiting for my pending approval… lol
@tylerbowers I followed the steps and got all the way to the end where you got a link (at 13:34 minutes into the recording) but I got an error saying "we were unable to complete your request. Please contact customer support for further assistance" any thought or any idea who I need to contact?
@@PhoenixSunshin Your app must be “Ready for Use” is there a chance that it says “approved - pending” instead?
Great code, thanks for sharing!
I cannot get the authorize request to work. If I use the "AppKey" it fails with "There was an unexpected error (type=Internal Server Error, status=500)."
I found a client_id when using the app request page and by watching the traffic... it lets me log in and returns back to the test page but at no point do I see the "code"
my app says "Approved - Pending" -> but it behaves like it's not approved...?
@@drstrangelove09 it’s not approved yet, you need to wait for “Ready For Use”
@@tylerebowers aha!!! thank you!!!
@@tylerebowers aha... I see that I am able to get the tokens if I work very fast... the auth code is only valid for 30 seconds
Thank you for great video. Do you know when the WebSocket Streaming will be available?
I don't know yet. Schwab is quiet about releases but they do deliver.
Hey @tylerebowers - thanks for the video! This is really helpful.
I am unable to get real time data for index using this API. is there any additional configuration that needs to happen to fetch pull real time data?
You can try using the video on streaming to get real time data. You may also need to enable thinkorswim
Great video. Q: are we able to get historical data for stocks on 1 min candle (ohlc)? I want to export 100 stocks and analyze it.
Thank you so so so so much. I really love the content!
Is there a way to send authentication to my phone once the refresh token is about to expire?
This way, I can authenticate with my phone again using something like face ID and the refresh token is refreshed.
Schwab requires manual authentication currently, however they have said that they are going to make the process easier in the future.
@ thanks for the comment! Hope authentication via phone can be utilized some day
Hey Tyler I still use the TDA API, but now trying to convert to Schwab
I am following your tutorial, however i do not understand how do you refresh the access token with the refresh token.
Do you have the request headers and payload data scheme.
The GitHub in the description might help.
Is there any reason why the account values don't reflect real-time values when the market is open?
How did you figure this out? is there Schwab documentation somewhere on this? I can't seem to find it.
developer.schwab.com/
This is great! thanks! so how do you refresh the token or use the refresh token? It seems like once the original token expires, you have to do the whole login thing again
Access token expires in 30 mins, refresh in 7 days. The GitHub program refreshes automatically. Schwab is working on a way to make it easier to deal with the refresh token so that you don’t have to manually authenticate every 7 days.
hello sir!! on the Schwab API, I could not find API to get a list of my current open positions, for example the list of stocks and options that i currently hold, am I missing something?
client.account_details(account_hash, fields="positions")
@tylerebowers incredible kindness is appreciated, sorry I missed the obvious thing I should have tried out
@@prakashparasuram7088 in the GitHub docs/ folder I have every api call possible documented as well as additional documentation for the client and streamer etc…
Can the initial authentication (login, check the box give consent blahbalh) be automated to? It is kind of lame to do it every time it expires
For the refresh token there is currently no way to automate it that wouldn’t go against Schwab’s policy. Since I have a public package I do not want to implement anything that would do that. I have also heard that their login page blocks attempts at automated logins and I believe that someone have gotten banned. So it’s quite the risk to do so.
great stuff :)
Tyler, thanks a lot for the video. Question - when logging in to get the redirect url, do you log in with the developer ID? If I remember it correctly, they forced that to be an email address. I tried that ID but it says invalid ID/password. My TD brokerage accounts are not migrated to Schwab yet. However, I have created the developer account and registered an app in Schwab and I was hoping I could test the authentication. Do I need to wait for the accounts to migrate over?
Yes, the redirect url is used to connect your Schwab account to the developer app.
Hello tyler,Can you please tell how much time it takes to move from status pending-approved to ready for use.
They run an approval process twice per week
@@tylerebowersbut i think it's been over a 10 days,no update in status of api
@@sidhantsatapathy8603 email them.
Hey Tyler, great tutorial, thanks for making it! It was a lot of help. Quick question - have you received any real data from the order requests? I'm sending the correct parameters like to/from entered time, status, etc..., and the status_code is coming back 200, but the array is empty even though I have order data of status and in time frame on my Schwab account.
You can get the order ID of the successful order like this: "orderID = resp.headers.get('location', '/').split('/')[-1]" This example is also in the github main.py.
@@tylerebowers I'm just wondering if you're getting actual data back from like a simple '/orders' request. I'm able to get data from '/accounts' requests, but 'orders' and 'transactions' data returns an empty array, even though I know I have data in my Schwab account in my specified parameters.
@@Fitznicelyy you only get the code and order id, it shouldn’t return anything else (unless there is an error).
Thanks for the video. It is very annoying to do authentications every 7 days, hope they change it.
Anyone knows if the developer account can be different than the Schwab account with Trading Accounts ? I have developer login that is different than trading account logins and when I try to get the initial token and have the code open. browser, I can't login using developer account there. But when I log in using credentials for Schwab account with Trading accounts, then I can sign in and select the accounts but it stops short of giving me the token/access_token and fails.
Yes, as far as I am aware they can be different. The developer account is for the app, and the broker account is the one that you link to the app when you sign in.
@@tylerebowers Thank you !! Great Video and explanation. Appreciate your time and effort tin sharing your code.
Great video Tyler- thank you. Your IDE seems clairvoyant. Is that Copilot?
It’s Codeium, there is also jetbrains ai and GitHub copilot but I don’t use those.
@@tylerebowerswow, and it’s free?!? Jeesh, you’re a wealth of great information- Thank you!
Hi! Thanks so much for posting this! Did you ever get the refresh token to auto refresh?
Schwab is going to implement a system to make that easier in the future
@@tylerebowers Got it - thanks!
Thank you Tyler. This and the github helps a lot.
I am using now for the access to ameritrade api session instead of requests. I am not sure if this difference impacts performance. What do you think?
I am not entirely sure what you mean here.
@@tylerebowers Apparently YT blocks my response if it includes links.
I access TDAmeritrade api hundreds of times a day. So, I use sessions. I copy the comment I wanted to show to you:
"The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3‘s connection pooling. So if you’re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase"
@@danielfutterweit4182 I see, I’m not sure how well that would work with Schwab. I think using sessions does violate REST but it really depends on the implementation. You shouldn’t really need to make a ton of api calls once websocket streaming comes out from Schwab.
I wish I could double thumbs up.
If you liked this video then you might like the video I released on streaming. I think that would count. 😄
nice work!!
Many thanks for this. I wonder whether anyone else is having the same login problem I'm having.
I created the app on the Schwab developer site so I have the app key and app secret. When I execute the code I go to the login page, then the page where I accept the agreements. Up to that point it's just as it appears in the video.
However, the next page that comes up in the video is a page where the user selects which account to link to, which then goes to a blank page with the URL to be copied. For me, after I accept the agreements the next page is just the generic Schwab login page. If I enter the login information again, it just keeps going through the same loop.
I'm using a Schwab account, not a TD account.
Any thoughts on what might be happening and how I can correct it would be greatly appreciated.
You might not have an account type that can be linked to
@@tylerebowers I hadn't thought of that. It's a 401k. Does anyone here know whether that disqualifies it?
@@ericjensen4497 401k's still not allowed, i have requested schwab for it
Thank you very much
Hi Tyler, is there a way to grab candle level data using the Schwab api?
I believe price history returns candles.
Hey Tyler, would this work for my Schwab Roth IRA account?
Roth IRA accounts are supported!
It would be great if you make more apis for other brokerages also
I only have an account at schwab.
When I try to create the token, it says: access denied. what is the reason? My application status: ready for use.
Did you link an account? That should not be happening.
Hello, can you automatically re-authenticate like TD Ameritrade? Thanks for the video.
Just the access token for now, waiting on a solution for the refresh token from Schwab.
Good work on this. really helped me a lot in converting from td to schwab. but place trade isn't working for me. As soon as it is placed it is getting cancelled. any params missing on it?
No other errors? Are you using the GitHub code? What the return code? There are some examples on Schwab, but the main.py code should work too.
@@tylerebowers yeah. i am using the github code # place an order (uncomment to test)
i am getting 201 response but schwab immediately cancel the trade.
Hi Tyler, Thanks for the great video. I am having issue with "from modules import terminal". I have just the same project structure as your git version, but can't recognize 'terminal'. What I'm doing wrong? Thanks
Is the terminal.py file missing?
@@tylerebowers terminal.py is there, still getting unresolved reference for modules and terminal
Sorry. After reviewing this, I think it may be because I included your project as a directory into an existing project. I just want to use your re-authentication part in my project. Can I just add those functions?
@@lahirys2809 which file are you running from? - you should be running from main.py
@@tylerebowers Now, I'm using your original git version, running from main.py. Its only authenticated first time. Subsequent run an gives me errors like below:
[INFO]: Access token last updated: 2024-05-17 21:26:53 (expires in -41562 seconds)
[INFO]: Refresh token last updated: 2024-05-17 21:26:53 (expires in 7 days)
[INFO]: The access token has expired, updating automatically.
[ERROR]: Could not get new access token.
[INFO]: Filling account number and account hash -> Error
[ERROR]: Could not get account numbers and account hash.
[ERROR]: Please make sure that your app status is "Ready For Use" and that the app key and app secret are valid.
[ERROR]: {'errors': [{'id': 'd0d9----- ....', 'status': 401, 'title': 'Unauthorized', 'detail': 'Client not authorized'}]}
... ...
What I'm doing wrong? Thanks so much for your time.
i had the same problem on windows. i just renamed the modules folder to "utilities" and in the code.
my python was resolving to another package that had the same name.
Thanks for posting, as official Schwab documentation is clearly lacking. In your code, I see an orderObject, but can't find the class. What is the format for placing orders? Also do you know if you can use a virtual/paper account?
orderObject is a dictionary which schwab has some documentation for. Currently schwab does not have paper trading access
@@tylerebowers thanks. I was unable to find this documentation. Could you please post a link?
All of the schemas I saw are incomplete
@@enriquehoja9767 I believe they are all complete, you don’t need everything filled out.
@@enriquehoja9767 The tab is currently missing from the dev website, normally you would go here: API Products -> Accounts and Trading Production -> Documentation tab
Hello Tyler, I need your help modifying my TD connections to Shwab. Can you help, please? Thank.
from td.client import TDClient
class DataApp:
def __init__(self,symbol,expiry,expiry_for_title):
self.TDSession = TDClient(
client_id = 'client IT',
redirect_uri = '127.0.0.1/',
credentials_path = 'jsonConfig1.json'
)
self.TDSession.login()
self.symbol=symbol
Hi
how would i get the login credential which will be add after clicking on authURL,
could you please help here ?
The description contains the demo file.
[ERROR]: Error in reading/writing token file, creating new token file. Any ideas on how to fix this? I don't know what it is supposed to contain, but it isn't creating/can't find it.
Are you on a Mac? Someone else with an arm-based Mac was having issues with the token file.
@@tylerebowers yes. Mac m1.
@@tylerh3526 The issue will likely be in the _TokenManager() function in api.py
@@tylerebowers Thanks! Mac seems to need one less folder or one more. For anyone else, the fix was just remove the folder. Instead of modules/tokens.txt, it looks like taking out modules, and just having tokens.txt allows it to run.
I am trying to place the order, order does get through with success code 201 but if I go to Schwab UI, I see it as cancelled. Do you know why? It never gets executed.
Using the GitHub code?
@@tylerebowers Yes that's correct Tyler.
@@amrit0975 is there a chance that you also uncommented the code that cancels it? I see no reason why it should be canceled
@@tylerebowers No I checked exactly for what you are saying, I do not have cancelOrder commented out.
@@amrit0975 It should be commented out if you don't want to cancel the order. If you mistyped that then the order could also be canceled because it is in an invalid format, you could try placing it within market hours.
mine hasn't been approved and its been over a week. Is there anything I could do?
Nope, just wait 🙁
is there any way to fully automate the authentication process?
Schwab will eventually make something so you only have to authenticate once. I am looking into a quick solution for now, but paused on significant development until next Friday since I am busy.
Thanks Tyler, I am swithching from TDA to Schwab. When I use this code I get a "Bad Request" error. any clues to correct?
Is your app "Ready For Use"?
@@tylerebowers yes it is
@@chrisruberg1491 is the redirect url: "127.0.0.1" (no slash at the end)
@@tylerebowers yes. is there a limit to the number of times you can request tokens?
@@chrisruberg1491 Not one that I am aware of. I have never hit it. What code are you using? Demo code?
Excellent video! Discord link has expired - Can I get the invite please?
I tried it again, it is still working.
Anyone else getting a "Whitelabel Error Page" message?
@@MrJSplash Callback url might be incompatible? And app status must be “Ready for Use”.
schwab api available for paper trading?
You could make your own version of paper trading, no actual api for that.
fonts are hard to see
That was as much as I could zoom in the ide, trust me it is better than my series on the TD ameritrade api.
Is you streamer working, I am not receiving all streamer info needed. please respond
Streaming is not officially supported by schwab yet.
@@tylerebowers Do you think they will add websockets for stock data by the time TD will switch to Schwab?
@@FabrizioGiordano I know as much as you so I cannot be sure about anything. I hope they will release it soon. There are currently ways to get the stream working but it’s not official yet. I will post a video when they release it.
@@tylerebowers thank you for the quick response. can you elaborate or give hint on "There are currently ways to get the stream working but it’s not official yet. " :)
@@FabrizioGiordano There isn’t anything to subscribe to yet, so all you can do is connect.
Hi Tyler. Thank you so much for this. running into an issue when i try and get movers if you can help:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 9 (char 22)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/nolannosike/projects.nosike/Wager/Schwab-API-Python-main/main.py", line 92, in
main() #call the user code above
^^^^^^
File "/Users/nolannosike/projects.nosike/Wager/Schwab-API-Python-main/main.py", line 70, in main
print(api.movers.getMovers("$DIJ").json())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 3 column 9 (char 22)
nolannosike@nolans-mbp projects.nosike %
I added the .json() to your print(api.movers.getMovers("$DIJ"), lmk if that was incorrect, I get a 404 when its not there.
Not sure what the issue is, when i try schwabs website it seems to be working. the decoder is too complex for my nooby brain to understand, not sure how to see the raw data either so i'm not sure what exactly its saying
The 404 code means there was some error in what you sent in the call. (A code around 200 is good). Because of the 404 error no json data is returned. 404 may indicate that the api link is invalid.
Hi Tyler, thank you very much for posting this. This is really helpful. I am trying this with R on mac m1. I have been receiving this error code. Would you happen to know what's causing this?
$error
[1] "unsupported_token_type"
$error_description
[1] "400 Bad Request: \"{\"error_description\":\"Bad authorization code: AuthorizationCode has expired,expiration=1712366963920,now=1712366966062 \",\"error\":\"invalid_request\"}\""
It says authorizationcode has expired but I just got the code in the browser address bar and it expired within the few seconds I transferred it from the address bar to RStudio?
@@kyawp i had the same error. It was because I didn't URL decode prior to making the request. However, this error seems to their genetic error repones even when it is the server error.
thank you!!