ib-api 10.33.1

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 (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +52 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CLAUDE.md +131 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +17 -0
  8. data/Gemfile.lock +120 -0
  9. data/Guardfile +24 -0
  10. data/LICENSE +674 -0
  11. data/LLM_GUIDE.md +388 -0
  12. data/README.md +114 -0
  13. data/Rakefile +11 -0
  14. data/VERSION +1 -0
  15. data/api.gemspec +50 -0
  16. data/bin/console +96 -0
  17. data/bin/console.yml +3 -0
  18. data/bin/setup +8 -0
  19. data/bin/simple +91 -0
  20. data/changelog.md +32 -0
  21. data/conditions/ib/execution_condition.rb +31 -0
  22. data/conditions/ib/margin_condition.rb +28 -0
  23. data/conditions/ib/order_condition.rb +29 -0
  24. data/conditions/ib/percent_change_condition.rb +34 -0
  25. data/conditions/ib/price_condition.rb +44 -0
  26. data/conditions/ib/time_condition.rb +42 -0
  27. data/conditions/ib/volume_condition.rb +36 -0
  28. data/lib/class_extensions.rb +167 -0
  29. data/lib/ib/base.rb +109 -0
  30. data/lib/ib/base_properties.rb +178 -0
  31. data/lib/ib/connection.rb +573 -0
  32. data/lib/ib/constants.rb +402 -0
  33. data/lib/ib/contract.rb +30 -0
  34. data/lib/ib/errors.rb +52 -0
  35. data/lib/ib/messages/abstract_message.rb +68 -0
  36. data/lib/ib/messages/incoming/abstract_message.rb +116 -0
  37. data/lib/ib/messages/incoming/abstract_tick.rb +25 -0
  38. data/lib/ib/messages/incoming/account_message.rb +26 -0
  39. data/lib/ib/messages/incoming/alert.rb +34 -0
  40. data/lib/ib/messages/incoming/contract_data.rb +105 -0
  41. data/lib/ib/messages/incoming/contract_message.rb +13 -0
  42. data/lib/ib/messages/incoming/delta_neutral_validation.rb +23 -0
  43. data/lib/ib/messages/incoming/execution_data.rb +50 -0
  44. data/lib/ib/messages/incoming/histogram_data.rb +30 -0
  45. data/lib/ib/messages/incoming/historical_data.rb +65 -0
  46. data/lib/ib/messages/incoming/historical_data_update.rb +50 -0
  47. data/lib/ib/messages/incoming/managed_accounts.rb +21 -0
  48. data/lib/ib/messages/incoming/market_depth.rb +34 -0
  49. data/lib/ib/messages/incoming/market_depth_l2.rb +15 -0
  50. data/lib/ib/messages/incoming/next_valid_id.rb +19 -0
  51. data/lib/ib/messages/incoming/open_order.rb +290 -0
  52. data/lib/ib/messages/incoming/order_status.rb +85 -0
  53. data/lib/ib/messages/incoming/portfolio_value.rb +47 -0
  54. data/lib/ib/messages/incoming/position_data.rb +21 -0
  55. data/lib/ib/messages/incoming/positions_multi.rb +15 -0
  56. data/lib/ib/messages/incoming/real_time_bar.rb +32 -0
  57. data/lib/ib/messages/incoming/receive_fa.rb +30 -0
  58. data/lib/ib/messages/incoming/scanner_data.rb +54 -0
  59. data/lib/ib/messages/incoming/tick_by_tick.rb +77 -0
  60. data/lib/ib/messages/incoming/tick_efp.rb +18 -0
  61. data/lib/ib/messages/incoming/tick_generic.rb +12 -0
  62. data/lib/ib/messages/incoming/tick_option.rb +60 -0
  63. data/lib/ib/messages/incoming/tick_price.rb +60 -0
  64. data/lib/ib/messages/incoming/tick_size.rb +55 -0
  65. data/lib/ib/messages/incoming/tick_string.rb +13 -0
  66. data/lib/ib/messages/incoming.rb +292 -0
  67. data/lib/ib/messages/outgoing/abstract_message.rb +84 -0
  68. data/lib/ib/messages/outgoing/bar_request_message.rb +247 -0
  69. data/lib/ib/messages/outgoing/new-place-order.rb +193 -0
  70. data/lib/ib/messages/outgoing/old-place-order.rb +147 -0
  71. data/lib/ib/messages/outgoing/place_order.rb +149 -0
  72. data/lib/ib/messages/outgoing/request_account_summary.rb +79 -0
  73. data/lib/ib/messages/outgoing/request_historical_data.rb +182 -0
  74. data/lib/ib/messages/outgoing/request_market_data.rb +102 -0
  75. data/lib/ib/messages/outgoing/request_market_depth.rb +57 -0
  76. data/lib/ib/messages/outgoing/request_real_time_bars.rb +48 -0
  77. data/lib/ib/messages/outgoing/request_scanner_subscription.rb +73 -0
  78. data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +21 -0
  79. data/lib/ib/messages/outgoing.rb +410 -0
  80. data/lib/ib/messages.rb +139 -0
  81. data/lib/ib/order_condition.rb +26 -0
  82. data/lib/ib/plugins.rb +27 -0
  83. data/lib/ib/prepare_data.rb +61 -0
  84. data/lib/ib/raw_message_parser.rb +99 -0
  85. data/lib/ib/socket.rb +83 -0
  86. data/lib/ib/support.rb +236 -0
  87. data/lib/ib/version.rb +6 -0
  88. data/lib/ib-api.rb +44 -0
  89. data/lib/server_versions.rb +145 -0
  90. data/lib/support/array_function.rb +28 -0
  91. data/lib/support/logging.rb +45 -0
  92. data/models/ib/account.rb +72 -0
  93. data/models/ib/account_value.rb +33 -0
  94. data/models/ib/bag.rb +55 -0
  95. data/models/ib/bar.rb +31 -0
  96. data/models/ib/combo_leg.rb +127 -0
  97. data/models/ib/contract.rb +411 -0
  98. data/models/ib/contract_detail.rb +118 -0
  99. data/models/ib/execution.rb +67 -0
  100. data/models/ib/forex.rb +12 -0
  101. data/models/ib/future.rb +64 -0
  102. data/models/ib/index.rb +14 -0
  103. data/models/ib/option.rb +149 -0
  104. data/models/ib/option_detail.rb +84 -0
  105. data/models/ib/order.rb +720 -0
  106. data/models/ib/order_state.rb +155 -0
  107. data/models/ib/portfolio_value.rb +86 -0
  108. data/models/ib/spread.rb +176 -0
  109. data/models/ib/stock.rb +25 -0
  110. data/models/ib/underlying.rb +32 -0
  111. data/plugins/ib/advanced-account.rb +442 -0
  112. data/plugins/ib/alerts/base-alert.rb +125 -0
  113. data/plugins/ib/alerts/gateway-alerts.rb +15 -0
  114. data/plugins/ib/alerts/order-alerts.rb +73 -0
  115. data/plugins/ib/auto-adjust.rb +0 -0
  116. data/plugins/ib/connection-tools.rb +122 -0
  117. data/plugins/ib/eod.rb +326 -0
  118. data/plugins/ib/greeks.rb +102 -0
  119. data/plugins/ib/managed-accounts.rb +274 -0
  120. data/plugins/ib/market-price.rb +150 -0
  121. data/plugins/ib/option-chain.rb +167 -0
  122. data/plugins/ib/order-flow.rb +157 -0
  123. data/plugins/ib/order-prototypes/abstract.rb +67 -0
  124. data/plugins/ib/order-prototypes/adaptive.rb +40 -0
  125. data/plugins/ib/order-prototypes/all-in-one.rb +46 -0
  126. data/plugins/ib/order-prototypes/combo.rb +46 -0
  127. data/plugins/ib/order-prototypes/forex.rb +40 -0
  128. data/plugins/ib/order-prototypes/limit.rb +193 -0
  129. data/plugins/ib/order-prototypes/market.rb +116 -0
  130. data/plugins/ib/order-prototypes/pegged.rb +169 -0
  131. data/plugins/ib/order-prototypes/premarket.rb +31 -0
  132. data/plugins/ib/order-prototypes/stop.rb +202 -0
  133. data/plugins/ib/order-prototypes/volatility.rb +39 -0
  134. data/plugins/ib/order-prototypes.rb +118 -0
  135. data/plugins/ib/probability-of-expiring.rb +109 -0
  136. data/plugins/ib/process-orders.rb +155 -0
  137. data/plugins/ib/roll.rb +86 -0
  138. data/plugins/ib/spread-prototypes/butterfly.rb +77 -0
  139. data/plugins/ib/spread-prototypes/calendar.rb +97 -0
  140. data/plugins/ib/spread-prototypes/stock-spread.rb +56 -0
  141. data/plugins/ib/spread-prototypes/straddle.rb +70 -0
  142. data/plugins/ib/spread-prototypes/strangle.rb +93 -0
  143. data/plugins/ib/spread-prototypes/vertical.rb +83 -0
  144. data/plugins/ib/spread-prototypes.rb +70 -0
  145. data/plugins/ib/symbols/abstract.rb +136 -0
  146. data/plugins/ib/symbols/bonds.rb +28 -0
  147. data/plugins/ib/symbols/cfd.rb +19 -0
  148. data/plugins/ib/symbols/combo.rb +46 -0
  149. data/plugins/ib/symbols/commodity.rb +17 -0
  150. data/plugins/ib/symbols/forex.rb +41 -0
  151. data/plugins/ib/symbols/futures.rb +127 -0
  152. data/plugins/ib/symbols/index.rb +43 -0
  153. data/plugins/ib/symbols/options.rb +99 -0
  154. data/plugins/ib/symbols/stocks.rb +44 -0
  155. data/plugins/ib/symbols/version.rb +5 -0
  156. data/plugins/ib/symbols.rb +118 -0
  157. data/plugins/ib/verify.rb +226 -0
  158. data/symbols/w20.yml +210 -0
  159. data/t.txt +20 -0
  160. data/update.md +71 -0
  161. metadata +327 -0
@@ -0,0 +1,178 @@
1
+ #require 'active_support/hash_with_indifferent_access'
2
+
3
+ module IB
4
+
5
+ # Module adds prop Macro and
6
+ module BaseProperties
7
+ extend ActiveSupport::Concern
8
+
9
+ ### Instance methods
10
+
11
+ # Default presentation
12
+ def to_human
13
+ "<#{self.class.to_s.demodulize}: " + attributes.map do |attr, value|
14
+ "#{attr}: #{value}" unless value.nil?
15
+ end.compact.sort.join(' ') + ">"
16
+ end
17
+
18
+ def table_header
19
+ [ self.class.to_s.demodulize ] + content_attributes.keys
20
+ end
21
+ def table_row
22
+ [ self.class.to_s.demodulize ] + content_attributes.values
23
+ end
24
+ # the optional block specifies a title
25
+ # i.e.
26
+ #s = Symbols::Spreads.stoxx_dez
27
+ # puts s.portfolio_value( U).as_table{ s.description[1..-2] }
28
+ #┌───────────┬─────────────────────────────────────────────┬─────┬────────┬─────────┬──────────┬────────────┬──────────┐
29
+ #│ │ Straddle ESTX50(4200.0)[Dec 2021] │ pos │ entry │ market │ value │ unrealized │ realized │
30
+ #╞═══════════╪═════════════════════════════════════════════╪═════╪════════╪═════════╪══════════╪════════════╪══════════╡
31
+ #│ U7274612 │ Option: ESTX50 20211217 put 4200.0 DTB EUR │ -4 │ 179.85 │ 169.831 │ -6793.22 │ 400.78 │ │
32
+ #│ U7274612 │ Option: ESTX50 20211217 call 4200.0 DTB EUR │ -4 │ 97.85 │ 131.438 │ -5257.51 │ -1343.51 │ │
33
+ #└───────────┴─────────────────────────────────────────────┴─────┴────────┴─────────┴──────────┴────────────┴──────────┘
34
+ #
35
+ def as_table &b
36
+ Terminal::Table.new headings: table_header(&b), rows: [table_row ], style: { border: :unicode }
37
+ end
38
+
39
+ # Comparison support
40
+ def content_attributes
41
+ #NoMethodError if a Hash is assigned to an attribute
42
+ Hash[attributes.reject do |(attr, _)|
43
+ attr.to_s =~ /(_count)\z/ ||
44
+ [:created_at, :type, :updated_at,
45
+ :id, :order_id, :contract_id].include?(attr.to_sym)
46
+ end]
47
+ end
48
+
49
+ =begin
50
+ Remove all Time-Stamps from the list of Attributes
51
+ =end
52
+ def invariant_attributes
53
+ attributes.reject{|x| x =~ /_at/}
54
+ end
55
+
56
+ # Update nil attributes from given Hash or model
57
+ def update_missing attrs
58
+ attrs = attrs.content_attributes unless attrs.kind_of?(Hash)
59
+
60
+ attrs.each { |attr, val| send "#{attr}=", val if send(attr).blank? }
61
+ self # for chaining
62
+ end
63
+
64
+ # Default Model comparison
65
+ def == other
66
+ case other
67
+ when String # Probably a Rails URI, delegate to AR::Base
68
+ super(other)
69
+ else
70
+ content_attributes.keys.inject(true) { |res, key|
71
+ res && other.respond_to?(key) && (send(key) == other.send(key)) }
72
+ end
73
+ end
74
+
75
+ ### Default attributes support
76
+
77
+ def default_attributes
78
+ {:created_at => Time.now
79
+ # :updated_at => Time.now,
80
+ }
81
+ end
82
+
83
+ def set_attribute_defaults
84
+ default_attributes.each do |key, val|
85
+ self.send("#{key}=", val) if self.send(key).nil?
86
+ # self.send("#{key}=", val) if self[key].nil? # Problems with association defaults
87
+ end
88
+ end
89
+
90
+ included do
91
+
92
+ after_initialize :set_attribute_defaults
93
+
94
+ ### Class macros
95
+
96
+ def self.prop *properties
97
+ prop_hash = properties.last.is_a?(Hash) ? properties.pop : {}
98
+
99
+ properties.each { |names| define_property names, nil }
100
+ prop_hash.each { |names, type| define_property names, type }
101
+ end
102
+
103
+ def self.define_property names, body
104
+ aliases = [names].flatten
105
+ name = aliases.shift
106
+ instance_eval do
107
+
108
+ define_property_methods name, body
109
+
110
+ aliases.each do |ali|
111
+ alias_method "#{ali}", name
112
+ alias_method "#{ali}=", "#{name}="
113
+ end
114
+ end
115
+ end
116
+
117
+ def self.define_property_methods name, body={}
118
+ #p name, body
119
+ case body
120
+ when '' # default getter and setter
121
+ define_property_methods name
122
+
123
+ when Array # [setter, getter, validators]
124
+ define_property_methods name,
125
+ :get => body[0],
126
+ :set => body[1],
127
+ :validate => body[2]
128
+
129
+ when Hash # recursion base case
130
+ getter = case # Define getter
131
+ when body[:get].respond_to?(:call)
132
+ body[:get]
133
+ when body[:get]
134
+ proc { self[name].send "to_#{body[:get]}" }
135
+ when IB::VALUES[name] # property is encoded
136
+ proc { IB::VALUES[name][self[name]] }
137
+ else
138
+ proc { self[name] }
139
+ end
140
+ define_method name, &getter if getter
141
+
142
+ setter = case # Define setter
143
+ when body[:set].respond_to?(:call)
144
+ body[:set]
145
+ when body[:set]
146
+ proc { |value| self[name] = value.send "to_#{body[:set]}" }
147
+ when CODES[name] # property is encoded
148
+ proc { |value| self[name] = CODES[name][value] || value }
149
+ else
150
+ proc { |value| self[name] = value } # p name, value;
151
+ end
152
+ define_method "#{name}=", &setter if setter
153
+
154
+ # Define validator(s)
155
+ [body[:validate]].flatten.compact.each do |validator|
156
+ case validator
157
+ when Proc
158
+ validates_each name, &validator
159
+ when Hash
160
+ validates name, validator.dup
161
+ end
162
+ end
163
+
164
+ # TODO define self[:name] accessors for :virtual and :flag properties
165
+
166
+ else # setter given
167
+ define_property_methods name, :set => body, :get => body
168
+ end
169
+ end
170
+
171
+ # Timestamps in lightweight models
172
+ # unless defined?(ActiveRecord::Base) && ancestors.include?(ActiveRecord::Base)
173
+ prop :created_at #, :updated_at
174
+ # end
175
+
176
+ end # included
177
+ end # module BaseProperties
178
+ end