feat(trading): Dhan + Shoonya Indian broker connectors (paper-capped)#181
Merged
Conversation
…ped) Two broker_sdk connectors for the Indian equity and F&O markets (NSE/BSE): Dhan (dhanhq) and Shoonya / Finvasia (NorenRestApiPy). Read access plus locally simulated paper-account order placement. Both brokers expose no sandbox and no runtime paper/live discriminator — a single token / TOTP login reaches the same real account — so, following the Longbridge precedent, the order path is structurally capped at paper: - place_order / cancel_order refuse any non-paper config at the first line, so a flipped `profile` override can never reach a live order; - no live order-placing profile is registered (paper-sdk read-only, paper-trade local-sim, live-sdk-readonly read-only — three profiles each, mirroring Longbridge); - DHAN/SHOONYA tool-class maps wired into the live classifier registry; - order ops pinned WRITE; secrets redacted; pyotp made an optional dependency; Shoonya sessions cached per user_id to avoid cross-account reuse. Tests cover profile registration, the non-paper fail-closed guard, paper simulation, WRITE-pinned order ops, secret redaction, and a regression guard that these no-discriminator brokers never expose a *-live-trade profile. Maintainer follow-up to PR #174: the original submission shipped live order placement with no structural paper/live discriminator (and an invalid asset class that crashed the live path); this revision caps both connectors to paper + read-only to keep the paper/live boundary structural, never an agent-flippable config flag. Co-authored-by: Haozhe Wu <haozhe_wu@connect.hku.hk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two
broker_sdkconnectors for the Indian equity and F&O markets (NSE/BSE) — Dhan (dhanhq) and Shoonya / Finvasia (NorenRestApiPy) — following the connector-first architecture. Read access + locally simulated paper-account order placement.This is a maintainer follow-up to #174 that lands the contribution with the paper/live boundary made structural.
Why capped to paper + read-only
Both brokers expose no sandbox and no runtime paper/live discriminator — a single token / TOTP login reaches the same real account, and "paper" is purely a local simulation flag. That is exactly the case the project already caps at paper + read-only for Longbridge, because every connector that places live orders earns it with a broker-provided discriminator (Tiger 17-digit account · Alpaca host+key separation · OKX demo flag · Binance testnet host · Futu
trd_env). Dhan/Shoonya can't provide one, so they follow the Longbridge precedent.Concretely, vs. the original #174 submission:
place_order/cancel_orderrefuse any non-paper config at the first line, so a flippedprofileoverride can never reach a live order. No*-live-tradeprofile is registered — three profiles each (paper-sdkread-only ·paper-tradelocal-sim ·live-sdk-readonlyread-only), mirroring Longbridge.in_equity, not a member ofAssetClass) that raisedValueErrorfor every order through the gate; that mapping is dropped.DHAN_TOOL_CLASS/SHOONYA_TOOL_CLASSare now registered in the live classifier registry (they were defined but never imported).pyotpmade an optional dependency with a clean error; Shoonya sessions cached peruser_idto avoid cross-account reuse; dead code removed.What you get
Real-time NSE/BSE data, account/position/order reads (paper + live read-only), and local paper-strategy simulation. Live order placement stays off by construction; if either broker ships a real sandbox/demo endpoint later, a discriminator can be added and the cap lifted cleanly.
Tests
pytest— 2998 passed, 2 skipped (CI-equivalent run). New coverage intest_sdk_connectors.py:place_order/cancel_order*-live-tradeprofileOriginal connector work by @panditvirchandra77-lgtm (#174).