TradeLore

Broker tutorials

How to Import Zerodha Trades Into a Trading Journal

TradeLore's repository contains a Zerodha connection flow that fetches trade fills, normalises instrument metadata and matches executions into reviewable trades.

The supported workflow

The implementation uses a Zerodha connection flow, an access token session and a server-side fetch of trade fills. It normalises exchange, symbol, segment, instrument token, fill time, order ID, trade ID, side, quantity and average price before sending orders through the shared trade-order sync pipeline.

TradeLore is read-only for this workflow: it imports data for journaling and analytics and does not place, modify or cancel orders.

Check Zerodha's current developer documentation before setup, as app, plan and export details can change.

Historical data, matching and duplicates

The code fetches the current broker trade data and uses stable broker, user, order and trade identifiers when normalising fills. The shared pipeline then persists orders and matches them into completed trades. This protects the import path from treating the same fill as a new trade on every sync; verify the current retention and historical range before promising a specific look-back period.

Common errors to check

  • Connection or token expiry: reconnect through the broker setup flow.
  • Missing identifiers or invalid quantity/price: the normaliser rejects incomplete fills.
  • Instrument metadata mismatch: confirm the current instrument index can be fetched.
  • Unexpected totals: compare imported fills with the broker's source data before reviewing P&L.

What you need before connecting Zerodha

The current TradeLore workflow expects a Zerodha Personal API app with an API key, API secret and redirect URL. The settings page displays the redirect URL that belongs in the app configuration. Save the credentials in TradeLore before clicking Connect Zerodha; the login route checks that credentials exist and that the server-side integration is configured.

Follow Zerodha's current Kite Connect developer documentation when creating the app. API plans, redirect requirements and credential setup can change.

  • A TradeLore account with the required active entitlement.
  • Your own Zerodha Personal API credentials.
  • The exact redirect URL shown in TradeLore settings.
  • A current Zerodha session that can approve the connection.

Step by step: connect, authorise and return

1. Open TradeLore's Zerodha settings and open the sync help if needed. 2. Save the API key and API secret. 3. Click Connect Zerodha. TradeLore generates a random state value, stores it in an HTTP-only short-lived cookie, and redirects you to the Kite login URL. 4. Complete the broker authorisation. 5. Zerodha returns a request token and state to the callback. TradeLore checks both values, exchanges the request token using the API key, secret and checksum, encrypts the returned access token, stores the broker identity and redirects you back with a connection status.

If the callback is missing a request token or the state cookie does not match, the connection is rejected. If the app is not enabled for the user, the UI reports that separately. These checks protect the connection flow; they do not replace careful credential handling.

What happens when you sync

The sync requests Zerodha trade fills and ignores incomplete rows without a trade ID, order ID, symbol, positive quantity or positive average price. It loads instrument metadata for any NFO, BFO or MCX exchange present in the fill set, then normalises symbol, exchange, segment, expiry, strike, lot size, instrument type, trade time, order ID, trade ID, side, quantity and price.

Normalised fills receive a stable identifier using the Zerodha user, order ID and trade ID. They pass through the shared trade-order sync pipeline, which persists the orders and matches them into completed trades. The sync returns imported orders, total orders, total trades and diagnostic counts such as raw fills, unique order IDs and collapsed fills.

The implementation fetches the current trade endpoint rather than promising unlimited history. Confirm Zerodha's current history and export behaviour before relying on a specific look-back range.

Equity, F&O, BFO and MCX metadata

For NSE and BSE fills, the normalised segment is equity. For NFO, BFO and MCX fills, TradeLore attempts to enrich the fill with the relevant instrument master. That enrichment can supply expiry, strike, lot size, instrument type and, for MCX, additional commodity metadata. If the metadata request fails, the fill may still be normalised with the fields available from the source, but the review should flag missing contract details.

Do not infer an option strike, expiry or lot size from a symbol string in the article or in a manual review. Use the source data and instrument metadata that actually arrived.

Reconnect, duplicates and troubleshooting

SymptomWhat to check
Reconnect requiredThe access token is short-lived or expired; connect again before syncing.
Credentials requiredAPI key/secret were not saved or the server is not configured.
No trades importedCheck the broker account, date/session, identifiers and source response.
Wrong contract fieldsCheck NFO/BFO/MCX instrument metadata availability.
Totals look duplicatedCompare stable trade IDs, order IDs and the shared pipeline totals.
Callback failedCheck redirect URL, app enablement and state-cookie completion.

TradeLore does not place, modify or cancel orders. Use a read-only Personal API setup and revoke credentials from the broker if you believe they were exposed.

Make review part of your trading day

Connect a read-only workflow, verify one session, then begin your review.

Start using TradeLore