Shared Token between Two or more algos

Hi,
Is there a standard/recommended way to share a token between two algos?
I have an issue that If I run two algos simultaneously then one which ran first is automatically invalidated and my algo throws an exception while performing any API action.
One of my algo fetches the option chain at 9:20 and the other algo fetches it at 9:18

Screenshot 2026-10-12 at 9.59.58 AM

Hi @Neil_Shah ,

Every time one of your algos logs in or generates a token, Dhan issues a new one and the old one stops working. So when your second algo starts and logs in, it kills the token the first algo was using. That’s why the first one throws errors.

The fix is to generate the token only once and let both algos share it. Write a small separate script (you can run it once a day before market opens) that generates the token and saves it somewhere common. Even a simple .txt file works fine: just save the token on a single line. You can also use a .env file or Redis if you prefer. Then both algos read the token from that same place instead of logging in themselves.

If an algo gets an auth error, have it re-read the saved token rather than logging in again, since the token may have been refreshed in the meantime.

Another option is to run both strategies in a single program that shares one Dhan client, which avoids the problem entirely.

One more thing: rate limits are per account, not per algo, so both algos share the same order and data limits. Keep that in mind if they place a lot of orders.

Thanks. This helps. I will have a look at it.

1 Like