marketcalls / openalgo

Open Source Algo Trading Platform for Everyone
https://docs.openalgo.in
GNU Affero General Public License v3.0
150 stars 68 forks source link

Internal Server Error: Trying to configure Dhan API #26

Closed juxta1357 closed 4 months ago

juxta1357 commented 6 months ago

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 -

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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