Skip to content

API Reference


API Reference / ConditionalTriggers

Class: ConditionalTriggers ​

Defined in: src/resources/ConditionalTriggers.ts:70

Conditional Trigger Orders (Alert Orders) API wrapper.

This wraps the /v2/alerts/orders endpoints for placing orders triggered by price or technical indicators. Unlike standard GTT/Forever orders, conditional triggers support:

  • PRICE_WITH_VALUE: Trigger when price crosses a specific value
  • TECHNICAL_WITH_VALUE: Trigger when an indicator (SMA, RSI, etc.) crosses a value
  • TECHNICAL_WITH_INDICATOR: Trigger when one indicator crosses another (e.g., SMA_20 > SMA_50)
  • Multiple orders can be triggered from a single condition

See ​

https://docs.dhanhq.co/api/v2/conditional-triggers

Constructors ​

Constructor ​

new ConditionalTriggers(httpClient): ConditionalTriggers

Defined in: src/resources/ConditionalTriggers.ts:71

Parameters ​

httpClient ​

HttpClient

Returns ​

ConditionalTriggers

Methods ​

list() ​

list(): Promise<GetAlertResponse[]>

Defined in: src/resources/ConditionalTriggers.ts:76

List all conditional trigger orders.

Returns ​

Promise<GetAlertResponse[]>


getById() ​

getById(alertId): Promise<GetAlertResponse>

Defined in: src/resources/ConditionalTriggers.ts:87

Get a specific conditional trigger order by ID.

Parameters ​

alertId ​

string

Returns ​

Promise<GetAlertResponse>


place() ​

place(request): Promise<AlertOrderResponse>

Defined in: src/resources/ConditionalTriggers.ts:139

Place a new conditional trigger order.

Parameters ​

request ​

PlaceConditionalTriggerRequest

Returns ​

Promise<AlertOrderResponse>

Example ​

ts
// Price-based trigger: buy a NIFTY option when the index spot crosses 24,500
await client.conditionalTriggers.place({
  dhanClientId: process.env.DHAN_CLIENT_ID!,
  condition: {
    comparisonType: "PRICE_WITH_VALUE",
    exchangeSegment: "IDX_I",
    securityId: "13", // NIFTY 50 index
    operator: "GREATER_THAN",
    comparingValue: 24500,
    frequency: "ONCE",
  },
  orders: [{
    transactionType: "BUY",
    exchangeSegment: "NSE_FNO",
    productType: "INTRADAY",
    orderType: "MARKET",
    validity: "DAY",
    securityId: "44000", // the FNO contract to buy when triggered
    quantity: 50,
  }],
});

// Technical trigger: Buy when RSI crosses above 30
await client.conditionalTriggers.place({
  dhanClientId: process.env.DHAN_CLIENT_ID!,
  condition: {
    comparisonType: "TECHNICAL_WITH_VALUE",
    exchangeSegment: "NSE_EQ",
    securityId: "26009", // RELIANCE
    indicatorName: "RSI_14",
    timeFrame: "FIFTEEN_MIN",
    operator: "CROSSING_UP",
    comparingValue: 30,
    frequency: "ONCE",
  },
  orders: [ { transactionType: "BUY", exchangeSegment: "NSE_FNO", productType: "INTRADAY", orderType: "MARKET", validity: "DAY", securityId: "44000", quantity: 50 } ],
});

modify() ​

modify(alertId, request): Promise<AlertOrderResponse>

Defined in: src/resources/ConditionalTriggers.ts:153

Modify an existing conditional trigger order.

Parameters ​

alertId ​

string

request ​

ModifyConditionalTriggerRequest

Returns ​

Promise<AlertOrderResponse>


cancel() ​

cancel(alertId): Promise<AlertOrderResponse>

Defined in: src/resources/ConditionalTriggers.ts:168

Cancel/delete a conditional trigger order.

Parameters ​

alertId ​

string

Returns ​

Promise<AlertOrderResponse>


buildPriceCondition() ​

static buildPriceCondition(options): AlertConditionInput

Defined in: src/resources/ConditionalTriggers.ts:188

Helper: Build a price-based condition for options buying stop-loss.

Parameters ​

options ​
exchangeSegment ​

"IDX_I" | "NSE_EQ" | "BSE_EQ" | undefined

securityId ​

string

triggerAbove? ​

number

triggerBelow? ​

number

frequency? ​

"ONCE"

Returns ​

AlertConditionInput

Example ​

ts
const condition = ConditionalTriggers.buildPriceCondition({
  exchangeSegment: "IDX_I",
  securityId: "13", // NIFTY 50 index
  triggerAbove: 24500, // Trigger when Nifty goes above 24500
});

buildTechnicalCondition() ​

static buildTechnicalCondition(options): AlertConditionInput

Defined in: src/resources/ConditionalTriggers.ts:240

Helper: Build a technical indicator-based condition.

Parameters ​

options ​
exchangeSegment ​

"IDX_I" | "NSE_EQ" | "BSE_EQ" | undefined

securityId ​

string

indicatorName ​

"SMA_5" | "SMA_10" | "SMA_20" | "SMA_50" | "SMA_100" | "SMA_200" | "EMA_5" | "EMA_10" | "EMA_20" | "EMA_50" | "EMA_100" | "EMA_200" | "BB_UPPER" | "BB_LOWER" | "RSI_14" | "ATR_14" | "STOCHASTIC" | "STOCHRSI_14" | "MACD_26" | "MACD_12" | "MACD_HIST" | undefined

timeFrame? ​

"DAY" | "ONE_MIN" | "FIVE_MIN" | "FIFTEEN_MIN"

crossingAbove? ​

number

crossingBelow? ​

number

frequency? ​

"ONCE"

Returns ​

AlertConditionInput

Example ​

ts
const condition = ConditionalTriggers.buildTechnicalCondition({
  exchangeSegment: "NSE_EQ",
  securityId: "26009", // RELIANCE
  indicatorName: "SMA_20",
  timeFrame: "FIFTEEN_MIN",
  crossingAbove: 2500, // Trigger when SMA_20 crosses above 2500
});

Community project — not affiliated with Dhan. MIT License.