TradeLore

Broker tutorials

How to Import Dhan Trades Into TradeLore

TradeLore's Dhan integration fetches trade data, normalises it into common trade-order fields, and sends it through the shared matching pipeline.

Connection and import

The Dhan client supports profile and trade-book requests through the configured Dhan credentials and consent flow. The sync converts valid records with trade ID, order ID, symbol, side, quantity, price, time, exchange segment and instrument details into TradeLore trade orders.

Connection steps, source fields and date availability can change. Confirm the current DhanHQ documentation before relying on a specific workflow or range.

Data and options handling

The normaliser preserves the exchange segment and derives exchange and instrument type fields where present. The repository test covers an NFO options record with CE type, quantity and price, so options records can be represented when the source supplies those fields. Do not infer a missing strike or expiry from a display name.

Historical availability depends on the broker response and the current sync request. Verify the returned date range before describing it as unlimited history.

Duplicate prevention and troubleshooting

Dhan records are assigned stable identifiers using broker, client, order and trade IDs and then pass through the common sync pipeline. If totals look wrong, compare source trades, date filters, segment values and rejected rows before importing again.

  • Reconnect if consent or credentials are invalid.
  • Check that quantity, price, side, order ID and trade ID are present.
  • Review the sync status and error returned by the broker route.
  • Use a small date range or one session to validate the first import.

What you need before connecting Dhan

The current Dhan workflow uses a DhanHQ app with Client ID, API key, API secret and the redirect and postback URL shown in TradeLore settings. The settings page instructs you to create credentials, save all three values, then connect through Dhan. TradeLore stores the app credentials and access token; the Dhan password, PIN and TOTP remain on Dhan.

Dhan's Individual Trader API-key flow uses an app ID (API key) and app secret. It creates consent, redirects to the registered URL with a token ID, then exchanges that token for an access token. Check DhanHQ's current authentication documentation before setup.

Step by step: Dhan consent connection

1. Open Dhan settings in TradeLore and copy the displayed redirect URL into the required Dhan app configuration. Configure a postback only if the current Dhan account setup uses one. 2. Save the Client ID, API key and API secret in TradeLore. 3. Click Connect Dhan. The server creates a consent application using the Client ID and app credentials, then redirects you to Dhan's consent login. 4. Complete the Dhan login and TOTP flow. 5. Dhan returns a token ID to TradeLore. The callback verifies that the connection was started, consumes the token, checks that the returned Dhan client ID matches the saved broker user ID, encrypts the access token and records its expiry.

If the token ID is missing, the flow was not started, credentials are missing, or the client ID does not match, the callback redirects back with a clear failure status. This is why a copied credential from a different Dhan account can fail even when the secret itself is valid.

What TradeLore imports from Dhan

The sync calls Dhan's trade endpoint with the saved client ID and decrypted access token. It normalises valid rows with exchange trade ID, order ID, exchange order ID, side, exchange segment, product type, symbol, security ID, traded quantity, traded price, and the most useful available timestamp. For derivatives it also preserves expiry, option type and strike when the source supplies them.

A Dhan record is accepted only when it has the identifiers, symbol, positive quantity and positive price needed to create a usable trade order. The normalised order enters the shared sync and trade-matching pipeline. The response reports imported trades, imported orders, total orders and total matched trades; it does not guarantee a particular historical look-back range.

Dhan's trade-history API is paginated. Verify the current response fields and availability with DhanHQ before relying on a retention window or a particular export format.

Options, duplicates and common errors

The repository test covers an NFO options record with CE type, quantity and price, so options metadata can be represented when Dhan returns it. Do not fill missing strike, expiry or lot-size values from a symbol guess. A valid record may still require a review note if the source omits a field important to your strategy.

  • Save all three credentials before connecting.
  • Reconnect when the access token expires or Dhan rejects it.
  • Compare imported totals with the Dhan trade book for one session.
  • Use order ID, exchange order ID and exchange trade ID to investigate duplicates.
  • Check the segment and timestamp fields before comparing day or time reports.

After the first sync

Choose one known day with equity and, if applicable, one derivatives trade. Compare symbol, direction, quantity, price, time and contract fields against the Dhan source. Then open the matched TradeLore trade, add the thesis, risk, exit reason and lesson, and only after that import a wider period. This makes a connection problem easier to isolate from a journaling problem.

Make review part of your trading day

Validate one Dhan session end to end before relying on a larger history.

Start using TradeLore