marketcalls / openalgo

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

Broker Configuration In Database #72

Open crypt0inf0 opened 2 days ago

crypt0inf0 commented 2 days ago

Can we save the broker configuration api in database, So that we can save multiple broker api's & switch between multiple brokers in the frontend.

We can also manage multiple brokerage account.

crypt0inf0 commented 2 days ago

After login we select broker, If the api is available in database it takes to broker login. If broker api is not available it redirect to enter the api key and save it.

marketcalls commented 2 days ago

Already have plans to migrate the broker credentials from .env to database. But the immediate challenge will be have to reconfigure the API structure in case of allowing multi broker login.

Here is the sample placeorder structure which needs to be reconfigured which I don't want to do at this point https://docs.openalgo.in/api-documentation/v1/placeorder

any other alternatives without changing the existing API structure.?

crypt0inf0 commented 1 day ago

There is no need to change the structure, We just need to change the os.getenv('BROKER_API_KEY') & os.getenv('BROKER_API_SECRET') to fetch from database instead of .env

And for os.getenv('REDIRECT_URL') we can use the broker selected by the user to be autofill on f'http://127.0.0.1:5000/$(broker)/callback'

If the user selected broker does not have any API stored then redirect to API secret page to enter the API details and save it.

API database struct like,

{
   BROKER: angelone,
   API_KEY: xxxx,
   API_SECRET: yyyy
}

Also provide a option to edit API keys, We can use the same template as save API keys. We also need to have a error handling for expired api key or wrong api keys.