DhanHQ 2.1.3 → 2.1.6

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +185 -0
  4. data/CHANGELOG.md +31 -0
  5. data/GUIDE.md +173 -31
  6. data/README.md +437 -133
  7. data/README1.md +267 -26
  8. data/docs/live_order_updates.md +319 -0
  9. data/docs/rails_integration.md +1 -1
  10. data/docs/rails_websocket_integration.md +847 -0
  11. data/docs/standalone_ruby_websocket_integration.md +1588 -0
  12. data/docs/technical_analysis.md +1 -0
  13. data/docs/websocket_integration.md +871 -0
  14. data/examples/comprehensive_websocket_examples.rb +148 -0
  15. data/examples/instrument_finder_test.rb +195 -0
  16. data/examples/live_order_updates.rb +118 -0
  17. data/examples/market_depth_example.rb +144 -0
  18. data/examples/market_feed_example.rb +81 -0
  19. data/examples/order_update_example.rb +105 -0
  20. data/examples/trading_fields_example.rb +215 -0
  21. data/lib/DhanHQ/config.rb +1 -0
  22. data/lib/DhanHQ/configuration.rb +16 -1
  23. data/lib/DhanHQ/contracts/expired_options_data_contract.rb +103 -0
  24. data/lib/DhanHQ/contracts/modify_order_contract.rb +1 -0
  25. data/lib/DhanHQ/contracts/option_chain_contract.rb +11 -1
  26. data/lib/DhanHQ/contracts/trade_contract.rb +70 -0
  27. data/lib/DhanHQ/errors.rb +2 -0
  28. data/lib/DhanHQ/models/expired_options_data.rb +331 -0
  29. data/lib/DhanHQ/models/instrument.rb +96 -2
  30. data/lib/DhanHQ/models/option_chain.rb +2 -0
  31. data/lib/DhanHQ/models/order_update.rb +235 -0
  32. data/lib/DhanHQ/models/trade.rb +118 -31
  33. data/lib/DhanHQ/rate_limiter.rb +4 -2
  34. data/lib/DhanHQ/resources/expired_options_data.rb +22 -0
  35. data/lib/DhanHQ/version.rb +1 -1
  36. data/lib/DhanHQ/ws/base_connection.rb +249 -0
  37. data/lib/DhanHQ/ws/client.rb +1 -1
  38. data/lib/DhanHQ/ws/connection.rb +3 -3
  39. data/lib/DhanHQ/ws/decoder.rb +3 -3
  40. data/lib/DhanHQ/ws/market_depth/client.rb +376 -0
  41. data/lib/DhanHQ/ws/market_depth/decoder.rb +131 -0
  42. data/lib/DhanHQ/ws/market_depth.rb +74 -0
  43. data/lib/DhanHQ/ws/orders/client.rb +177 -10
  44. data/lib/DhanHQ/ws/orders/connection.rb +41 -83
  45. data/lib/DhanHQ/ws/orders.rb +31 -2
  46. data/lib/DhanHQ/ws/registry.rb +1 -0
  47. data/lib/DhanHQ/ws/segments.rb +21 -5
  48. data/lib/DhanHQ/ws/sub_state.rb +1 -1
  49. data/lib/DhanHQ/ws.rb +3 -2
  50. data/lib/{DhanHQ.rb → dhan_hq.rb} +5 -0
  51. data/lib/dhanhq/analysis/helpers/bias_aggregator.rb +18 -18
  52. data/lib/dhanhq/analysis/helpers/moneyness_helper.rb +1 -0
  53. data/lib/dhanhq/analysis/multi_timeframe_analyzer.rb +2 -0
  54. data/lib/dhanhq/analysis/options_buying_advisor.rb +4 -3
  55. data/lib/dhanhq/contracts/options_buying_advisor_contract.rb +1 -0
  56. data/lib/ta/candles.rb +1 -0
  57. data/lib/ta/fetcher.rb +1 -0
  58. data/lib/ta/indicators.rb +2 -1
  59. data/lib/ta/market_calendar.rb +4 -3
  60. data/lib/ta/technical_analysis.rb +3 -2
  61. metadata +38 -4
  62. data/lib/DhanHQ/ws/errors.rb +0 -0
  63. /data/lib/DhanHQ/contracts/{modify_order_contract copy.rb → modify_order_contract_copy.rb} +0 -0
data/lib/ta/fetcher.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "date"
4
4
 
5
5
  module TA
6
+ # Historical data fetching with windowing and throttling
6
7
  class Fetcher
7
8
  def initialize(throttle_seconds: 3.0, max_retries: 3)
8
9
  @throttle_seconds = throttle_seconds.to_f
data/lib/ta/indicators.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TA
4
+ # Technical indicator calculations with fallback implementations
4
5
  module Indicators
5
6
  module_function
6
7
 
@@ -9,7 +10,7 @@ module TA
9
10
 
10
11
  k = 2.0 / (period + 1)
11
12
  series.each_with_index.reduce(nil) do |ema_prev, (v, i)|
12
- i == 0 ? v.to_f : (v.to_f * k) + ((ema_prev || v.to_f) * (1 - k))
13
+ i.zero? ? v.to_f : (v.to_f * k) + ((ema_prev || v.to_f) * (1 - k))
13
14
  end
14
15
  end
15
16
 
@@ -3,6 +3,7 @@
3
3
  require "date"
4
4
 
5
5
  module TA
6
+ # Market calendar utilities for trading day calculations
6
7
  module MarketCalendar
7
8
  MARKET_HOLIDAYS = [
8
9
  Date.new(2025, 8, 15),
@@ -35,12 +36,12 @@ module TA
35
36
  trading_day?(Date.today) ? Date.today : last_trading_day(from: Date.today)
36
37
  end
37
38
 
38
- def self.trading_days_ago(date, n)
39
- raise ArgumentError, "n must be >= 0" if n.to_i.negative?
39
+ def self.trading_days_ago(date, days)
40
+ raise ArgumentError, "days must be >= 0" if days.to_i.negative?
40
41
 
41
42
  d = trading_day?(date) ? date : today_or_last_trading_day
42
43
  count = 0
43
- while count < n
44
+ while count < days
44
45
  d = prev_trading_day(from: d)
45
46
  count += 1
46
47
  end
@@ -16,13 +16,14 @@ rescue LoadError => e
16
16
  warn "technical-analysis not available: #{e.message}"
17
17
  end
18
18
 
19
- require "DhanHQ"
19
+ require "dhan_hq"
20
20
  require_relative "market_calendar"
21
21
  require_relative "candles"
22
22
  require_relative "indicators"
23
23
  require_relative "fetcher"
24
24
 
25
25
  module TA
26
+ # Main technical analysis orchestrator for multi-timeframe indicator computation
26
27
  class TechnicalAnalysis
27
28
  DEFAULTS = {
28
29
  rsi_period: 14,
@@ -122,7 +123,7 @@ module TA
122
123
  end
123
124
 
124
125
  def normalize_from_date(from_date, to_date, days_back)
125
- if (from_date.nil? || from_date.to_s.strip.empty?) && days_back && days_back.to_i.positive?
126
+ if (from_date.nil? || from_date.to_s.strip.empty?) && days_back&.to_i&.positive?
126
127
  to_d = Date.parse(to_date)
127
128
  n_back = [days_back.to_i - 1, 0].max
128
129
  return MarketCalendar.trading_days_ago(to_d, n_back).strftime("%Y-%m-%d")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DhanHQ
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shubham Taywade
@@ -65,6 +65,20 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: csv
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
68
82
  - !ruby/object:Gem::Dependency
69
83
  name: dry-validation
70
84
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +159,7 @@ extra_rdoc_files: []
145
159
  files:
146
160
  - ".rspec"
147
161
  - ".rubocop.yml"
162
+ - ".rubocop_todo.yml"
148
163
  - CHANGELOG.md
149
164
  - CODE_OF_CONDUCT.md
150
165
  - GUIDE.md
@@ -161,25 +176,37 @@ files:
161
176
  - config/initializers/order_update_hub.rb
162
177
  - diagram.html
163
178
  - diagram.md
179
+ - docs/live_order_updates.md
164
180
  - docs/rails_integration.md
181
+ - docs/rails_websocket_integration.md
182
+ - docs/standalone_ruby_websocket_integration.md
165
183
  - docs/technical_analysis.md
184
+ - docs/websocket_integration.md
185
+ - examples/comprehensive_websocket_examples.rb
186
+ - examples/instrument_finder_test.rb
187
+ - examples/live_order_updates.rb
188
+ - examples/market_depth_example.rb
189
+ - examples/market_feed_example.rb
190
+ - examples/order_update_example.rb
191
+ - examples/trading_fields_example.rb
166
192
  - exe/DhanHQ
167
- - lib/DhanHQ.rb
168
193
  - lib/DhanHQ/client.rb
169
194
  - lib/DhanHQ/config.rb
170
195
  - lib/DhanHQ/configuration.rb
171
196
  - lib/DhanHQ/constants.rb
172
197
  - lib/DhanHQ/contracts/base_contract.rb
198
+ - lib/DhanHQ/contracts/expired_options_data_contract.rb
173
199
  - lib/DhanHQ/contracts/historical_data_contract.rb
174
200
  - lib/DhanHQ/contracts/instrument_list_contract.rb
175
201
  - lib/DhanHQ/contracts/margin_calculator_contract.rb
176
- - lib/DhanHQ/contracts/modify_order_contract copy.rb
177
202
  - lib/DhanHQ/contracts/modify_order_contract.rb
203
+ - lib/DhanHQ/contracts/modify_order_contract_copy.rb
178
204
  - lib/DhanHQ/contracts/option_chain_contract.rb
179
205
  - lib/DhanHQ/contracts/order_contract.rb
180
206
  - lib/DhanHQ/contracts/place_order_contract.rb
181
207
  - lib/DhanHQ/contracts/position_conversion_contract.rb
182
208
  - lib/DhanHQ/contracts/slice_order_contract.rb
209
+ - lib/DhanHQ/contracts/trade_contract.rb
183
210
  - lib/DhanHQ/core/base_api.rb
184
211
  - lib/DhanHQ/core/base_model.rb
185
212
  - lib/DhanHQ/core/base_resource.rb
@@ -194,6 +221,7 @@ files:
194
221
  - lib/DhanHQ/helpers/validation_helper.rb
195
222
  - lib/DhanHQ/json_loader.rb
196
223
  - lib/DhanHQ/models/edis.rb
224
+ - lib/DhanHQ/models/expired_options_data.rb
197
225
  - lib/DhanHQ/models/forever_order.rb
198
226
  - lib/DhanHQ/models/funds.rb
199
227
  - lib/DhanHQ/models/historical_data.rb
@@ -205,6 +233,7 @@ files:
205
233
  - lib/DhanHQ/models/market_feed.rb
206
234
  - lib/DhanHQ/models/option_chain.rb
207
235
  - lib/DhanHQ/models/order.rb
236
+ - lib/DhanHQ/models/order_update.rb
208
237
  - lib/DhanHQ/models/position.rb
209
238
  - lib/DhanHQ/models/profile.rb
210
239
  - lib/DhanHQ/models/super_order.rb
@@ -214,6 +243,7 @@ files:
214
243
  - lib/DhanHQ/requests/optionchain/nifty_expiries.json
215
244
  - lib/DhanHQ/requests/orders/create.json
216
245
  - lib/DhanHQ/resources/edis.rb
246
+ - lib/DhanHQ/resources/expired_options_data.rb
217
247
  - lib/DhanHQ/resources/forever_orders.rb
218
248
  - lib/DhanHQ/resources/funds.rb
219
249
  - lib/DhanHQ/resources/historical_data.rb
@@ -231,11 +261,14 @@ files:
231
261
  - lib/DhanHQ/resources/trades.rb
232
262
  - lib/DhanHQ/version.rb
233
263
  - lib/DhanHQ/ws.rb
264
+ - lib/DhanHQ/ws/base_connection.rb
234
265
  - lib/DhanHQ/ws/client.rb
235
266
  - lib/DhanHQ/ws/cmd_bus.rb
236
267
  - lib/DhanHQ/ws/connection.rb
237
268
  - lib/DhanHQ/ws/decoder.rb
238
- - lib/DhanHQ/ws/errors.rb
269
+ - lib/DhanHQ/ws/market_depth.rb
270
+ - lib/DhanHQ/ws/market_depth/client.rb
271
+ - lib/DhanHQ/ws/market_depth/decoder.rb
239
272
  - lib/DhanHQ/ws/orders.rb
240
273
  - lib/DhanHQ/ws/orders/client.rb
241
274
  - lib/DhanHQ/ws/orders/connection.rb
@@ -255,6 +288,7 @@ files:
255
288
  - lib/DhanHQ/ws/singleton_lock.rb
256
289
  - lib/DhanHQ/ws/sub_state.rb
257
290
  - lib/DhanHQ/ws/websocket_packet_parser.rb
291
+ - lib/dhan_hq.rb
258
292
  - lib/dhanhq/analysis/helpers/bias_aggregator.rb
259
293
  - lib/dhanhq/analysis/helpers/moneyness_helper.rb
260
294
  - lib/dhanhq/analysis/multi_timeframe_analyzer.rb
File without changes