DhanHQ 2.3.0 → 2.5.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/CHANGELOG.md +50 -1
- data/CODE_REVIEW_ISSUES.md +2 -2
- data/GUIDE.md +2 -2
- data/README.md +194 -741
- data/REVIEW_SUMMARY.md +2 -2
- data/{README1.md → docs/ARCHIVE_README.md} +4 -4
- data/docs/AUTHENTICATION.md +116 -2
- data/docs/CONFIGURATION.md +109 -0
- data/docs/SUPER_ORDERS.md +284 -0
- data/docs/TESTING_GUIDE.md +8 -8
- data/docs/TROUBLESHOOTING.md +117 -0
- data/docs/WEBSOCKET_PROTOCOL.md +154 -0
- data/docs/live_order_updates.md +2 -2
- data/docs/rails_integration.md +7 -7
- data/docs/standalone_ruby_websocket_integration.md +24 -24
- data/docs/technical_analysis.md +1 -1
- data/docs/websocket_integration.md +4 -4
- data/examples/comprehensive_websocket_examples.rb +2 -2
- data/examples/instrument_finder_test.rb +2 -2
- data/examples/market_depth_example.rb +2 -2
- data/examples/market_feed_example.rb +2 -2
- data/examples/order_update_example.rb +2 -2
- data/examples/trading_fields_example.rb +2 -2
- data/lib/DhanHQ/auth/token_generator.rb +33 -0
- data/lib/DhanHQ/auth/token_manager.rb +88 -0
- data/lib/DhanHQ/auth/token_renewal.rb +25 -0
- data/lib/DhanHQ/auth.rb +91 -31
- data/lib/DhanHQ/client.rb +42 -2
- data/lib/DhanHQ/configuration.rb +2 -2
- data/lib/DhanHQ/contracts/order_contract.rb +0 -23
- data/lib/DhanHQ/contracts/trade_by_order_id_contract.rb +12 -0
- data/lib/DhanHQ/contracts/trade_contract.rb +0 -65
- data/lib/DhanHQ/contracts/trade_history_contract.rb +52 -0
- data/lib/DhanHQ/core/auth_api.rb +21 -0
- data/lib/DhanHQ/helpers/request_helper.rb +1 -1
- data/lib/DhanHQ/models/alert_order.rb +22 -0
- data/lib/DhanHQ/models/edis.rb +110 -0
- data/lib/DhanHQ/models/kill_switch.rb +22 -0
- data/lib/DhanHQ/models/margin.rb +49 -0
- data/lib/DhanHQ/models/pnl_exit.rb +130 -0
- data/lib/DhanHQ/models/position.rb +22 -0
- data/lib/DhanHQ/models/postback.rb +123 -0
- data/lib/DhanHQ/models/token_response.rb +88 -0
- data/lib/DhanHQ/resources/kill_switch.rb +8 -0
- data/lib/DhanHQ/resources/margin_calculator.rb +9 -0
- 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/dhan_hq.rb +31 -81
- metadata +46 -4
- data/lib/DhanHQ/config.rb +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77553eb49e2a23ec764bc3baeebd5426f60054fbdbc4eb4c7c49d7f2c7e87515
|
|
4
|
+
data.tar.gz: 9fc44cb543abbc725cdee1489c66a08bd5d2615772640b454e46d54fb7b139f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47344dfbf5aba9b0c48e05937e3d9ff28d7a43db87442d1e695b84477568d5df02e83c918e884000751f094996e43984000b8f4c32bec235313f64673756b176
|
|
7
|
+
data.tar.gz: f68c7be56db1807c284e01007cf0003f8519f92d57209d4073686f84e35d36db06e36f151c8b3b3df5dbae59bc272010c7e3ce4898e5a23eeddb5d6162f10b2c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,53 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [2.5.0] - 2026-02-21
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
#### New Endpoints — Full Dhan API v2 Parity
|
|
6
|
+
- **Exit All Positions**: `DhanHQ::Models::Position.exit_all!` — emergency closure of all positions and cancellation of all open orders via `DELETE /v2/positions`. Resource method: `DhanHQ::Resources::Positions#exit_all`.
|
|
7
|
+
- **Kill Switch Status**: `DhanHQ::Models::KillSwitch.status` — query current kill switch state via `GET /v2/killswitch`. Resource method: `DhanHQ::Resources::KillSwitch#status`.
|
|
8
|
+
- **P&L Based Exit**: New `DhanHQ::Models::PnlExit` model and `DhanHQ::Resources::PnlExit` resource for automatic profit/loss-based position exit:
|
|
9
|
+
- `PnlExit.configure(profit_value:, loss_value:, product_type:, enable_kill_switch:)` — `POST /v2/pnlExit`
|
|
10
|
+
- `PnlExit.stop` — `DELETE /v2/pnlExit`
|
|
11
|
+
- `PnlExit.status` — `GET /v2/pnlExit`
|
|
12
|
+
- **Multi-Order Margin Calculator**: `DhanHQ::Models::Margin.calculate_multi` — batch margin calculation with hedge benefit across multiple instruments via `POST /v2/margincalculator/multi`. Resource method: `DhanHQ::Resources::MarginCalculator#calculate_multi`.
|
|
13
|
+
- **EDIS Model**: New `DhanHQ::Models::Edis` wrapping existing `DhanHQ::Resources::Edis` with ORM-style class methods:
|
|
14
|
+
- `Edis.generate_tpin`, `Edis.generate_form`, `Edis.generate_bulk_form`, `Edis.inquire`
|
|
15
|
+
- **Postback Payload Parser**: New `DhanHQ::Models::Postback` utility model for parsing Dhan webhook payloads:
|
|
16
|
+
- `Postback.parse(json_or_hash)` — accepts JSON string or Hash
|
|
17
|
+
- Status predicates: `traded?`, `rejected?`, `pending?`, `cancelled?`
|
|
18
|
+
- **AlertOrder Modify**: Explicit `DhanHQ::Models::AlertOrder.modify(alert_id, params)` class method for updating conditional triggers with better discoverability.
|
|
19
|
+
|
|
20
|
+
#### Tests
|
|
21
|
+
- **28 new specs** across 7 files (442 total, 0 failures):
|
|
22
|
+
- `spec/dhan_hq/models/pnl_exit_spec.rb` — configure, stop, status, defaults, nil handling
|
|
23
|
+
- `spec/dhan_hq/models/edis_spec.rb` — generate_tpin, generate_form, bulk_form, inquire
|
|
24
|
+
- `spec/dhan_hq/models/postback_spec.rb` — JSON/Hash parsing, snake_case support, status predicates
|
|
25
|
+
- Updated: `kill_switch_spec.rb`, `positions_spec.rb`, `margin_spec.rb`, `alert_order_spec.rb`
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- **README.md**: Updated Key Features to reflect full API v2 parity including P&L Exit, Postback parser, and EDIS model.
|
|
29
|
+
- **Bundler**: Updated `BUNDLED WITH` to latest version, eliminating platform constant re-definition warnings.
|
|
30
|
+
|
|
31
|
+
### Notes
|
|
32
|
+
- **Backward Compatible**: All changes are additive — no existing APIs or method signatures changed.
|
|
33
|
+
- **Full API v2 Parity**: The gem now covers every endpoint documented at [dhanhq.co/docs/v2](https://dhanhq.co/docs/v2/).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## [2.4.0] - 2026-02-18
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
- Support for Individual TOTP-based access token generation
|
|
41
|
+
- `DhanHQ::Auth.generate_access_token`
|
|
42
|
+
- `DhanHQ::Auth.generate_totp`
|
|
43
|
+
|
|
44
|
+
### Updated
|
|
45
|
+
- RenewToken now uses POST (aligned with Dhan API behavior)
|
|
46
|
+
- Improved error handling for authentication APIs
|
|
47
|
+
|
|
48
|
+
### Notes
|
|
49
|
+
- TOTP tokens can now be programmatically regenerated without browser login
|
|
50
|
+
- RenewToken still applies only to web-generated tokens
|
|
2
51
|
|
|
3
52
|
---
|
|
4
53
|
|
data/CODE_REVIEW_ISSUES.md
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
**Location**: `lib/DhanHQ/client.rb:40`
|
|
13
13
|
**Issue**: The client initializes configuration conditionally, which can lead to runtime errors:
|
|
14
14
|
```ruby
|
|
15
|
-
DhanHQ.configure_with_env if ENV.fetch("
|
|
15
|
+
DhanHQ.configure_with_env if ENV.fetch("DHAN_CLIENT_ID", nil)
|
|
16
16
|
```
|
|
17
|
-
**Problem**: If `
|
|
17
|
+
**Problem**: If `DHAN_CLIENT_ID` exists but `DHAN_ACCESS_TOKEN` doesn't, configuration will be partially initialized, leading to authentication failures later.
|
|
18
18
|
**Recommendation**: Validate both required credentials before proceeding or fail fast with a clear error message.
|
|
19
19
|
|
|
20
20
|
### 2. **Race Condition in Rate Limiter**
|
data/GUIDE.md
CHANGED
|
@@ -44,8 +44,8 @@ DhanHQ.logger.level = (ENV["DHAN_LOG_LEVEL"] || "INFO").upcase.then { |level| Lo
|
|
|
44
44
|
|
|
45
45
|
| Variable | Description |
|
|
46
46
|
| -------------- | ---------------------------------------------------- |
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
47
|
+
| `DHAN_CLIENT_ID` | Your Dhan trading client id. |
|
|
48
|
+
| `DHAN_ACCESS_TOKEN` | REST/WebSocket access token generated via Dhan APIs. |
|
|
49
49
|
|
|
50
50
|
Provide them via `.env`, Rails credentials, or your secret manager of choice
|
|
51
51
|
before the initializer runs.
|