Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Server Error: Trying to configure Dhan API #26

Closed
juxta1357 opened this issue May 3, 2024 · 3 comments
Closed

Internal Server Error: Trying to configure Dhan API #26

juxta1357 opened this issue May 3, 2024 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@juxta1357
Copy link

Hello

After setup, on login page it gave options for various brokers. I am choosing Dhan. I configured environment variables using DHAN api key.

On restarting the app, getting this error. What am I missing

127.0.0.1 - - [02/May/2024 01:30:40] "GET /dashboard HTTP/1.1" 500 -
127.0.0.1 - - [02/May/2024 01:30:41] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [02/May/2024 01:32:24] "GET /setup HTTP/1.1" 302 -
127.0.0.1 - - [02/May/2024 01:32:24] "GET /auth/login HTTP/1.1" 302 -
127.0.0.1 - - [02/May/2024 01:32:24] "GET /auth/broker HTTP/1.1" 302 -
<broker_api_secret>
Funds Details: {'errorCode': 'UNAUTHORIZED', 'httpStatus': 'UNAUTHORIZED', 'internalErrorCode': 'RS-9005', 'internalErrorMessage': 'The token was expected to have 3 parts, but got 1.'}
Positionbook : {'errorCode': 'UNAUTHORIZED', 'httpStatus': 'UNAUTHORIZED', 'internalErrorCode': 'RS-9005', 'internalErrorMessage': 'The token was expected to have 3 parts, but got 1.'}
[2024-05-02 01:32:24,643] ERROR in app: Exception on /dashboard [GET]
Traceback (most recent call last):
File "C:\Users\V\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\V\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\V\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\V\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File "C:\Users\V\openalgo\blueprints\dashboard.py", line 51, in dashboard
margin_data = get_margin_data_func(AUTH_TOKEN)
File "C:\Users\V\openalgo\broker\dhan\api\funds.py", line 49, in get_margin_data
total_realised, total_unrealised = sum_realised_unrealised(position_book)
File "C:\Users\V\openalgo\broker\dhan\api\funds.py", line 45, in sum_realised_unrealised
total_realised = sum(position['realizedProfit'] for position in position_book)
File "C:\Users\V\openalgo\broker\dhan\api\funds.py", line 45, in
total_realised = sum(position['realizedProfit'] for position in position_book)
TypeError: string indices must be integers
127.0.0.1 - - [02/May/2024 01:32:24] "GET /dashboard HTTP/1.1" 500 -

@marketcalls
Copy link
Owner

Looks like you haven't configured your API key

here is the sample format
Here is how you would typically set up your environment variables in a .env file for Dhan's API:

BROKER_API_KEY = 'your_dhan_clientid_here'
BROKER_API_SECRET = 'your_dhan_token_here'
REDIRECT_URL = 'http://127.0.0.1:5000/dhan/callback'

configuration instruction can be found here
https://docs.openalgo.in/connect-brokers/dhan

Here is the how the config looks like

BROKER_API_KEY = '10xx000xx30'
BROKER_API_SECRET = 'eyJ0eXAiOiJKxxxxxxxxxxxxxxIUzUxMiJ9.eyJp-DZhBw'

REDIRECT_URL = 'http://127.0.0.1:5000/dhan/callback'

@juxta1357
Copy link
Author

I've set this up in the .env file, in openalgo folder.
The API secret though, is about 5 times the length of what's shown here (is there some catch here?)
Still getting the same issue

@marketcalls
Copy link
Owner

marketcalls commented May 4, 2024

While it is a lengthy key, for simplicity's sake, I've used a shorter example here.

Please get in touch with our discord community support. If required will take remote and will check this out.

https://docs.openalgo.in/community-support

@marketcalls marketcalls added the help wanted Extra attention is needed label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants