Skip to content

Add Zerodha broker import (equity, long-only)#171

Open
rajeshmohanan wants to merge 1 commit into
Eleven-Trading:mainfrom
rajeshmohanan:indian_markets
Open

Add Zerodha broker import (equity, long-only)#171
rajeshmohanan wants to merge 1 commit into
Eleven-Trading:mainfrom
rajeshmohanan:indian_markets

Conversation

@rajeshmohanan

Copy link
Copy Markdown

Adds support for importing trades from Zerodha (Kite), one of the largest Indian discount brokers, by parsing their tradebook CSV export.

New "Zerodha" entry in the broker import dropdown
Maps Zerodha's tradebook CSV columns to TradeNote's internal execution format
Since Zerodha's tradebook export doesn't include brokerage/taxes/fees, this PR computes them using Zerodha's published equity fee schedule (brokerage, STT, exchange transaction charges, SEBI charges, stamp duty, GST), classified per matched buy/sell pair as intraday or delivery based on whether they occurred on the same day
Scope (v1)
This is intentionally scoped to start:

Equity (EQ) segment only — no F&O, currency, or commodity
Long positions only — any sell that would require a short position is rejected with a clear error rather than imported incorrectly
One account per import — users with multiple Zerodha accounts should import each account's tradebook separately
Known limitation: fee estimation is approximate, not exact
Zerodha's tradebook export doesn't say whether an order was placed as intraday (MIS) or delivery (CNC), which is the actual basis Zerodha bills on. This PR estimates that by checking whether a matched buy/sell pair happened on the same calendar day. That's a reasonable approximation for journaling purposes, but it can diverge from the real ledger — e.g. a position originally placed as an intraday order but carried overnight will be billed by Zerodha at intraday rates, while this estimates it at delivery rates. Documented in brokers/README.md; not intended to be relied on for tax/accounting purposes.

Test plan
Done:

  • npm run build succeeds with no errors
  • Verified the FIFO buy/sell matching logic against a real Zerodha tradebook export — output matches the lot-splitting Zerodha's own tax P&L report produces for the same trades
  • Verified gross P&L from the import matches Zerodha's own P&L statement exactly for a multi-fill position
  • Manually imported a sample tradebook through the UI (register → Add Trades → select Zerodha → upload CSV) and confirmed the resulting blotter/trades look correct

Not done:

  • Would appreciate a second pair of eyes / real-world testing from another Zerodha user, given the fee approximation noted above

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.

1 participant