DhanHQ 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -1
- data/CHANGELOG.md +103 -7
- data/GUIDE.md +57 -39
- data/README.md +198 -755
- data/docs/API_DOCS_GAPS.md +128 -0
- data/docs/API_VERIFICATION.md +10 -11
- data/{README1.md → docs/ARCHIVE_README.md} +16 -16
- data/docs/AUTHENTICATION.md +72 -10
- data/docs/CONFIGURATION.md +109 -0
- data/docs/CONSTANTS_REFERENCE.md +477 -0
- data/docs/DATA_API_PARAMETERS.md +7 -7
- data/docs/{rails_websocket_integration.md → RAILS_WEBSOCKET_INTEGRATION.md} +10 -10
- data/docs/{standalone_ruby_websocket_integration.md → STANDALONE_RUBY_WEBSOCKET_INTEGRATION.md} +32 -32
- data/docs/SUPER_ORDERS.md +284 -0
- data/docs/{technical_analysis.md → TECHNICAL_ANALYSIS.md} +3 -3
- data/docs/TESTING_GUIDE.md +84 -82
- data/docs/TROUBLESHOOTING.md +117 -0
- data/docs/{websocket_integration.md → WEBSOCKET_INTEGRATION.md} +19 -19
- data/docs/WEBSOCKET_PROTOCOL.md +154 -0
- data/lib/DhanHQ/constants.rb +456 -151
- data/lib/DhanHQ/contracts/alert_order_contract.rb +37 -10
- data/lib/DhanHQ/contracts/base_contract.rb +22 -0
- data/lib/DhanHQ/contracts/edis_contract.rb +25 -0
- data/lib/DhanHQ/contracts/margin_calculator_contract.rb +27 -4
- data/lib/DhanHQ/contracts/modify_order_contract.rb +65 -12
- data/lib/DhanHQ/contracts/multi_scrip_margin_calc_request_contract.rb +23 -0
- data/lib/DhanHQ/contracts/order_contract.rb +171 -39
- data/lib/DhanHQ/contracts/place_order_contract.rb +14 -141
- data/lib/DhanHQ/contracts/pnl_based_exit_contract.rb +20 -0
- data/lib/DhanHQ/contracts/position_conversion_contract.rb +15 -3
- data/lib/DhanHQ/contracts/slice_order_contract.rb +10 -1
- data/lib/DhanHQ/contracts/user_ip_contract.rb +14 -0
- data/lib/DhanHQ/core/base_model.rb +13 -4
- data/lib/DhanHQ/helpers/response_helper.rb +2 -2
- data/lib/DhanHQ/helpers/validation_helper.rb +1 -1
- data/lib/DhanHQ/models/alert_order.rb +29 -11
- data/lib/DhanHQ/models/concerns/api_response_handler.rb +46 -0
- data/lib/DhanHQ/models/edis.rb +101 -0
- data/lib/DhanHQ/models/expired_options_data.rb +6 -12
- data/lib/DhanHQ/models/forever_order.rb +8 -5
- data/lib/DhanHQ/models/historical_data.rb +0 -8
- data/lib/DhanHQ/models/instrument.rb +1 -7
- data/lib/DhanHQ/models/instrument_helpers.rb +4 -4
- data/lib/DhanHQ/models/kill_switch.rb +23 -11
- data/lib/DhanHQ/models/margin.rb +51 -2
- data/lib/DhanHQ/models/order.rb +107 -126
- data/lib/DhanHQ/models/order_update.rb +7 -13
- data/lib/DhanHQ/models/pnl_exit.rb +122 -0
- data/lib/DhanHQ/models/position.rb +23 -1
- data/lib/DhanHQ/models/postback.rb +114 -0
- data/lib/DhanHQ/models/profile.rb +0 -10
- data/lib/DhanHQ/models/super_order.rb +13 -3
- data/lib/DhanHQ/models/trade.rb +11 -23
- data/lib/DhanHQ/resources/ip_setup.rb +16 -5
- data/lib/DhanHQ/resources/kill_switch.rb +17 -7
- data/lib/DhanHQ/resources/margin_calculator.rb +9 -0
- data/lib/DhanHQ/resources/orders.rb +41 -41
- data/lib/DhanHQ/resources/pnl_exit.rb +37 -0
- data/lib/DhanHQ/resources/positions.rb +8 -0
- data/lib/DhanHQ/version.rb +1 -1
- data/lib/DhanHQ/ws/cmd_bus.rb +1 -1
- data/lib/DhanHQ/ws/orders/client.rb +6 -6
- data/lib/DhanHQ/ws/singleton_lock.rb +2 -1
- data/lib/dhanhq/analysis/options_buying_advisor.rb +2 -2
- data/lib/rubocop/cop/dhanhq/use_constants.rb +171 -0
- metadata +29 -24
- data/TODO-1.md +0 -14
- data/TODO.md +0 -127
- data/app/services/live/order_update_guard_support.rb +0 -75
- data/app/services/live/order_update_hub.rb +0 -76
- data/app/services/live/order_update_persistence_support.rb +0 -68
- data/docs/PR_2.2.0.md +0 -48
- data/examples/comprehensive_websocket_examples.rb +0 -148
- data/examples/instrument_finder_test.rb +0 -195
- data/examples/live_order_updates.rb +0 -118
- data/examples/market_depth_example.rb +0 -144
- data/examples/market_feed_example.rb +0 -81
- data/examples/order_update_example.rb +0 -105
- data/examples/trading_fields_example.rb +0 -215
- /data/docs/{live_order_updates.md → LIVE_ORDER_UPDATES.md} +0 -0
- /data/docs/{rails_integration.md → RAILS_INTEGRATION.md} +0 -0
data/docs/{standalone_ruby_websocket_integration.md → STANDALONE_RUBY_WEBSOCKET_INTEGRATION.md}
RENAMED
|
@@ -43,10 +43,10 @@ market_client = DhanHQ::WS.connect(mode: :ticker) do |tick|
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# Subscribe to major indices
|
|
46
|
-
market_client.subscribe_one(segment:
|
|
47
|
-
market_client.subscribe_one(segment:
|
|
48
|
-
market_client.subscribe_one(segment:
|
|
49
|
-
market_client.subscribe_one(segment:
|
|
46
|
+
market_client.subscribe_one(segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13") # NIFTY
|
|
47
|
+
market_client.subscribe_one(segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25") # BANKNIFTY
|
|
48
|
+
market_client.subscribe_one(segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29") # NIFTYIT
|
|
49
|
+
market_client.subscribe_one(segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51") # SENSEX
|
|
50
50
|
|
|
51
51
|
# Wait for data
|
|
52
52
|
sleep(30)
|
|
@@ -179,10 +179,10 @@ class MarketFeedScript
|
|
|
179
179
|
|
|
180
180
|
def subscribe_to_indices
|
|
181
181
|
indices = [
|
|
182
|
-
{ segment:
|
|
183
|
-
{ segment:
|
|
184
|
-
{ segment:
|
|
185
|
-
{ segment:
|
|
182
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
183
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
184
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
185
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
186
186
|
]
|
|
187
187
|
|
|
188
188
|
indices.each do |index|
|
|
@@ -411,8 +411,8 @@ class MarketDepthScript
|
|
|
411
411
|
|
|
412
412
|
# Define symbols with correct exchange segments and security IDs
|
|
413
413
|
symbols = [
|
|
414
|
-
{ symbol: "RELIANCE", exchange_segment:
|
|
415
|
-
{ symbol: "TCS", exchange_segment:
|
|
414
|
+
{ symbol: "RELIANCE", exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ, security_id: "2885" },
|
|
415
|
+
{ symbol: "TCS", exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ, security_id: "11536" }
|
|
416
416
|
]
|
|
417
417
|
|
|
418
418
|
@depth_client = DhanHQ::WS::MarketDepth.connect(symbols: symbols) do |depth_data|
|
|
@@ -664,10 +664,10 @@ class MarketFeedDaemon
|
|
|
664
664
|
|
|
665
665
|
def subscribe_to_indices
|
|
666
666
|
indices = [
|
|
667
|
-
{ segment:
|
|
668
|
-
{ segment:
|
|
669
|
-
{ segment:
|
|
670
|
-
{ segment:
|
|
667
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
668
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
669
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
670
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
671
671
|
]
|
|
672
672
|
|
|
673
673
|
indices.each do |index|
|
|
@@ -906,10 +906,10 @@ class MarketDataCLI
|
|
|
906
906
|
|
|
907
907
|
def subscribe_to_default_indices(client)
|
|
908
908
|
indices = [
|
|
909
|
-
{ segment:
|
|
910
|
-
{ segment:
|
|
911
|
-
{ segment:
|
|
912
|
-
{ segment:
|
|
909
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
910
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
911
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
912
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
913
913
|
]
|
|
914
914
|
|
|
915
915
|
indices.each do |index|
|
|
@@ -1128,10 +1128,10 @@ class RobustWebSocketClient
|
|
|
1128
1128
|
|
|
1129
1129
|
def subscribe_to_indices
|
|
1130
1130
|
indices = [
|
|
1131
|
-
{ segment:
|
|
1132
|
-
{ segment:
|
|
1133
|
-
{ segment:
|
|
1134
|
-
{ segment:
|
|
1131
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
1132
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
1133
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
1134
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
1135
1135
|
]
|
|
1136
1136
|
|
|
1137
1137
|
indices.each do |index|
|
|
@@ -1311,10 +1311,10 @@ class ProductionWebSocketClient
|
|
|
1311
1311
|
|
|
1312
1312
|
def subscribe_to_indices
|
|
1313
1313
|
indices = [
|
|
1314
|
-
{ segment:
|
|
1315
|
-
{ segment:
|
|
1316
|
-
{ segment:
|
|
1317
|
-
{ segment:
|
|
1314
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
1315
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
1316
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
1317
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
1318
1318
|
]
|
|
1319
1319
|
|
|
1320
1320
|
indices.each do |index|
|
|
@@ -1461,8 +1461,8 @@ class WebSocketMonitor
|
|
|
1461
1461
|
|
|
1462
1462
|
def start_market_depth_client
|
|
1463
1463
|
symbols = [
|
|
1464
|
-
{ symbol: "RELIANCE", exchange_segment:
|
|
1465
|
-
{ symbol: "TCS", exchange_segment:
|
|
1464
|
+
{ symbol: "RELIANCE", exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ, security_id: "2885" },
|
|
1465
|
+
{ symbol: "TCS", exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ, security_id: "11536" }
|
|
1466
1466
|
]
|
|
1467
1467
|
|
|
1468
1468
|
@clients[:market_depth] = DhanHQ::WS::MarketDepth.connect(symbols: symbols) do |depth_data|
|
|
@@ -1483,10 +1483,10 @@ class WebSocketMonitor
|
|
|
1483
1483
|
|
|
1484
1484
|
def subscribe_to_indices(client)
|
|
1485
1485
|
indices = [
|
|
1486
|
-
{ segment:
|
|
1487
|
-
{ segment:
|
|
1488
|
-
{ segment:
|
|
1489
|
-
{ segment:
|
|
1486
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "13", name: "NIFTY" },
|
|
1487
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "25", name: "BANKNIFTY" },
|
|
1488
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "29", name: "NIFTYIT" },
|
|
1489
|
+
{ segment: DhanHQ::Constants::ExchangeSegment::IDX_I, security_id: "51", name: "SENSEX" }
|
|
1490
1490
|
]
|
|
1491
1491
|
|
|
1492
1492
|
indices.each do |index|
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Super Orders — Full API Reference
|
|
2
|
+
|
|
3
|
+
Super orders are built for smart execution. They club the entry, target, and stop-loss legs (with optional trailing jump) into a single request so you can manage risk immediately after entry.
|
|
4
|
+
|
|
5
|
+
This gem exposes the full REST surface to create, modify, cancel, and list super orders across all supported exchanges and segments.
|
|
6
|
+
|
|
7
|
+
## Endpoints
|
|
8
|
+
|
|
9
|
+
| Method | Path | Description |
|
|
10
|
+
| -------- | -------------------------------------- | ------------------------------------- |
|
|
11
|
+
| `POST` | `/super/orders` | Create a new super order |
|
|
12
|
+
| `PUT` | `/super/orders/{order_id}` | Modify a pending super order |
|
|
13
|
+
| `DELETE` | `/super/orders/{order_id}/{order_leg}` | Cancel a pending super order leg |
|
|
14
|
+
| `GET` | `/super/orders` | Retrieve the list of all super orders |
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Place Super Order
|
|
19
|
+
|
|
20
|
+
The place endpoint lets you submit a new super order that can include entry, target, stop-loss, and optional trailing jump definitions. It is available across exchanges and segments, and supports intraday, carry-forward, or MTF orders.
|
|
21
|
+
|
|
22
|
+
> ℹ️ Static IP whitelisting with Dhan support is required before invoking this API.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
curl --request POST \
|
|
26
|
+
--url https://api.dhan.co/v2/super/orders \
|
|
27
|
+
--header 'Content-Type: application/json' \
|
|
28
|
+
--header 'access-token: JWT' \
|
|
29
|
+
--data '{Request JSON}'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Request body
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"dhan_client_id": "1000000003",
|
|
37
|
+
"correlation_id": "123abc678",
|
|
38
|
+
"transaction_type": "BUY",
|
|
39
|
+
"exchange_segment": "NSE_EQ",
|
|
40
|
+
"product_type": "CNC",
|
|
41
|
+
"order_type": "LIMIT",
|
|
42
|
+
"security_id": "11536",
|
|
43
|
+
"quantity": 5,
|
|
44
|
+
"price": 1500,
|
|
45
|
+
"target_price": 1600,
|
|
46
|
+
"stop_loss_price": 1400,
|
|
47
|
+
"trailing_jump": 10
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Parameters
|
|
52
|
+
|
|
53
|
+
| Field | Type | Description |
|
|
54
|
+
| ------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `dhan_client_id` | string *(required)* | User specific identification generated by Dhan. When you call through `DhanHQ::Models::SuperOrder`, the gem injects your configured client id so you can omit this key locally. |
|
|
56
|
+
| `correlation_id` | string | Caller generated correlation identifier |
|
|
57
|
+
| `transaction_type` | enum string *(required)* | Trading side. `BUY` or `SELL`. |
|
|
58
|
+
| `exchange_segment` | enum string *(required)* | Exchange segment (see appendix). |
|
|
59
|
+
| `product_type` | enum string *(required)* | Product type. `CNC`, `INTRADAY`, `MARGIN`, or `MTF`. |
|
|
60
|
+
| `order_type` | enum string *(required)* | Order type. `LIMIT` or `MARKET`. |
|
|
61
|
+
| `security_id` | string *(required)* | Exchange standard security identifier. |
|
|
62
|
+
| `quantity` | integer *(required)* | Number of shares for the order. |
|
|
63
|
+
| `price` | float *(required)* | Price at which the entry leg is placed. |
|
|
64
|
+
| `target_price` | float *(required)* | Target price for the super order. |
|
|
65
|
+
| `stop_loss_price` | float *(required)* | Stop-loss price for the super order. |
|
|
66
|
+
| `trailing_jump` | float *(required)* | Price jump size used to trail the stop-loss. |
|
|
67
|
+
|
|
68
|
+
> 🐍 When you call `DhanHQ::Models::SuperOrder.create`, pass snake_case keys as shown above. The client automatically camelizes
|
|
69
|
+
> them before posting to Dhan's REST API and injects your configured `dhan_client_id`, so you can omit that key in Ruby code.
|
|
70
|
+
|
|
71
|
+
### Response
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"order_id": "112111182198",
|
|
76
|
+
"order_status": "PENDING"
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Field | Type | Description |
|
|
81
|
+
| -------------- | ----------- | --------------------------------------------------- |
|
|
82
|
+
| `order_id` | string | Order identifier generated by Dhan |
|
|
83
|
+
| `order_status` | enum string | Latest status. `TRANSIT`, `PENDING`, or `REJECTED`. |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Modify Super Order
|
|
88
|
+
|
|
89
|
+
Use the modify endpoint to update any leg while the super order remains in `PENDING` or `PART_TRADED` status.
|
|
90
|
+
|
|
91
|
+
> ℹ️ Static IP whitelisting with Dhan support is required before invoking this API.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
curl --request PUT \
|
|
95
|
+
--url https://api.dhan.co/v2/super/orders/{order_id} \
|
|
96
|
+
--header 'Content-Type: application/json' \
|
|
97
|
+
--header 'access-token: JWT' \
|
|
98
|
+
--data '{Request JSON}'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Request body
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"dhan_client_id": "1000000009",
|
|
106
|
+
"order_id": "112111182045",
|
|
107
|
+
"order_type": "LIMIT",
|
|
108
|
+
"leg_name": "ENTRY_LEG",
|
|
109
|
+
"quantity": 40,
|
|
110
|
+
"price": 1300,
|
|
111
|
+
"target_price": 1450,
|
|
112
|
+
"stop_loss_price": 1350,
|
|
113
|
+
"trailing_jump": 20
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Parameters
|
|
118
|
+
|
|
119
|
+
| Field | Type | Description |
|
|
120
|
+
| ----------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
121
|
+
| `dhan_client_id` | string *(required)* | User specific identification generated by Dhan. Automatically added when you call through the Ruby models. |
|
|
122
|
+
| `order_id` | string *(required)* | Super order identifier generated by Dhan. |
|
|
123
|
+
| `order_type` | enum string *(conditionally required)* | `LIMIT` or `MARKET`. Required when modifying `ENTRY_LEG`. |
|
|
124
|
+
| `leg_name` | enum string *(required)* | `ENTRY_LEG`, `TARGET_LEG`, or `STOP_LOSS_LEG`. Entry leg updates entire order while status is `PENDING` or `PART_TRADED`. |
|
|
125
|
+
| `quantity` | integer *(conditionally required)* | Quantity update for `ENTRY_LEG`. |
|
|
126
|
+
| `price` | float *(conditionally required)* | Entry price update for `ENTRY_LEG`. |
|
|
127
|
+
| `target_price` | float *(conditionally required)* | Target price update for `ENTRY_LEG` or `TARGET_LEG`. |
|
|
128
|
+
| `stop_loss_price` | float *(conditionally required)* | Stop-loss price update for `ENTRY_LEG` or `STOP_LOSS_LEG`. |
|
|
129
|
+
| `trailing_jump` | float *(conditionally required)* | Trailing jump update for `ENTRY_LEG` or `STOP_LOSS_LEG`. Omit or set to `0` to cancel trailing. |
|
|
130
|
+
|
|
131
|
+
> ℹ️ Once the entry leg status becomes `TRADED`, only the `TARGET_LEG` and `STOP_LOSS_LEG` can be modified (price and trailing jump).
|
|
132
|
+
|
|
133
|
+
### Response
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"order_id": "112111182045",
|
|
138
|
+
"order_status": "TRANSIT"
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| Field | Type | Description |
|
|
143
|
+
| -------------- | ----------- | ------------------------------------------------------------- |
|
|
144
|
+
| `order_id` | string | Order identifier generated by Dhan |
|
|
145
|
+
| `order_status` | enum string | Latest status. `TRANSIT`, `PENDING`, `REJECTED`, or `TRADED`. |
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Cancel Super Order
|
|
150
|
+
|
|
151
|
+
Cancel a pending or active super order leg using the order ID. Cancelling the entry leg removes every leg. Cancelling a specific target or stop-loss leg removes only that leg and it cannot be re-added.
|
|
152
|
+
|
|
153
|
+
> ℹ️ Static IP whitelisting with Dhan support is required before invoking this API.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
curl --request DELETE \
|
|
157
|
+
--url https://api.dhan.co/v2/super/orders/{order_id}/{order_leg} \
|
|
158
|
+
--header 'Content-Type: application/json' \
|
|
159
|
+
--header 'access-token: JWT'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Path parameters
|
|
163
|
+
|
|
164
|
+
| Field | Description | Example |
|
|
165
|
+
| ----------- | ------------------------------------------------------------- | ------------- |
|
|
166
|
+
| `order_id` | Super order identifier. | `11211182198` |
|
|
167
|
+
| `order_leg` | Leg to cancel. `ENTRY_LEG`, `TARGET_LEG`, or `STOP_LOSS_LEG`. | `ENTRY_LEG` |
|
|
168
|
+
|
|
169
|
+
### Response
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"order_id": "112111182045",
|
|
174
|
+
"order_status": "CANCELLED"
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
| Field | Type | Description |
|
|
179
|
+
| -------------- | ----------- | ---------------------------------------------------------------- |
|
|
180
|
+
| `order_id` | string | Order identifier generated by Dhan |
|
|
181
|
+
| `order_status` | enum string | Latest status. `TRANSIT`, `PENDING`, `REJECTED`, or `CANCELLED`. |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Super Order List
|
|
186
|
+
|
|
187
|
+
List every super order placed during the trading day. The API nests leg details under the entry leg, and individual legs also appear in the main order book.
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
curl --request GET \
|
|
191
|
+
--url https://api.dhan.co/v2/super/orders \
|
|
192
|
+
--header 'Content-Type: application/json' \
|
|
193
|
+
--header 'access-token: JWT'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Response
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
[
|
|
200
|
+
{
|
|
201
|
+
"dhan_client_id": "1100003626",
|
|
202
|
+
"order_id": "5925022734212",
|
|
203
|
+
"correlation_id": "string",
|
|
204
|
+
"order_status": "PENDING",
|
|
205
|
+
"transaction_type": "BUY",
|
|
206
|
+
"exchange_segment": "NSE_EQ",
|
|
207
|
+
"product_type": "CNC",
|
|
208
|
+
"order_type": "LIMIT",
|
|
209
|
+
"validity": "DAY",
|
|
210
|
+
"trading_symbol": "HDFCBANK",
|
|
211
|
+
"security_id": "1333",
|
|
212
|
+
"quantity": 10,
|
|
213
|
+
"remaining_quantity": 10,
|
|
214
|
+
"ltp": 1660.95,
|
|
215
|
+
"price": 1500,
|
|
216
|
+
"after_market_order": false,
|
|
217
|
+
"leg_name": "ENTRY_LEG",
|
|
218
|
+
"exchange_order_id": "11925022734212",
|
|
219
|
+
"create_time": "2025-02-27 19:09:42",
|
|
220
|
+
"update_time": "2025-02-27 19:09:42",
|
|
221
|
+
"exchange_time": "2025-02-27 19:09:42",
|
|
222
|
+
"oms_error_description": "",
|
|
223
|
+
"average_traded_price": 0,
|
|
224
|
+
"filled_qty": 0,
|
|
225
|
+
"leg_details": [
|
|
226
|
+
{
|
|
227
|
+
"order_id": "5925022734212",
|
|
228
|
+
"leg_name": "STOP_LOSS_LEG",
|
|
229
|
+
"transaction_type": "SELL",
|
|
230
|
+
"total_quantity": 0,
|
|
231
|
+
"remaining_quantity": 0,
|
|
232
|
+
"triggered_quantity": 0,
|
|
233
|
+
"price": 1400,
|
|
234
|
+
"order_status": "PENDING",
|
|
235
|
+
"trailing_jump": 10
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"order_id": "5925022734212",
|
|
239
|
+
"leg_name": "TARGET_LEG",
|
|
240
|
+
"transaction_type": "SELL",
|
|
241
|
+
"remaining_quantity": 0,
|
|
242
|
+
"triggered_quantity": 0,
|
|
243
|
+
"price": 1550,
|
|
244
|
+
"order_status": "PENDING",
|
|
245
|
+
"trailing_jump": 0
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Response Parameters
|
|
253
|
+
|
|
254
|
+
| Field | Type | Description |
|
|
255
|
+
| ----------------------- | ----------- | --------------------------------------------------------------------------------------------------- |
|
|
256
|
+
| `dhan_client_id` | string | User specific identification generated by Dhan. |
|
|
257
|
+
| `order_id` | string | Order identifier generated by Dhan. |
|
|
258
|
+
| `correlation_id` | string | Correlation identifier supplied by the caller. |
|
|
259
|
+
| `order_status` | enum string | Latest status. `TRANSIT`, `PENDING`, `CLOSED`, `REJECTED`, `CANCELLED`, `PART_TRADED`, or `TRADED`. |
|
|
260
|
+
| `transaction_type` | enum string | Trading side. `BUY` or `SELL`. |
|
|
261
|
+
| `exchange_segment` | enum string | Exchange segment. |
|
|
262
|
+
| `product_type` | enum string | Product type. `CNC`, `INTRADAY`, `MARGIN`, or `MTF`. |
|
|
263
|
+
| `order_type` | enum string | Order type. `LIMIT` or `MARKET`. |
|
|
264
|
+
| `validity` | enum string | Order validity. `DAY`. |
|
|
265
|
+
| `trading_symbol` | string | Trading symbol reference. |
|
|
266
|
+
| `security_id` | string | Exchange security identifier. |
|
|
267
|
+
| `quantity` | integer | Ordered quantity. |
|
|
268
|
+
| `remaining_quantity` | integer | Quantity pending execution. |
|
|
269
|
+
| `ltp` | float | Last traded price. |
|
|
270
|
+
| `price` | float | Order price. |
|
|
271
|
+
| `after_market_order` | boolean | Indicates if the order was placed after market hours. |
|
|
272
|
+
| `leg_name` | enum string | Leg identifier: `ENTRY_LEG`, `TARGET_LEG`, or `STOP_LOSS_LEG`. |
|
|
273
|
+
| `trailing_jump` | float | Trailing jump for stop-loss. |
|
|
274
|
+
| `exchange_order_id` | string | Exchange-generated order identifier. |
|
|
275
|
+
| `create_time` | string | Order creation timestamp. |
|
|
276
|
+
| `update_time` | string | Latest update timestamp. |
|
|
277
|
+
| `exchange_time` | string | Exchange timestamp. |
|
|
278
|
+
| `oms_error_description` | string | OMS error description when applicable. |
|
|
279
|
+
| `average_traded_price` | float | Average traded price. |
|
|
280
|
+
| `filled_qty` | integer | Quantity traded on the exchange. |
|
|
281
|
+
| `triggered_quantity` | integer | Quantity triggered for stop-loss or target legs. |
|
|
282
|
+
| `leg_details` | array | Nested leg details for the super order. |
|
|
283
|
+
|
|
284
|
+
> ✅ `CLOSED` indicates the entry leg plus either target or stop-loss leg completed for the entire quantity. `TRIGGERED` appears on target and stop-loss legs to show which leg fired; inspect `triggered_quantity` for the executed quantity.
|
|
@@ -26,8 +26,8 @@ DhanHQ.configure_with_env
|
|
|
26
26
|
|
|
27
27
|
ta = TA::TechnicalAnalysis.new(throttle_seconds: 2.5, max_retries: 3)
|
|
28
28
|
indicators = ta.compute(
|
|
29
|
-
exchange_segment:
|
|
30
|
-
instrument:
|
|
29
|
+
exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ,
|
|
30
|
+
instrument: DhanHQ::Constants::InstrumentType::EQUITY,
|
|
31
31
|
security_id: "1333",
|
|
32
32
|
intervals: [1, 5, 15, 25, 60] # each fetched directly from API
|
|
33
33
|
)
|
|
@@ -75,7 +75,7 @@ Example summary:
|
|
|
75
75
|
|
|
76
76
|
```ruby
|
|
77
77
|
{
|
|
78
|
-
meta: { security_id: "1333", instrument:
|
|
78
|
+
meta: { security_id: "1333", instrument: DhanHQ::Constants::InstrumentType::EQUITY, exchange_segment: DhanHQ::Constants::ExchangeSegment::NSE_EQ },
|
|
79
79
|
summary: {
|
|
80
80
|
bias: :bullish, # :bullish | :bearish | :neutral
|
|
81
81
|
setup: :buy_on_dip, # :buy_on_dip | :sell_on_rise | :range_trade
|