DhanHQ 2.3.0 → 2.4.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 +17 -0
- data/CODE_REVIEW_ISSUES.md +2 -2
- data/GUIDE.md +2 -2
- data/README.md +15 -4
- data/README1.md +4 -4
- data/REVIEW_SUMMARY.md +2 -2
- data/docs/AUTHENTICATION.md +54 -2
- data/docs/TESTING_GUIDE.md +8 -8
- 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/token_response.rb +88 -0
- data/lib/DhanHQ/version.rb +1 -1
- data/lib/dhan_hq.rb +31 -81
- metadata +37 -3
- data/lib/DhanHQ/config.rb +0 -33
data/lib/dhan_hq.rb
CHANGED
|
@@ -1,96 +1,46 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "json"
|
|
4
4
|
require "logger"
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
require "zeitwerk"
|
|
6
|
+
require "dotenv/load"
|
|
7
|
+
# Minimal eager requires for backward-compatible constants.
|
|
8
|
+
# These are widely referenced (e.g. `DhanHQ::BaseAPI`) and should not depend on
|
|
9
|
+
# the autoloader being fully configured.
|
|
7
10
|
require_relative "DhanHQ/helpers/api_helper"
|
|
8
11
|
require_relative "DhanHQ/helpers/attribute_helper"
|
|
9
12
|
require_relative "DhanHQ/helpers/validation_helper"
|
|
10
13
|
require_relative "DhanHQ/helpers/request_helper"
|
|
11
14
|
require_relative "DhanHQ/helpers/response_helper"
|
|
12
|
-
require_relative "DhanHQ/json_loader"
|
|
13
|
-
|
|
14
15
|
require_relative "DhanHQ/core/base_api"
|
|
15
|
-
require_relative "DhanHQ/core/base_resource"
|
|
16
16
|
require_relative "DhanHQ/core/base_model"
|
|
17
|
-
require_relative "DhanHQ/core/
|
|
18
|
-
|
|
19
|
-
require_relative "DhanHQ/version"
|
|
20
|
-
require_relative "DhanHQ/errors"
|
|
21
|
-
require_relative "DhanHQ/error_object"
|
|
22
|
-
|
|
23
|
-
require_relative "DhanHQ/client"
|
|
24
|
-
require_relative "DhanHQ/configuration"
|
|
25
|
-
require_relative "DhanHQ/rate_limiter"
|
|
26
|
-
require_relative "DhanHQ/auth"
|
|
27
|
-
|
|
28
|
-
# Contracts
|
|
29
|
-
require_relative "DhanHQ/contracts/base_contract"
|
|
30
|
-
require_relative "DhanHQ/contracts/historical_data_contract"
|
|
31
|
-
require_relative "DhanHQ/contracts/margin_calculator_contract"
|
|
32
|
-
require_relative "DhanHQ/contracts/position_conversion_contract"
|
|
33
|
-
require_relative "DhanHQ/contracts/slice_order_contract"
|
|
34
|
-
require_relative "DhanHQ/contracts/trade_contract"
|
|
35
|
-
require_relative "DhanHQ/contracts/expired_options_data_contract"
|
|
36
|
-
require_relative "DhanHQ/contracts/alert_order_contract"
|
|
37
|
-
|
|
38
|
-
# Resources
|
|
39
|
-
require_relative "DhanHQ/resources/option_chain"
|
|
40
|
-
require_relative "DhanHQ/resources/orders"
|
|
41
|
-
require_relative "DhanHQ/resources/forever_orders"
|
|
42
|
-
require_relative "DhanHQ/resources/super_orders"
|
|
43
|
-
require_relative "DhanHQ/resources/funds"
|
|
44
|
-
require_relative "DhanHQ/resources/holdings"
|
|
45
|
-
require_relative "DhanHQ/resources/positions"
|
|
46
|
-
require_relative "DhanHQ/resources/statements"
|
|
47
|
-
require_relative "DhanHQ/resources/trades"
|
|
48
|
-
require_relative "DhanHQ/resources/historical_data"
|
|
49
|
-
require_relative "DhanHQ/resources/margin_calculator"
|
|
50
|
-
require_relative "DhanHQ/resources/market_feed"
|
|
51
|
-
require_relative "DhanHQ/resources/instruments"
|
|
52
|
-
require_relative "DhanHQ/resources/alert_orders"
|
|
53
|
-
require_relative "DhanHQ/resources/edis"
|
|
54
|
-
require_relative "DhanHQ/resources/ip_setup"
|
|
55
|
-
require_relative "DhanHQ/resources/kill_switch"
|
|
56
|
-
require_relative "DhanHQ/resources/trader_control"
|
|
57
|
-
require_relative "DhanHQ/resources/profile"
|
|
58
|
-
require_relative "DhanHQ/resources/expired_options_data"
|
|
59
|
-
|
|
60
|
-
# Models
|
|
61
|
-
require_relative "DhanHQ/models/alert_order"
|
|
62
|
-
require_relative "DhanHQ/models/order"
|
|
63
|
-
require_relative "DhanHQ/models/funds"
|
|
64
|
-
require_relative "DhanHQ/models/option_chain"
|
|
65
|
-
require_relative "DhanHQ/models/forever_order"
|
|
66
|
-
require_relative "DhanHQ/models/super_order"
|
|
67
|
-
require_relative "DhanHQ/models/historical_data"
|
|
68
|
-
require_relative "DhanHQ/models/market_feed"
|
|
69
|
-
require_relative "DhanHQ/models/instrument"
|
|
70
|
-
require_relative "DhanHQ/models/position"
|
|
71
|
-
require_relative "DhanHQ/models/holding"
|
|
72
|
-
require_relative "DhanHQ/models/ledger_entry"
|
|
73
|
-
require_relative "DhanHQ/models/trade"
|
|
74
|
-
require_relative "DhanHQ/models/margin"
|
|
75
|
-
require_relative "DhanHQ/models/kill_switch"
|
|
76
|
-
require_relative "DhanHQ/models/profile"
|
|
77
|
-
require_relative "DhanHQ/models/order_update"
|
|
78
|
-
require_relative "DhanHQ/models/expired_options_data"
|
|
79
|
-
|
|
80
|
-
require_relative "DhanHQ/constants"
|
|
81
|
-
require_relative "DhanHQ/ws"
|
|
82
|
-
require_relative "DhanHQ/ws/singleton_lock"
|
|
83
|
-
require_relative "ta"
|
|
84
|
-
require_relative "dhanhq/analysis/multi_timeframe_analyzer"
|
|
85
|
-
require_relative "dhanhq/analysis/helpers/bias_aggregator"
|
|
86
|
-
require_relative "dhanhq/analysis/helpers/moneyness_helper"
|
|
87
|
-
require_relative "dhanhq/contracts/options_buying_advisor_contract"
|
|
88
|
-
require_relative "dhanhq/analysis/options_buying_advisor"
|
|
17
|
+
require_relative "DhanHQ/core/base_resource"
|
|
89
18
|
|
|
90
19
|
# The top-level module for the DhanHQ client library.
|
|
91
20
|
#
|
|
92
21
|
# Provides configuration management for setting credentials and API-related settings.
|
|
93
22
|
module DhanHQ
|
|
23
|
+
LOADER = Zeitwerk::Loader.new
|
|
24
|
+
LOADER.tag = "dhanhq"
|
|
25
|
+
LOADER.inflector.inflect(
|
|
26
|
+
"api_helper" => "APIHelper",
|
|
27
|
+
"auth_api" => "AuthAPI",
|
|
28
|
+
"base_api" => "BaseAPI",
|
|
29
|
+
"ip_setup" => "IPSetup",
|
|
30
|
+
"json_loader" => "JSONLoader",
|
|
31
|
+
"ws" => "WS"
|
|
32
|
+
)
|
|
33
|
+
LOADER.push_dir(File.join(__dir__, "DhanHQ"), namespace: self)
|
|
34
|
+
LOADER.push_dir(File.join(__dir__, "dhanhq"), namespace: self)
|
|
35
|
+
LOADER.collapse(File.join(__dir__, "DhanHQ", "core"))
|
|
36
|
+
LOADER.collapse(File.join(__dir__, "DhanHQ", "helpers"))
|
|
37
|
+
LOADER.collapse(File.join(__dir__, "dhanhq", "analysis", "helpers"))
|
|
38
|
+
LOADER.ignore(
|
|
39
|
+
File.join(__dir__, "DhanHQ", "errors.rb"),
|
|
40
|
+
File.join(__dir__, "DhanHQ", "version.rb")
|
|
41
|
+
)
|
|
42
|
+
LOADER.setup
|
|
43
|
+
|
|
94
44
|
class Error < StandardError; end
|
|
95
45
|
|
|
96
46
|
class << self
|
|
@@ -131,7 +81,7 @@ module DhanHQ
|
|
|
131
81
|
|
|
132
82
|
# Configures the DhanHQ client using environment variables.
|
|
133
83
|
#
|
|
134
|
-
# When credentials are injected via `
|
|
84
|
+
# When credentials are injected via `DHAN_ACCESS_TOKEN` and `DHAN_CLIENT_ID` this helper
|
|
135
85
|
# can be used to initialise a configuration without a block.
|
|
136
86
|
#
|
|
137
87
|
# @example
|
|
@@ -140,8 +90,8 @@ module DhanHQ
|
|
|
140
90
|
# @return [void]
|
|
141
91
|
def configure_with_env
|
|
142
92
|
self.configuration ||= Configuration.new
|
|
143
|
-
configuration.access_token = ENV.fetch("
|
|
144
|
-
configuration.client_id = ENV.fetch("
|
|
93
|
+
configuration.access_token = ENV.fetch("DHAN_ACCESS_TOKEN", nil)
|
|
94
|
+
configuration.client_id = ENV.fetch("DHAN_CLIENT_ID", nil)
|
|
145
95
|
configuration.base_url = ENV.fetch("DHAN_BASE_URL", BASE_URL)
|
|
146
96
|
configuration.ws_version = ENV.fetch("DHAN_WS_VERSION", configuration.ws_version || 2).to_i
|
|
147
97
|
configuration.ws_order_url = ENV.fetch("DHAN_WS_ORDER_URL", configuration.ws_order_url)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: DhanHQ
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shubham Taywade
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-02-
|
|
11
|
+
date: 2026-02-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -150,6 +150,34 @@ dependencies:
|
|
|
150
150
|
- - ">="
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
152
|
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: rotp
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :runtime
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: zeitwerk
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :runtime
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
153
181
|
description: DhanHQ is a simple CLI for DhanHQ API.
|
|
154
182
|
email:
|
|
155
183
|
- shubhamtaywade82@gmail.com
|
|
@@ -204,8 +232,10 @@ files:
|
|
|
204
232
|
- examples/trading_fields_example.rb
|
|
205
233
|
- exe/DhanHQ
|
|
206
234
|
- lib/DhanHQ/auth.rb
|
|
235
|
+
- lib/DhanHQ/auth/token_generator.rb
|
|
236
|
+
- lib/DhanHQ/auth/token_manager.rb
|
|
237
|
+
- lib/DhanHQ/auth/token_renewal.rb
|
|
207
238
|
- lib/DhanHQ/client.rb
|
|
208
|
-
- lib/DhanHQ/config.rb
|
|
209
239
|
- lib/DhanHQ/configuration.rb
|
|
210
240
|
- lib/DhanHQ/constants.rb
|
|
211
241
|
- lib/DhanHQ/contracts/alert_order_contract.rb
|
|
@@ -220,7 +250,10 @@ files:
|
|
|
220
250
|
- lib/DhanHQ/contracts/place_order_contract.rb
|
|
221
251
|
- lib/DhanHQ/contracts/position_conversion_contract.rb
|
|
222
252
|
- lib/DhanHQ/contracts/slice_order_contract.rb
|
|
253
|
+
- lib/DhanHQ/contracts/trade_by_order_id_contract.rb
|
|
223
254
|
- lib/DhanHQ/contracts/trade_contract.rb
|
|
255
|
+
- lib/DhanHQ/contracts/trade_history_contract.rb
|
|
256
|
+
- lib/DhanHQ/core/auth_api.rb
|
|
224
257
|
- lib/DhanHQ/core/base_api.rb
|
|
225
258
|
- lib/DhanHQ/core/base_model.rb
|
|
226
259
|
- lib/DhanHQ/core/base_resource.rb
|
|
@@ -252,6 +285,7 @@ files:
|
|
|
252
285
|
- lib/DhanHQ/models/position.rb
|
|
253
286
|
- lib/DhanHQ/models/profile.rb
|
|
254
287
|
- lib/DhanHQ/models/super_order.rb
|
|
288
|
+
- lib/DhanHQ/models/token_response.rb
|
|
255
289
|
- lib/DhanHQ/models/trade.rb
|
|
256
290
|
- lib/DhanHQ/rate_limiter.rb
|
|
257
291
|
- lib/DhanHQ/requests/optionchain/nifty.json
|
data/lib/DhanHQ/config.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "logger"
|
|
4
|
-
|
|
5
|
-
# DhanHQ Ruby SDK for trading and market data
|
|
6
|
-
module DhanHQ
|
|
7
|
-
class << self
|
|
8
|
-
# keep whatever you already have; add these if missing:
|
|
9
|
-
attr_accessor :client_id, :access_token, :base_url, :ws_version
|
|
10
|
-
|
|
11
|
-
# default logger so calls like DhanHQ.logger&.info never explode
|
|
12
|
-
def logger
|
|
13
|
-
@logger ||= Logger.new($stdout, level: Logger::INFO)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
attr_writer :logger
|
|
17
|
-
|
|
18
|
-
# same API style as your README
|
|
19
|
-
def configure
|
|
20
|
-
yield self
|
|
21
|
-
# ensure a logger is present even if user didn’t set one
|
|
22
|
-
self.logger ||= Logger.new($stdout, level: Logger::INFO)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# if you support env bootstrap
|
|
26
|
-
def configure_with_env
|
|
27
|
-
self.client_id = ENV.fetch("CLIENT_ID", nil)
|
|
28
|
-
self.access_token = ENV.fetch("ACCESS_TOKEN", nil)
|
|
29
|
-
self.base_url = ENV.fetch("DHAN_BASE_URL", "https://api.dhan.co/v2")
|
|
30
|
-
self.ws_version = ENV.fetch("DHAN_WS_VERSION", 2).to_i
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|