Skip to content

Conversation

@kalai-de
Copy link
Contributor

@kalai-de kalai-de commented Nov 6, 2025

  • Introduce new RESTX endpoint for custom broker API requests
  • Extract common API response logic into shared module for zerodha
  • Refactor funds and order APIs to use shared API response module

#561, We can extend broker functionalities directly with this new endpoint,

image image image

we can extend individual brokers cabality depending on broker that we are using.


Summary by cubic

Adds a custom broker RESTX endpoint and centralizes Zerodha API request handling to cut duplication and simplify maintenance. This makes funds and order APIs cleaner and makes it easier to extend support for more brokers.

  • New Features

    • New POST /broker/custom endpoint to forward broker API requests.
    • Validates input with CustomBrokerSchema and returns consistent error messages.
    • Dynamically routes to broker modules via broker_custom_service.execute_custom.
  • Refactors

    • Moved shared get_api_response to broker/zerodha/api/api_response.py with pooled httpx client and unified error handling.
    • Updated funds.py and order_api.py to use the shared helper; removed duplicate request code.
    • Registered the new namespace in restx_api/init.py.

Written for commit 3b9beba. Summary will update automatically on new commits.

… calls

- Introduce new RESTX endpoint for custom broker API requests
- Extract common API response logic into shared module for zerodha
- Refactor funds and order APIs to use shared API response module
@kalai-de
Copy link
Contributor Author

kalai-de commented Nov 6, 2025

@marketcalls if it is okay for zerodha, I can do the same for other brokers too.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

@crypt0inf0
Copy link
Contributor

What's the benefit of using the custom broker endpoint?

@kalai-de
Copy link
Contributor Author

kalai-de commented Nov 7, 2025

Example: Open algo dont have feature to calculate the margin required to execute the option strategies, create the alerts or alert triggered order.

In my case I use zerodha, they have api to

  1. calculate the margin required to execute basket of orders.
  2. Alerts and alert triggered order(ATO), I found ATO is really good feature and I use regularly in zerodha

Similarly Dhan have option to get the option chain, option expiry list, option geeks.

with my above implementation,using openalgo api I can directly execute my broker's api, without needing to go through extra authentication layer with broker again.

    endpoint = fields.Str(required=True)
    method = fields.Str(required=False, default="GET")
    payload = fields.Raw(required=False, default=None)

I can pass the endpoint, method and payload to execute my brokers api call through openalgo api..

we can execute brokers' api through openalgo without needing to go through seperate implementation

@crypt0inf0
Copy link
Contributor

Was it any different from #564

@kalai-de
Copy link
Contributor Author

kalai-de commented Nov 7, 2025

@crypt0inf0 yes, it is different,
#564 covers only margins, but still i cannot execute alert triggered order offered my broker,

image

Also dhan offers, historical price for expired options, powerfull option chain with geeks.

image image

I can execute all these, without waiting for openalgo to implement, say for example, we need to wait for openalgo to implement #564 for margin calculation but with this custom broker api execution we can directly use zerodha one without needing to wait for openalgo implementation

@crypt0inf0
Copy link
Contributor

I understand your idea and your implementation but most of the openalgo users are non technical user's. They want a simple user experience.

Can you give a example of how to use this custom API?

1 similar comment
@crypt0inf0
Copy link
Contributor

I understand your idea and your implementation but most of the openalgo users are non technical user's. They want a simple user experience.

Can you give a example of how to use this custom API?

@kalai-de
Copy link
Contributor Author

kalai-de commented Nov 7, 2025

@crypt0inf0 , I agree this is not for non-technical users, but technical people can easily call this,

from openalgo import api

client = api(api_key='api_key', host='http://127.0.0.1:5000')

client._make_request(endpoint='/broker/custom', payload={
    'endpoint': '/alerts',
    "method":"GET",
    "payload":{}
})

We can update the python, node sdk to access this easiy without using _make_request

@crypt0inf0
Copy link
Contributor

@kalai-de Now I understand we can directly use the broker API endpoint via openalgo @marketcalls Can you test this and merge it?

@marketcalls
Copy link
Owner

im exploring it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants