Open sivadosapati opened 2 months ago
Can you give me a little more info about what you have tried and any errors or messages that you are seeing?
Sure - I did the following steps
0 - I set up the Custom Token Handler that will print the refresh token and access token and
@PostConstruct
public void init() {
System.out.println("Initializing SchwabApiClientHandler..");
if (!schwabMarketDataApiClient.isInitialized()) {
ClientTokenHandler clientTokenHandler = new ClientTokenHandler();
SchwabAccount schwabAccount = new SchwabAccount();
schwabAccount.setUserId(schwabUserId);
// If you have saved your refresh token, pass it to the API client service.
// Otherwise, you will have to generate one each time you run this example.`
// schwabAccount.setRefreshToken(schwabRefreshToken);
// schwabAccount.setRefreshExpiration(schwabRefreshExpiration);
schwabMarketDataApiClient.init(schwabAccount, clientTokenHandler);
System.out.println("Initialized SACH");
}
}
public class ClientTokenHandler implements SchwabTokenHandler { @Override public void onAccessTokenChange(@NonNull SchwabAccount schwabAccount) { System.out.print("Access Token : "+schwabAccount.getAccessToken()); }
@Override
public void onRefreshTokenChange(@NonNull SchwabAccount schwabAccount) {
// ...Do something to save the Refresh Token here
System.out.print("Refresh Token : "+schwabAccount.getRefreshToken());
System.out.print(" expires on ");
System.out.println("Refresh Token Expires : "+schwabAccount.getRefreshExpiration());
}
}
1 - Accessed the authorization end point (from step #9) - http:/localhost:8080/oauth2/schwab/authorization?schwabUserId=<
I'm happy to do a video meeting to walk you through what I was doing (if you have time available)
@gporter0205 - Any insight would be greatly appreciated. I'm missing my automated trades which worked on TDA. Manually trading is a pain in the neck and I would love to jump on automatic trading sooner
Any update will be greatly appreciated
Sorry, Siva. Been pretty busy for the last week. I'll try take a look this week.
Sorry again. I just had a chance to look through this. I think you are missing the connection between getting/generating the refresh token and then passing it to the services for use. Instead of just printing out the refresh and access tokens in the TokenHandler, save them so you can pass them to the init method of the api client so in the ScwabAccount class so it can use them when calling the API. You shouldn't need to call the /oauth2/schwab/code endpoint again like you did in step 3. Once you authorize the app at Schwab, it will call that endpoint with a code that it generates, which also triggers the TokenHandler methods. I hope this makes sense and helps.
Thank you, Greg! I never saw onAccessToken() and onRefreshTokenChange() got called. I invoked http:/localhost:8080/oauth2/schwab/authorization?schwabUserId=<
They should get triggered by Schwab calling the oauth2/schwab/code end point after you authorize. Make sure the redirect url that you are using in your application.yml is in the list of redirect URLs that you have set up in your Schwab app on the developer portal and that your services are running on that host. The redirect url should be https://*DOMAIN*/oauth2/schwab/code where DOMAIN will be the host where your services are running. Schwab won't allow you to redirect to localhost:8080 and it'll require https. They will allow you to use https://127.0.0.1 though, but then you'll have to set up self signed certs on your development machine. It's a pain for development. I struggled with it for a while. Again, I hope this makes sense and helps.
@sivadosapati were you able to get past this issue?
I am also facing the same issue with step #9. I am using Greg's 'schwab-client-example' app. On invoking, http:/localhost:8080/oauth2/schwab/authorization?schwabUserId=<
And, in the app logs, there is "c.p.s.a.c.oauth2.SchwabOauth2Controller : Initialization Error: Unable to get Refresh Token before service initialization" error message.
@ab101421 -> I was busy with other things for the last few weeks and didn't get a chance to look at this. I will give this a try in the next few weeks and will update if I'm able to make further progress
@siva-dmg sounds good. thanks!
Any fix available on above issue?
I'm unable to access refresh tokens. I followed the steps outlined here - https://github.com/gporter0205/schwab-api-client/wiki. I'm stuck at Step #9 and any help to unblock would be greatly appreciated.