ib-api 10.33.4 → 972.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.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/Gemfile +2 -3
  4. data/Gemfile.lock +52 -67
  5. data/README.md +8 -60
  6. data/VERSION +1 -1
  7. data/api.gemspec +3 -10
  8. data/bin/console +38 -39
  9. data/bin/console.yml +2 -2
  10. data/changelog.md +0 -25
  11. data/example/README.md +76 -0
  12. data/example/account_info +54 -0
  13. data/example/account_positions +30 -0
  14. data/example/account_summary +88 -0
  15. data/example/cancel_orders +74 -0
  16. data/example/fa_accounts +25 -0
  17. data/example/fundamental_data +40 -0
  18. data/example/historic_data_cli +186 -0
  19. data/example/list_orders +45 -0
  20. data/example/portfolio_csv +81 -0
  21. data/example/scanner_data +62 -0
  22. data/example/template +19 -0
  23. data/example/tick_data +28 -0
  24. data/lib/extensions/class-extensions.rb +87 -0
  25. data/lib/ib/base.rb +1 -7
  26. data/lib/ib/base_properties.rb +12 -30
  27. data/lib/ib/connection.rb +269 -418
  28. data/lib/ib/constants.rb +22 -31
  29. data/lib/ib/errors.rb +1 -9
  30. data/lib/ib/logger.rb +26 -0
  31. data/lib/ib/messages/abstract_message.rb +43 -10
  32. data/lib/ib/messages/incoming/abstract_message.rb +98 -98
  33. data/lib/ib/messages/incoming/account_value.rb +78 -0
  34. data/lib/ib/messages/incoming/alert.rb +4 -4
  35. data/lib/ib/messages/incoming/contract_data.rb +29 -32
  36. data/lib/ib/messages/incoming/execution_data.rb +3 -3
  37. data/lib/ib/messages/incoming/historical_data.rb +33 -14
  38. data/lib/ib/messages/incoming/{market_depth.rb → market_depths.rb} +10 -0
  39. data/lib/ib/messages/incoming/next_valid_id.rb +0 -1
  40. data/lib/ib/messages/incoming/open_order.rb +201 -214
  41. data/lib/ib/messages/incoming/order_status.rb +1 -1
  42. data/lib/ib/messages/incoming/portfolio_value.rb +58 -27
  43. data/lib/ib/messages/incoming/scanner_data.rb +1 -1
  44. data/lib/ib/messages/incoming/ticks.rb +268 -0
  45. data/lib/ib/messages/incoming.rb +95 -136
  46. data/lib/ib/messages/outgoing/abstract_message.rb +22 -18
  47. data/lib/ib/messages/outgoing/{request_account_summary.rb → account_requests.rb} +40 -7
  48. data/lib/ib/messages/outgoing/{bar_request_message.rb → bar_requests.rb} +16 -13
  49. data/lib/ib/messages/outgoing/place_order.rb +198 -138
  50. data/lib/ib/messages/outgoing/{request_market_data.rb → request_marketdata.rb} +29 -32
  51. data/lib/ib/messages/outgoing/request_tick_data.rb +21 -0
  52. data/lib/ib/messages/outgoing.rb +160 -133
  53. data/lib/ib/messages.rb +7 -47
  54. data/lib/ib/model.rb +4 -0
  55. data/lib/ib/models.rb +14 -0
  56. data/lib/{server_versions.rb → ib/server_versions.rb} +9 -40
  57. data/lib/ib/socket.rb +147 -45
  58. data/lib/ib/support.rb +158 -240
  59. data/lib/ib/version.rb +1 -1
  60. data/lib/ib-api.rb +5 -42
  61. data/lib/models/ib/account.rb +85 -0
  62. data/{models → lib/models}/ib/account_value.rb +5 -5
  63. data/{models → lib/models}/ib/bag.rb +7 -7
  64. data/{models → lib/models}/ib/bar.rb +2 -2
  65. data/{models → lib/models}/ib/combo_leg.rb +4 -26
  66. data/lib/models/ib/condition.rb +245 -0
  67. data/{models → lib/models}/ib/contract.rb +170 -166
  68. data/{models → lib/models}/ib/contract_detail.rb +15 -25
  69. data/{models → lib/models}/ib/execution.rb +1 -1
  70. data/{models → lib/models}/ib/forex.rb +2 -1
  71. data/lib/models/ib/future.rb +15 -0
  72. data/{models → lib/models}/ib/index.rb +3 -2
  73. data/lib/models/ib/option.rb +78 -0
  74. data/lib/models/ib/option_detail.rb +55 -0
  75. data/{models → lib/models}/ib/order.rb +165 -366
  76. data/{models → lib/models}/ib/order_state.rb +22 -25
  77. data/lib/models/ib/portfolio_value.rb +64 -0
  78. data/lib/models/ib/stock.rb +16 -0
  79. data/{models → lib/models}/ib/underlying.rb +5 -3
  80. data/lib/models/ib/vertical.rb +96 -0
  81. data/lib/requires.rb +12 -0
  82. metadata +64 -188
  83. data/CLAUDE.md +0 -131
  84. data/LLM_GUIDE.md +0 -388
  85. data/bin/simple +0 -91
  86. data/conditions/ib/execution_condition.rb +0 -31
  87. data/conditions/ib/margin_condition.rb +0 -28
  88. data/conditions/ib/order_condition.rb +0 -29
  89. data/conditions/ib/percent_change_condition.rb +0 -34
  90. data/conditions/ib/price_condition.rb +0 -44
  91. data/conditions/ib/time_condition.rb +0 -42
  92. data/conditions/ib/volume_condition.rb +0 -36
  93. data/lib/class_extensions.rb +0 -167
  94. data/lib/ib/contract.rb +0 -30
  95. data/lib/ib/messages/incoming/abstract_tick.rb +0 -25
  96. data/lib/ib/messages/incoming/account_message.rb +0 -26
  97. data/lib/ib/messages/incoming/contract_message.rb +0 -13
  98. data/lib/ib/messages/incoming/histogram_data.rb +0 -30
  99. data/lib/ib/messages/incoming/historical_data_update.rb +0 -50
  100. data/lib/ib/messages/incoming/managed_accounts.rb +0 -21
  101. data/lib/ib/messages/incoming/market_depth_l2.rb +0 -15
  102. data/lib/ib/messages/incoming/position_data.rb +0 -21
  103. data/lib/ib/messages/incoming/positions_multi.rb +0 -15
  104. data/lib/ib/messages/incoming/receive_fa.rb +0 -30
  105. data/lib/ib/messages/incoming/tick_by_tick.rb +0 -77
  106. data/lib/ib/messages/incoming/tick_efp.rb +0 -18
  107. data/lib/ib/messages/incoming/tick_generic.rb +0 -12
  108. data/lib/ib/messages/incoming/tick_option.rb +0 -60
  109. data/lib/ib/messages/incoming/tick_price.rb +0 -60
  110. data/lib/ib/messages/incoming/tick_size.rb +0 -55
  111. data/lib/ib/messages/incoming/tick_string.rb +0 -13
  112. data/lib/ib/messages/outgoing/new-place-order.rb +0 -193
  113. data/lib/ib/messages/outgoing/old-place-order.rb +0 -147
  114. data/lib/ib/messages/outgoing/request_historical_data.rb +0 -182
  115. data/lib/ib/messages/outgoing/request_market_depth.rb +0 -57
  116. data/lib/ib/messages/outgoing/request_real_time_bars.rb +0 -48
  117. data/lib/ib/messages/outgoing/request_scanner_subscription.rb +0 -73
  118. data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +0 -21
  119. data/lib/ib/order_condition.rb +0 -26
  120. data/lib/ib/plugins.rb +0 -27
  121. data/lib/ib/prepare_data.rb +0 -61
  122. data/lib/ib/raw_message_parser.rb +0 -99
  123. data/lib/support/array_function.rb +0 -28
  124. data/lib/support/logging.rb +0 -45
  125. data/models/ib/account.rb +0 -72
  126. data/models/ib/future.rb +0 -64
  127. data/models/ib/option.rb +0 -149
  128. data/models/ib/option_detail.rb +0 -84
  129. data/models/ib/portfolio_value.rb +0 -86
  130. data/models/ib/spread.rb +0 -176
  131. data/models/ib/stock.rb +0 -25
  132. data/plugins/ib/advanced-account.rb +0 -442
  133. data/plugins/ib/alerts/base-alert.rb +0 -125
  134. data/plugins/ib/alerts/gateway-alerts.rb +0 -15
  135. data/plugins/ib/alerts/order-alerts.rb +0 -73
  136. data/plugins/ib/auto-adjust.rb +0 -0
  137. data/plugins/ib/connection-tools.rb +0 -122
  138. data/plugins/ib/eod.rb +0 -326
  139. data/plugins/ib/greeks.rb +0 -102
  140. data/plugins/ib/managed-accounts.rb +0 -274
  141. data/plugins/ib/market-price.rb +0 -150
  142. data/plugins/ib/option-chain.rb +0 -167
  143. data/plugins/ib/order-flow.rb +0 -157
  144. data/plugins/ib/order-prototypes/abstract.rb +0 -67
  145. data/plugins/ib/order-prototypes/adaptive.rb +0 -40
  146. data/plugins/ib/order-prototypes/all-in-one.rb +0 -46
  147. data/plugins/ib/order-prototypes/combo.rb +0 -46
  148. data/plugins/ib/order-prototypes/forex.rb +0 -40
  149. data/plugins/ib/order-prototypes/limit.rb +0 -193
  150. data/plugins/ib/order-prototypes/market.rb +0 -116
  151. data/plugins/ib/order-prototypes/pegged.rb +0 -169
  152. data/plugins/ib/order-prototypes/premarket.rb +0 -31
  153. data/plugins/ib/order-prototypes/stop.rb +0 -202
  154. data/plugins/ib/order-prototypes/volatility.rb +0 -39
  155. data/plugins/ib/order-prototypes.rb +0 -118
  156. data/plugins/ib/probability-of-expiring.rb +0 -109
  157. data/plugins/ib/process-orders.rb +0 -155
  158. data/plugins/ib/roll.rb +0 -86
  159. data/plugins/ib/spread-prototypes/butterfly.rb +0 -77
  160. data/plugins/ib/spread-prototypes/calendar.rb +0 -97
  161. data/plugins/ib/spread-prototypes/stock-spread.rb +0 -56
  162. data/plugins/ib/spread-prototypes/straddle.rb +0 -70
  163. data/plugins/ib/spread-prototypes/strangle.rb +0 -93
  164. data/plugins/ib/spread-prototypes/vertical.rb +0 -83
  165. data/plugins/ib/spread-prototypes.rb +0 -70
  166. data/plugins/ib/symbols/abstract.rb +0 -136
  167. data/plugins/ib/symbols/bonds.rb +0 -28
  168. data/plugins/ib/symbols/cfd.rb +0 -19
  169. data/plugins/ib/symbols/combo.rb +0 -46
  170. data/plugins/ib/symbols/commodity.rb +0 -17
  171. data/plugins/ib/symbols/forex.rb +0 -41
  172. data/plugins/ib/symbols/futures.rb +0 -127
  173. data/plugins/ib/symbols/index.rb +0 -43
  174. data/plugins/ib/symbols/options.rb +0 -99
  175. data/plugins/ib/symbols/stocks.rb +0 -44
  176. data/plugins/ib/symbols/version.rb +0 -5
  177. data/plugins/ib/symbols.rb +0 -118
  178. data/plugins/ib/verify.rb +0 -226
  179. data/symbols/w20.yml +0 -210
  180. data/t.txt +0 -20
  181. data/update.md +0 -71
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d9a4c216502efb44ea4f2623804809e053f1ba64b86f46aa36bde860a9ade25
4
- data.tar.gz: 1afd8025c476db5dd8db0aaf266888bd3ee56594a7cf530d8adc739d3095305a
3
+ metadata.gz: 542bca5318150ae448c4b7578abd64beec70e5b35760eea8abfd22c28f5da1fd
4
+ data.tar.gz: cb68b0afa4812eb224936f5269be2f6d6c825ea5f9bd21b25c1c9dfe21b70777
5
5
  SHA512:
6
- metadata.gz: 76cd2898733774d607d2e57ecb6dbf68b9e4edbc3c79f3daaa9648188c93f77157048a03709cd49c633c32cd545d318ce97c482da6cabc942a6425e833d91c2a
7
- data.tar.gz: 23046dad3ed7332c14d8a3135d5047dd2cbe5fb8b0d157fadfd3dda87131e4188366b5d361508776815ea95e8be6e8d6706e4b38121ef21d3bf2a3af5e8c2da5
6
+ metadata.gz: 96bac41a8432c7175dcba4fa38548db4af966d370fc8e12570c4cfd28f89284afb3188ad50d1131859861cc40d414515772cece8bed147093de04aaaf3e6b2c5
7
+ data.tar.gz: 57c186381a3da9eb7e2169d588ca99440c24993a41905ca9828c4490471a229d1e078739b34f58e666fffb7d4031bba0dfcae4a48e987667ce6d0d65246a66be
data/.gitignore CHANGED
@@ -1,7 +1,5 @@
1
1
  *.gem
2
2
  *.rbc
3
- *.swp
4
- *.swo
5
3
  /.config
6
4
  /coverage/
7
5
  /InstalledFiles
data/Gemfile CHANGED
@@ -5,13 +5,12 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in api.gemspec
6
6
  gemspec
7
7
 
8
- # gem 'value_semantics' # models, future plans
9
-
8
+ gem 'value_semantics' # models
9
+ gem 'ox', git: 'https://github.com/ohler55/ox.git' # xml handling used for news and flex
10
10
 
11
11
 
12
12
  gem 'rspec'
13
13
  gem 'rspec-its'
14
- gem 'rspec-given'
15
14
  gem 'rspec-collection_matchers'
16
15
  gem 'guard'
17
16
  gem 'guard-rspec'
data/Gemfile.lock CHANGED
@@ -1,47 +1,39 @@
1
+ GIT
2
+ remote: https://github.com/ohler55/ox.git
3
+ revision: 67ce6ecb45a0d1354e1f8ed9a155826ba986e21e
4
+ specs:
5
+ ox (2.13.4)
6
+
1
7
  PATH
2
8
  remote: .
3
9
  specs:
4
- ib-api (10.33.1)
10
+ ib-api (972.0)
5
11
  activemodel
6
12
  activesupport (>= 6.0)
7
- ox
8
- terminal-table
9
- workflow (~> 3.1)
10
- zeitwerk
11
13
 
12
14
  GEM
13
15
  remote: https://rubygems.org/
14
16
  specs:
15
- activemodel (7.1.3.4)
16
- activesupport (= 7.1.3.4)
17
- activesupport (7.1.3.4)
18
- base64
19
- bigdecimal
17
+ activemodel (6.0.3.4)
18
+ activesupport (= 6.0.3.4)
19
+ activesupport (6.0.3.4)
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
- connection_pool (>= 2.2.5)
22
- drb
23
- i18n (>= 1.6, < 2)
24
- minitest (>= 5.1)
25
- mutex_m
26
- tzinfo (~> 2.0)
27
- base64 (0.2.0)
28
- bigdecimal (3.1.8)
21
+ i18n (>= 0.7, < 2)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ zeitwerk (~> 2.2, >= 2.2.2)
29
25
  coderay (1.1.3)
30
- concurrent-ruby (1.3.3)
31
- connection_pool (2.4.1)
32
- diff-lcs (1.5.1)
33
- drb (2.2.1)
34
- ffi (1.17.3-x86_64-linux-gnu)
35
- formatador (1.1.0)
36
- given_core (3.8.2)
37
- sorcerer (>= 0.3.7)
38
- guard (2.18.1)
26
+ concurrent-ruby (1.1.7)
27
+ diff-lcs (1.4.4)
28
+ ffi (1.13.1)
29
+ formatador (0.2.5)
30
+ guard (2.16.2)
39
31
  formatador (>= 0.2.4)
40
32
  listen (>= 2.7, < 4.0)
41
33
  lumberjack (>= 1.0.12, < 2.0)
42
34
  nenv (~> 0.1)
43
35
  notiffany (~> 0.0)
44
- pry (>= 0.13.0)
36
+ pry (>= 0.9.12)
45
37
  shellany (~> 0.0)
46
38
  thor (>= 0.18.1)
47
39
  guard-compat (1.2.1)
@@ -49,72 +41,65 @@ GEM
49
41
  guard (~> 2.1)
50
42
  guard-compat (~> 1.1)
51
43
  rspec (>= 2.99.0, < 4.0)
52
- i18n (1.14.5)
44
+ i18n (1.8.5)
53
45
  concurrent-ruby (~> 1.0)
54
- listen (3.9.0)
46
+ listen (3.2.1)
55
47
  rb-fsevent (~> 0.10, >= 0.10.3)
56
48
  rb-inotify (~> 0.9, >= 0.9.10)
57
- lumberjack (1.2.10)
58
- method_source (1.1.0)
59
- minitest (5.24.1)
60
- mutex_m (0.2.0)
49
+ lumberjack (1.2.8)
50
+ method_source (1.0.0)
51
+ minitest (5.14.2)
61
52
  nenv (0.3.0)
62
53
  notiffany (0.1.3)
63
54
  nenv (~> 0.1)
64
55
  shellany (~> 0.0)
65
- ox (2.14.18)
66
- pry (0.14.2)
56
+ pry (0.13.1)
67
57
  coderay (~> 1.1)
68
58
  method_source (~> 1.0)
69
- rake (13.2.1)
70
- rb-fsevent (0.11.2)
71
- rb-inotify (0.11.1)
59
+ rake (13.0.1)
60
+ rb-fsevent (0.10.4)
61
+ rb-inotify (0.10.1)
72
62
  ffi (~> 1.0)
73
- rspec (3.13.0)
74
- rspec-core (~> 3.13.0)
75
- rspec-expectations (~> 3.13.0)
76
- rspec-mocks (~> 3.13.0)
77
- rspec-collection_matchers (1.2.1)
63
+ rspec (3.9.0)
64
+ rspec-core (~> 3.9.0)
65
+ rspec-expectations (~> 3.9.0)
66
+ rspec-mocks (~> 3.9.0)
67
+ rspec-collection_matchers (1.2.0)
78
68
  rspec-expectations (>= 2.99.0.beta1)
79
- rspec-core (3.13.0)
80
- rspec-support (~> 3.13.0)
81
- rspec-expectations (3.13.1)
69
+ rspec-core (3.9.3)
70
+ rspec-support (~> 3.9.3)
71
+ rspec-expectations (3.9.2)
82
72
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.13.0)
84
- rspec-given (3.8.2)
85
- given_core (= 3.8.2)
86
- rspec (>= 2.14.0)
73
+ rspec-support (~> 3.9.0)
87
74
  rspec-its (1.3.0)
88
75
  rspec-core (>= 3.0.0)
89
76
  rspec-expectations (>= 3.0.0)
90
- rspec-mocks (3.13.1)
77
+ rspec-mocks (3.9.1)
91
78
  diff-lcs (>= 1.2.0, < 2.0)
92
- rspec-support (~> 3.13.0)
93
- rspec-support (3.13.1)
79
+ rspec-support (~> 3.9.0)
80
+ rspec-support (3.9.3)
94
81
  shellany (0.0.1)
95
- sorcerer (2.0.1)
96
- terminal-table (3.0.2)
97
- unicode-display_width (>= 1.1.1, < 3)
98
- thor (1.3.1)
99
- tzinfo (2.0.6)
100
- concurrent-ruby (~> 1.0)
101
- unicode-display_width (2.5.0)
102
- workflow (3.1.1)
103
- zeitwerk (2.6.16)
82
+ thor (1.0.1)
83
+ thread_safe (0.3.6)
84
+ tzinfo (1.2.7)
85
+ thread_safe (~> 0.1)
86
+ value_semantics (3.6.0)
87
+ zeitwerk (2.4.0)
104
88
 
105
89
  PLATFORMS
106
- x86_64-linux
90
+ ruby
107
91
 
108
92
  DEPENDENCIES
109
- bundler
93
+ bundler (~> 1.17)
110
94
  guard
111
95
  guard-rspec
112
96
  ib-api!
97
+ ox!
113
98
  rake (~> 13.0)
114
99
  rspec
115
100
  rspec-collection_matchers
116
- rspec-given
117
101
  rspec-its
102
+ value_semantics
118
103
 
119
104
  BUNDLED WITH
120
- 2.4.6
105
+ 1.17.3
data/README.md CHANGED
@@ -1,39 +1,22 @@
1
1
  # ib-api
2
2
  Ruby interface to Interactive Brokers' TWS API
3
3
 
4
- Reimplementation of ib-ruby
4
+ Reimplementation of the basic functions of ib-ruby
5
5
 
6
- ---
7
- __VERSION 10__
8
-
9
- You have to switch from "require 'ib-extentions', 'ib-symbols'," etc. to "activate_plugin :name"
10
- ---
11
-
12
- **Whats new**
13
-
14
- * Zeitwerk integration.
15
- * Plugin's to ease automations
16
- ---
17
-
18
- __Documentation: [https://ib-ruby.github.io/ib-doc/](https://ib-ruby.github.io/ib-doc/)__
19
6
 
20
7
  ----
21
- `ib-api` offers a modular access to the TWS-API-Interface of Interactive Brokers.
8
+ `ib-ruby` offers a modular access to the TWS-API-Interface of Interactive Brokers.
22
9
 
23
- ----
10
+ `ib-api` provides a simple interface to low-level TWS API-calls.
24
11
 
25
- Install in the usual way
12
+ ----
26
13
 
27
- ```
28
- $ gem install ib-api
29
- ```
14
+ In its plain vanilla usage, it just exchanges messages with the TWS. The user is responsible for any further data processing.
30
15
 
31
- In its plain vanilla usage, it just exchanges messages with the TWS. Any response is stored in the `received-array`.
32
16
 
33
- It needs just a few lines of code to place an order
17
+ Even then, it needs just a few lines of code to place an order
34
18
 
35
19
  ```ruby
36
- require 'ib-api'
37
20
  # connect with default parameters
38
21
  ib = IB::Connection.new
39
22
 
@@ -56,44 +39,9 @@ puts ib.recieved[:OrderStatus].to_human
56
39
  # => ["<OrderState: Submitted #17/1528367295 from 2000 filled 0.0/100.0 at 0.0/0.0 why_held >"]
57
40
 
58
41
  ```
59
-
60
- ## Plugins
61
-
62
- **IB-API** ships with simple plugins to facilitate automations
63
-
64
- ```ruby
65
- require 'ib-api'
66
- # connect with default parameters
67
- ib = IB::Connection.new do | c |
68
- c.activate_plugin "verify"
69
- end
70
-
71
- g = IB::Stock.new symbol: 'GE'
72
- puts g.verify.first.attributes
73
- {:symbol=>"GE", :sec_type=>"STK", :last_trading_day=>"", :strike=>0.0, :right=>"", :exchange=>"SMART", :currency=>"USD", :local_symbol=>"GE", :trading_class=>"GE", :con_id=>498843743, :multiplier=>0, :primary_exchange=>"NYSE", }
74
- ```
75
-
76
- Currently implemented plugins
77
-
78
- * connection-tools: ensure that a connection is established and active
79
- * verify: get contract details from the tws
80
- * symbols: use predefined symbols
81
- * managed-accounts: fetch and organize account- and portfoliovalues
82
- * advanced-account: perform account-based previewing, opening, modifying and closing of Positions
83
- * process-orders: account-based bookkeeping of orders
84
- * auto-adjust: properly adjust the orderprice to the next valid min-tick of the contract
85
- * market-price: fetch the current market-price of a contract
86
- * eod: retrieve EOD-Data for the given contract
87
- * greeks: read current option greeks
88
- * roll: easy rolling of futures and options
89
- * option-chain: build option-chains for given strikes and expiries
90
- * spread-prototypes: create limit, stop, market, etc. orders through prototypes
91
- * probability-of-expiring: calculate the probability of expiring for the option-contract
92
-
93
-
94
42
  ## Minimal TWS-Version
95
43
 
96
- `ib-api` is tested via the _stable IB-Gateway_ (Version 10.33) and should work with any current tws-installation.
44
+ `ib-api` is tested via the _stable ib-Gateway_ (Version 9.72)
97
45
 
98
46
  ## Tests
99
47
 
@@ -110,7 +58,7 @@ You have to edit `spec/spec.yml` and replace the `:account`-Setting with your ow
110
58
 
111
59
  ## Contributing
112
60
 
113
- Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ib-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
114
62
 
115
63
  ## Code of Conduct
116
64
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 10.33.4
1
+ 972.0
data/api.gemspec CHANGED
@@ -8,12 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.version = IB::VERSION
9
9
  spec.authors = ["Hartmut Bischoff"]
10
10
  spec.email = ["topofocus@gmail.com"]
11
- spec.license = "MIT"
12
11
 
13
12
  spec.summary = %q{Ruby Implementation of the Interactive Brokers TWS API}
14
13
  spec.description = %q{Ruby Implementation of the Interactive Brokers TWS API}
15
14
  spec.homepage = "https://github.com/ib-ruby"
16
- spec.required_ruby_version = ">= 3.0"
17
15
 
18
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -37,14 +35,9 @@ Gem::Specification.new do |spec|
37
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
36
  spec.require_paths = ["lib"]
39
37
 
40
- spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "bundler", "~> 1.17"
41
39
  spec.add_development_dependency "rake", "~> 13.0"
42
40
  spec.add_development_dependency "rspec", "~> 3.0"
43
- spec.add_dependency 'activesupport', '~> 7.0'
44
- spec.add_dependency 'activemodel', '~> 7.0'
45
- spec.add_dependency 'ox', '~> 2.14'
46
- spec.add_dependency 'terminal-table', '~> 3.0'
47
- spec.add_dependency 'zeitwerk', '~> 2.6'
48
- spec.add_dependency 'workflow', '~> 3.1'
49
-
41
+ spec.add_dependency 'activesupport', '>= 6.0'
42
+ spec.add_dependency 'activemodel'
50
43
  end
data/bin/console CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- ### loads the active-orient environment
2
+ ### loads the active-orient environment
3
3
  ### and starts an interactive shell
4
4
  ###
5
5
  ### Parameter: t)ws | g)ateway (or number of port ) Default: Gateway ,
@@ -10,6 +10,8 @@
10
10
  require 'bundler/setup'
11
11
  require 'yaml'
12
12
 
13
+ require 'logger'
14
+
13
15
  require 'ib-api'
14
16
 
15
17
  class Array
@@ -17,9 +19,9 @@ class Array
17
19
  # i.e
18
20
  #
19
21
  # 2.5.0 :006 > C.received[:OpenOrder].local_id
20
- # => [16, 17, 21, 20, 19, 8, 7]
22
+ # => [16, 17, 21, 20, 19, 8, 7]
21
23
  # 2.5.0 :007 > C.received[:OpenOrder].contract.to_human
22
- # => ["<Bag: IECombo SMART USD legs: >", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: WFC USD>", "<Stock: WFC USD>"]
24
+ # => ["<Bag: IECombo SMART USD legs: >", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: WFC USD>", "<Stock: WFC USD>"]
23
25
  #
24
26
  # its included only in the console, for inspection purposes
25
27
 
@@ -31,66 +33,63 @@ class Array
31
33
  end
32
34
  end # Array
33
35
 
34
- class Object
35
- def inspect
36
- respond_to?(:to_human) ? to_human : super
37
- end
38
- end
39
36
 
40
- # read items from console.yml
41
- read_yml = -> (key) do
37
+ # read items from console.yml
38
+ read_yml = -> (key) do
42
39
  YAML::load_file( File.expand_path('../console.yml',__FILE__))[key]
43
40
  end
44
41
 
45
- puts
46
- puts ">> IB-API Interactive Console <<"
42
+
43
+ puts
44
+ puts ">> IB-Core Interactive Console <<"
47
45
  puts '-'* 45
48
- puts
46
+ puts
49
47
  puts "Namespace is IB ! "
50
48
  puts
51
49
  puts '-'* 45
50
+ include LogDev
52
51
  include IB
53
52
  require 'irb'
54
53
  client_id = ARGV[1] || read_yml[:client_id]
55
- specified_host = ARGV[0] || 'Gateway'
56
- host = case specified_host
54
+ specified_port = ARGV[0] || 'Gateway'
55
+ port = case specified_port
56
+ when Integer
57
+ specified_port # just use the number
57
58
  when /^[gG]/
58
59
  read_yml[:gateway]
59
60
  when /^[Tt]/
60
61
  read_yml[:tws]
61
- else
62
- raise "Specify target from console.yml: `g|t` instead of #{specified_host}"
63
62
  end
64
- ARGV.clear
65
63
 
66
- C = Connection.new client_id: client_id, host: host
67
- C.logger.level = Logger::WARN
68
-
69
- C.subscribe(:Alert){ |m| puts "A: "+ m.message }
70
- C.subscribe(:AccountUpdateTime){ }
64
+ ARGV.clear
65
+ logger = default_logger # Logger.new STDOUT
66
+
67
+ ## The Block takes instructions which are executed after initializing all instance-variables
68
+ ## and prior to the connection-process
69
+ ## Here we just subscribe to some events
70
+ C = Connection.new client_id: client_id, port: port do |c| # future use__ , optional_capacities: "+PACEAPI" do |c|
71
71
 
72
- C.received = true
73
- C.activate_plugin :connection_tools, :symbols, :market_price,
74
- "order-prototypes", "spread-prototypes",
75
- "advanced_account", 'process_orders'
76
- C.logger.level = Logger::INFO
77
- puts C.workflow_state
78
- C.get_account_data
79
- C.request_open_orders
80
- C.logger.level = Logger::ERROR
81
- puts "Connection established on #{host}"
72
+ c.subscribe( :ContractData, :BondContractData) { |msg| logger.info { msg.contract.to_human } }
73
+ c.subscribe( :Alert, :ContractDataEnd, :ManagedAccounts, :OrderStatus ) {| m| logger.info { m.to_human } }
74
+ c.subscribe( :PortfolioValue, :AccountValue, :OrderStatus, :OpenOrderEnd, :ExecutionData ) {| m| logger.info { m.to_human }}
75
+ # c.subscribe :ManagedAccounts do |msg|
76
+ # puts "------------------------------- Managed Accounts ----------------------------------"
77
+ # puts "Detected Accounts: #{msg.accounts.account.join(' -- ')} "
78
+ # puts
79
+ # end
82
80
 
81
+ c.subscribe( :OpenOrder){ |msg| "Open Order detected and stored: C.received[:OpenOrders] " }
82
+ c.logger.level = Logger::INFO
83
+ end
83
84
  unless C.received[:OpenOrder].blank?
84
- puts "---------------------------------------- OpenOrders -------------------------------------------"
85
- puts C.clients.map{ |c| c.orders.map &:to_human }.flatten.join("\n")
85
+ puts "------------------------------- OpenOrders ----------------------------------"
86
+ puts C.received[:OpenOrder].to_human.join "\n"
86
87
  end
87
- puts ""
88
- puts Terminal::Table.new title: 'Active Plugins',
89
- rows: C.plugins.delete_if{ |x| x =~ /\// }.sort.each_slice(4),
90
- style: { border: :unicode }
88
+ puts "Connection established on Port #{port}, client_id #{client_id} used"
91
89
  puts
92
90
  puts "----> C points to the connection-instance"
93
91
  puts
92
+ puts "some basic Messages are subscribed and accordingly displayed"
94
93
  puts '-'* 45
95
94
 
96
95
  IRB.start(__FILE__)
data/bin/console.yml CHANGED
@@ -1,3 +1,3 @@
1
- :gateway: "localhost:4002"
2
- :tws: "tws:7496"
1
+ :gateway: 4002
2
+ :tws: 7496
3
3
  :client_id: 2000
data/changelog.md CHANGED
@@ -5,28 +5,3 @@ Changelog
5
5
  |=++++ |=++++++++++++ |
6
6
  | 30.8.2020 | migrating lib-files from ib-ruby-project |
7
7
 
8
- | 28.11.2020| separating lib/model and lib/models to enable extension with
9
- ActiveRecord/Rails and OrientDB/ActiveOrient. |
10
- | | Introducing a Database-Switch in /lib/requires to omit
11
- loading of model- and messages files. This has to be done
12
- manually after assigning the database-model framework. |
13
-
14
- | 1.12.2020 | moving model/ib/spread.rb from `ib-extensions` to `ib-api`.|
15
- | 1.12.2020 | creating a dummy Contract#verify to guaranty safe operation of spreads |
16
-
17
- | | Preparation of a Gem-Release |
18
- | 23.2.2021 | Fixed retrieving of ContractDetail requests of Options with strikes < 1
19
- | | Gem Release |
20
-
21
- | 1.4.2024 | Proper monkey patching of classes through class_extensions (Prepare for Zeitwerk, V10)
22
- | 2.4.2024 | Renaming of IBSupport and IBSocket to IB::Support and IB::Socket (Prepare for Zeitwerk, V10)
23
- | 4.4.2024 | Apply Zeitwerk, V10
24
- Put `model` to the root directory (the files are then easily fetched through zeitwerk)
25
- Reorganizing Messages. One message class per file. Keeping general incoming and outgoing-files
26
- | 1.1.2025 | introducing plugins
27
- | | using a state machine to organize access to advanced featurs
28
-
29
- | 7.5.2025 | Disabled verify buffer size to enable receiving historical datastreams
30
- | | Removed contract#verify! in favour of #contract.verify
31
-
32
-
data/example/README.md ADDED
@@ -0,0 +1,76 @@
1
+ ## IB-RUBY EXAMPLES:
2
+
3
+ This folder contains sample scripts that demonstrate common ib-ruby use cases.
4
+ The scripts show you how to access account info, print real time quotes, retrieve
5
+ historic or fundamental data, request options calculations, place, list, and cancel orders.
6
+ You may also want to look into `spec/integration` directory for more scenarios,
7
+ use cases and examples of handling IB messages.
8
+
9
+ Normally you run these examples like this:
10
+
11
+ $ ruby example/list_orders
12
+
13
+ The examples are executable.
14
+ If you're on Unix-like platform, they can be called directly ( » ./{script} «)
15
+
16
+ The Examples assume a running Gateway-Application on Localhost. Please use a Demo-Account or run
17
+ the API in »read-only-mode«
18
+
19
+ ## EXAMPLE DESCRIPTION:
20
+
21
+ *account_info* - Request your account info, current positions, portfolio values and so on
22
+
23
+ $ ruby example/account_info # or cd example; ./account_info
24
+
25
+ For Financial Advisors, you need to add the managed account you want info for:
26
+
27
+ $ ruby example/account_info U123456
28
+
29
+ *cancel_orders* - Cancel either all open orders, or specific order(s), by their (local) ids. Examples:
30
+
31
+ $ ruby example/cancel_orders
32
+ $ ruby example/cancel_orders 492 495
33
+
34
+ *contract_details* - Obtain detailed descriptions for specific Stock, Option, Forex, Futures and Bond contracts.
35
+
36
+ *contract_sample details* - Define Contract samples provided by java and python API-implementations
37
+
38
+ *depth_of_market* - Receive a stream of MarketDepth change events for Stock, Forex and Future symbols.
39
+
40
+ *fa_accounts* - Get info about accounts under management (for Financial Advisors).
41
+
42
+ *flex_query* - Run a pre-defined Flex query, receive and print Flex report. Example:
43
+
44
+ $ ruby example/flex_query 12345 # Flex query id pre-defined in Account Management
45
+
46
+ *fundamental_data* - Request and print fundamental data report for a specific stock.
47
+
48
+ *historic_data* - Receive 5 days of 1-hour trade data for Stock, Forex and Future symbols.
49
+
50
+ *historic_data_cli* - CLI script for historic data downloading. It has many options, for detailed help run:
51
+
52
+ $ ruby example/historic_data_cli
53
+
54
+ *list_orders* - List all open API orders.
55
+
56
+ *market_data* - Receive a stream of trade events for multiple Forex symbols.
57
+
58
+ *option_data* - Receive a stream of underlying, price and greeks calculations for multiple Option symbols.
59
+
60
+ *place_braket_order* - Place a braket order for Stock.
61
+
62
+ *place_combo_order* - Place an Option combo order (Google butterfly).
63
+
64
+ *place_order* - Place a simple limit order to buy Stock.
65
+
66
+ *portfolio_csv* - Exports your IB portfolio in a CSV format. Usage:
67
+
68
+ $ ruby example/portfolio_csv [account] > my_portfolio.csv
69
+
70
+ *real_time_data* - Subscribe to real time data for specific symbol.
71
+
72
+ *template* - A blank example to start a new script (setting up all the dependencies).
73
+
74
+ *tick_data* - Subscribe to extended tick types for a single stock symbol.
75
+
76
+ *time_and_sales* - Print out Time&Sales format for Futures symbols.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This script connects to IB API, subscribes to account info and prints out
4
+ # messages received from IB (update every 3 minute or so)
5
+
6
+ require 'bundler/setup'
7
+ require 'ib-api'
8
+
9
+ # Only for Advisor accounts: you can provide account_code such as U666777 (otherwise the last account is used)
10
+ account_code = ARGV[0] || ''
11
+
12
+ include IB
13
+ # Connect to IB TWS
14
+ accounts = []
15
+ ib = Connection.new client_id: 1113, port: 4002 do | gw | # :port => 7497 # TWS
16
+
17
+ # Subscribe to TWS alerts/errors and account-related messages
18
+ # that TWS sends in response to account data request
19
+ gw.subscribe(:Alert) do |msg|
20
+ ## if an account is not given. but required, (Error 321 indicates this)
21
+ ## fetch data from the last account detected. (The first is most probably the Advisor-Account)
22
+ if msg.code == 321
23
+ gw.send_message :RequestAccountData, :subscribe => true, :account_code => accounts.last
24
+ else
25
+ puts msg.to_human
26
+ end
27
+ end
28
+
29
+ ## Print Account+Portfolio-Values
30
+ gw.subscribe(:AccountValue,
31
+ :PortfolioValue, :AccountUpdateTime) { |msg| puts msg.to_human }
32
+
33
+ ## Just in case: put account-names into accounts-array
34
+ gw.subscribe(:ManagedAccounts){ |msg| accounts = msg.accounts_list.split ',' }
35
+
36
+ # Set log level
37
+ gw.logger.level = Logger::FATAL # DEBUG #FATAL
38
+ end
39
+
40
+ ib.send_message :RequestAccountData, :subscribe => true, :account_code => account_code
41
+
42
+ puts "\nSubscribing to IB account data"
43
+
44
+ ## print message after recieving account-data
45
+ Thread.new do
46
+ sleep 3
47
+ puts "\n******** Press <Enter> to quit *********\n\n"
48
+ end
49
+
50
+ STDIN.gets
51
+ puts "Cancelling account data subscription.."
52
+
53
+ ib.send_message :RequestAccountData, :subscribe => false
54
+ sleep 2
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This script connects to IB API and subscribes to Position Values which are updated regulary
4
+
5
+ require 'bundler/setup'
6
+ require 'ib-api'
7
+
8
+
9
+ # connect to IB TWS.
10
+
11
+
12
+ ib = IB::Connection.new( :client_id => 1110) do | gw | #, :port => 7496 # TWS)
13
+ ## Subcribe to forseable events before the connection is completed
14
+ ## Subscribe to TWS alerts/errors
15
+ gw.subscribe(:Alert, :PositionData){ |msg| puts msg.to_human }
16
+ gw.logger.level = Logger::FATAL # DEBUG -- INFO -- WARN -- ERROR -- FATAL
17
+ end
18
+
19
+ Thread.new do
20
+ sleep 1
21
+ puts "\n******** Press <Enter> to quit *********\n\n"
22
+ end
23
+ # request the AccountSummary
24
+ ib.send_message :RequestPositions
25
+
26
+ STDIN.gets
27
+ puts "\n *** canceling Reqest ..."
28
+ ib.send_message :CancelPositions
29
+ sleep 1
30
+ puts "done."