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.
- checksums.yaml +7 -0
- data/.gitignore +52 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CLAUDE.md +131 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +120 -0
- data/Guardfile +24 -0
- data/LICENSE +674 -0
- data/LLM_GUIDE.md +388 -0
- data/README.md +114 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/api.gemspec +50 -0
- data/bin/console +96 -0
- data/bin/console.yml +3 -0
- data/bin/setup +8 -0
- data/bin/simple +91 -0
- data/changelog.md +32 -0
- data/conditions/ib/execution_condition.rb +31 -0
- data/conditions/ib/margin_condition.rb +28 -0
- data/conditions/ib/order_condition.rb +29 -0
- data/conditions/ib/percent_change_condition.rb +34 -0
- data/conditions/ib/price_condition.rb +44 -0
- data/conditions/ib/time_condition.rb +42 -0
- data/conditions/ib/volume_condition.rb +36 -0
- data/lib/class_extensions.rb +167 -0
- data/lib/ib/base.rb +109 -0
- data/lib/ib/base_properties.rb +178 -0
- data/lib/ib/connection.rb +573 -0
- data/lib/ib/constants.rb +402 -0
- data/lib/ib/contract.rb +30 -0
- data/lib/ib/errors.rb +52 -0
- data/lib/ib/messages/abstract_message.rb +68 -0
- data/lib/ib/messages/incoming/abstract_message.rb +116 -0
- data/lib/ib/messages/incoming/abstract_tick.rb +25 -0
- data/lib/ib/messages/incoming/account_message.rb +26 -0
- data/lib/ib/messages/incoming/alert.rb +34 -0
- data/lib/ib/messages/incoming/contract_data.rb +105 -0
- data/lib/ib/messages/incoming/contract_message.rb +13 -0
- data/lib/ib/messages/incoming/delta_neutral_validation.rb +23 -0
- data/lib/ib/messages/incoming/execution_data.rb +50 -0
- data/lib/ib/messages/incoming/histogram_data.rb +30 -0
- data/lib/ib/messages/incoming/historical_data.rb +65 -0
- data/lib/ib/messages/incoming/historical_data_update.rb +50 -0
- data/lib/ib/messages/incoming/managed_accounts.rb +21 -0
- data/lib/ib/messages/incoming/market_depth.rb +34 -0
- data/lib/ib/messages/incoming/market_depth_l2.rb +15 -0
- data/lib/ib/messages/incoming/next_valid_id.rb +19 -0
- data/lib/ib/messages/incoming/open_order.rb +290 -0
- data/lib/ib/messages/incoming/order_status.rb +85 -0
- data/lib/ib/messages/incoming/portfolio_value.rb +47 -0
- data/lib/ib/messages/incoming/position_data.rb +21 -0
- data/lib/ib/messages/incoming/positions_multi.rb +15 -0
- data/lib/ib/messages/incoming/real_time_bar.rb +32 -0
- data/lib/ib/messages/incoming/receive_fa.rb +30 -0
- data/lib/ib/messages/incoming/scanner_data.rb +54 -0
- data/lib/ib/messages/incoming/tick_by_tick.rb +77 -0
- data/lib/ib/messages/incoming/tick_efp.rb +18 -0
- data/lib/ib/messages/incoming/tick_generic.rb +12 -0
- data/lib/ib/messages/incoming/tick_option.rb +60 -0
- data/lib/ib/messages/incoming/tick_price.rb +60 -0
- data/lib/ib/messages/incoming/tick_size.rb +55 -0
- data/lib/ib/messages/incoming/tick_string.rb +13 -0
- data/lib/ib/messages/incoming.rb +292 -0
- data/lib/ib/messages/outgoing/abstract_message.rb +84 -0
- data/lib/ib/messages/outgoing/bar_request_message.rb +247 -0
- data/lib/ib/messages/outgoing/new-place-order.rb +193 -0
- data/lib/ib/messages/outgoing/old-place-order.rb +147 -0
- data/lib/ib/messages/outgoing/place_order.rb +149 -0
- data/lib/ib/messages/outgoing/request_account_summary.rb +79 -0
- data/lib/ib/messages/outgoing/request_historical_data.rb +182 -0
- data/lib/ib/messages/outgoing/request_market_data.rb +102 -0
- data/lib/ib/messages/outgoing/request_market_depth.rb +57 -0
- data/lib/ib/messages/outgoing/request_real_time_bars.rb +48 -0
- data/lib/ib/messages/outgoing/request_scanner_subscription.rb +73 -0
- data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +21 -0
- data/lib/ib/messages/outgoing.rb +410 -0
- data/lib/ib/messages.rb +139 -0
- data/lib/ib/order_condition.rb +26 -0
- data/lib/ib/plugins.rb +27 -0
- data/lib/ib/prepare_data.rb +61 -0
- data/lib/ib/raw_message_parser.rb +99 -0
- data/lib/ib/socket.rb +83 -0
- data/lib/ib/support.rb +236 -0
- data/lib/ib/version.rb +6 -0
- data/lib/ib-api.rb +44 -0
- data/lib/server_versions.rb +145 -0
- data/lib/support/array_function.rb +28 -0
- data/lib/support/logging.rb +45 -0
- data/models/ib/account.rb +72 -0
- data/models/ib/account_value.rb +33 -0
- data/models/ib/bag.rb +55 -0
- data/models/ib/bar.rb +31 -0
- data/models/ib/combo_leg.rb +127 -0
- data/models/ib/contract.rb +411 -0
- data/models/ib/contract_detail.rb +118 -0
- data/models/ib/execution.rb +67 -0
- data/models/ib/forex.rb +12 -0
- data/models/ib/future.rb +64 -0
- data/models/ib/index.rb +14 -0
- data/models/ib/option.rb +149 -0
- data/models/ib/option_detail.rb +84 -0
- data/models/ib/order.rb +720 -0
- data/models/ib/order_state.rb +155 -0
- data/models/ib/portfolio_value.rb +86 -0
- data/models/ib/spread.rb +176 -0
- data/models/ib/stock.rb +25 -0
- data/models/ib/underlying.rb +32 -0
- data/plugins/ib/advanced-account.rb +442 -0
- data/plugins/ib/alerts/base-alert.rb +125 -0
- data/plugins/ib/alerts/gateway-alerts.rb +15 -0
- data/plugins/ib/alerts/order-alerts.rb +73 -0
- data/plugins/ib/auto-adjust.rb +0 -0
- data/plugins/ib/connection-tools.rb +122 -0
- data/plugins/ib/eod.rb +326 -0
- data/plugins/ib/greeks.rb +102 -0
- data/plugins/ib/managed-accounts.rb +274 -0
- data/plugins/ib/market-price.rb +150 -0
- data/plugins/ib/option-chain.rb +167 -0
- data/plugins/ib/order-flow.rb +157 -0
- data/plugins/ib/order-prototypes/abstract.rb +67 -0
- data/plugins/ib/order-prototypes/adaptive.rb +40 -0
- data/plugins/ib/order-prototypes/all-in-one.rb +46 -0
- data/plugins/ib/order-prototypes/combo.rb +46 -0
- data/plugins/ib/order-prototypes/forex.rb +40 -0
- data/plugins/ib/order-prototypes/limit.rb +193 -0
- data/plugins/ib/order-prototypes/market.rb +116 -0
- data/plugins/ib/order-prototypes/pegged.rb +169 -0
- data/plugins/ib/order-prototypes/premarket.rb +31 -0
- data/plugins/ib/order-prototypes/stop.rb +202 -0
- data/plugins/ib/order-prototypes/volatility.rb +39 -0
- data/plugins/ib/order-prototypes.rb +118 -0
- data/plugins/ib/probability-of-expiring.rb +109 -0
- data/plugins/ib/process-orders.rb +155 -0
- data/plugins/ib/roll.rb +86 -0
- data/plugins/ib/spread-prototypes/butterfly.rb +77 -0
- data/plugins/ib/spread-prototypes/calendar.rb +97 -0
- data/plugins/ib/spread-prototypes/stock-spread.rb +56 -0
- data/plugins/ib/spread-prototypes/straddle.rb +70 -0
- data/plugins/ib/spread-prototypes/strangle.rb +93 -0
- data/plugins/ib/spread-prototypes/vertical.rb +83 -0
- data/plugins/ib/spread-prototypes.rb +70 -0
- data/plugins/ib/symbols/abstract.rb +136 -0
- data/plugins/ib/symbols/bonds.rb +28 -0
- data/plugins/ib/symbols/cfd.rb +19 -0
- data/plugins/ib/symbols/combo.rb +46 -0
- data/plugins/ib/symbols/commodity.rb +17 -0
- data/plugins/ib/symbols/forex.rb +41 -0
- data/plugins/ib/symbols/futures.rb +127 -0
- data/plugins/ib/symbols/index.rb +43 -0
- data/plugins/ib/symbols/options.rb +99 -0
- data/plugins/ib/symbols/stocks.rb +44 -0
- data/plugins/ib/symbols/version.rb +5 -0
- data/plugins/ib/symbols.rb +118 -0
- data/plugins/ib/verify.rb +226 -0
- data/symbols/w20.yml +210 -0
- data/t.txt +20 -0
- data/update.md +71 -0
- metadata +327 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
module IB
|
|
3
|
+
module Messages
|
|
4
|
+
module Incoming
|
|
5
|
+
extend Messages # def_message macros
|
|
6
|
+
class AbstractTick < AbstractMessage
|
|
7
|
+
# Returns Symbol with a meaningful name for received tick type
|
|
8
|
+
def type
|
|
9
|
+
TICK_TYPES[@data[:tick_type]]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_human
|
|
13
|
+
"<#{self.message_type} #{type}:" +
|
|
14
|
+
@data.map do |key, value|
|
|
15
|
+
" #{key} #{value}" unless [:version, :ticker_id, :tick_type].include?(key)
|
|
16
|
+
end.compact.join('",') + " >"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def the_data
|
|
20
|
+
@data.reject{|k,_| [:version, :ticker_id].include? k }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
extend Messages # def_message macros
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Receives previously requested FA configuration information from TWS.
|
|
9
|
+
|
|
10
|
+
class AccountMessage < AbstractMessage
|
|
11
|
+
def account_value
|
|
12
|
+
@account_value = IB::AccountValue.new @data[:account_value]
|
|
13
|
+
end
|
|
14
|
+
def account_name
|
|
15
|
+
@account_name = @data[:account]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_human
|
|
19
|
+
"<AccountValue: #{account_name}, #{account_value}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
end # module AccountValues
|
|
25
|
+
end # module Messages
|
|
26
|
+
end # module IB
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
# Called Error in Java code, but in fact this type of messages also
|
|
6
|
+
# deliver system alerts and additional (non-error) info from TWS.
|
|
7
|
+
Alert = def_message([4, 2],
|
|
8
|
+
[:error_id, :int],
|
|
9
|
+
[:code, :int],
|
|
10
|
+
[:message, :string])
|
|
11
|
+
class Alert
|
|
12
|
+
# Is it an Error message?
|
|
13
|
+
def error?
|
|
14
|
+
code < 1000
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Is it a System message?
|
|
18
|
+
def system?
|
|
19
|
+
code > 1000 && code < 2000
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Is it a Warning message?
|
|
23
|
+
def warning?
|
|
24
|
+
code > 2000
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_human
|
|
28
|
+
"TWS #{ error? ? 'Error' : system? ? 'System' : 'Warning'} #{code}: #{message}"
|
|
29
|
+
end
|
|
30
|
+
end # class Alert
|
|
31
|
+
|
|
32
|
+
end # module Incoming
|
|
33
|
+
end # module Messages
|
|
34
|
+
end # module IB
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
ContractData = ContractDetails =
|
|
6
|
+
def_message([ 10, 0 ], #, [8, 8]],
|
|
7
|
+
[:request_id, :int], ## request id
|
|
8
|
+
[:contract, :symbol, :string], ## next the major contract-fields
|
|
9
|
+
[:contract, :sec_type, :string], ## are transmitted
|
|
10
|
+
[:contract, :last_trading_day, :date], ## difference to the array.get_contract
|
|
11
|
+
[:contract, :strike, :decimal], ## method: con_id is transmitted
|
|
12
|
+
[:contract, :right, :string], ## AFTER the main fields
|
|
13
|
+
[:contract, :exchange, :string], ##
|
|
14
|
+
[:contract, :currency, :string], ## thus we have to read the fields separately
|
|
15
|
+
[:contract, :local_symbol, :string],
|
|
16
|
+
[:contract_detail, :market_name, :string], ## extended
|
|
17
|
+
[:contract, :trading_class, :string], ## new Version 8
|
|
18
|
+
[:contract, :con_id, :int],
|
|
19
|
+
[:contract_detail, :min_tick, :decimal],
|
|
20
|
+
# [:contract_detail, :md_size_multiplier, :int], # Vers 10.12 not used anymore
|
|
21
|
+
[:contract, :multiplier, :decimal], ## Crypto-option multipliers can be decimal
|
|
22
|
+
[:contract_detail, :order_types, :string],
|
|
23
|
+
[:contract_detail, :valid_exchanges, :string],
|
|
24
|
+
[:contract_detail, :price_magnifier, :int],
|
|
25
|
+
[:contract_detail, :under_con_id, :int],
|
|
26
|
+
[:contract_detail, :long_name, :string],
|
|
27
|
+
[:contract, :primary_exchange, :string],
|
|
28
|
+
[:contract_detail, :contract_month, :string],
|
|
29
|
+
[:contract_detail, :industry, :string],
|
|
30
|
+
[:contract_detail, :category, :string],
|
|
31
|
+
[:contract_detail, :subcategory, :string],
|
|
32
|
+
[:contract_detail, :time_zone, :string],
|
|
33
|
+
[:contract_detail, :trading_hours, :string],
|
|
34
|
+
[:contract_detail, :liquid_hours, :string],
|
|
35
|
+
[:contract_detail, :ev_rule, :decimal],
|
|
36
|
+
[:contract_detail, :ev_multipler, :string],
|
|
37
|
+
[:contract_detail, :sec_id_list,:hash],
|
|
38
|
+
[:contract_detail, :agg_group, :int ],
|
|
39
|
+
[:contract_detail, :under_symbol, :string ],
|
|
40
|
+
[:contract_detail, :under_sec_type, :string ],
|
|
41
|
+
[:contract_detail, :market_rule_ids, :string ],
|
|
42
|
+
[:contract_detail, :real_expiration_date, :date ],
|
|
43
|
+
[:contract_detail, :stock_type, :string ], # new Version 10.12
|
|
44
|
+
[:contract_detail, :min_size, :int ], # new Version 10.12
|
|
45
|
+
[:contract_detail, :size_increment, :int ], # new Version 10.12
|
|
46
|
+
[:contract_detail, :suggested_size_increment, :int ], # new Version 10.12
|
|
47
|
+
)
|
|
48
|
+
#
|
|
49
|
+
#
|
|
50
|
+
class ContractData
|
|
51
|
+
using IB::Support # defines tws-method for Array (socket.rb)
|
|
52
|
+
def contract
|
|
53
|
+
@contract = IB::Contract.build @data[:contract].merge(:contract_detail => contract_detail)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def contract_detail
|
|
57
|
+
@contract_detail = IB::ContractDetail.new @data[:contract_detail]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def to_human
|
|
61
|
+
"<Contract #{contract.to_human} #{contract_detail.to_human}>"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end # ContractData
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
module ContractAccessors
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
BondContractData =
|
|
71
|
+
def_message [18, [4, 6]], ContractDetails,
|
|
72
|
+
[:request_id, :int],
|
|
73
|
+
[:contract, :symbol, :string],
|
|
74
|
+
[:contract, :sec_type, :string],
|
|
75
|
+
[:contract_detail, :cusip, :string],
|
|
76
|
+
[:contract_detail, :coupon, :decimal],
|
|
77
|
+
[:contract_detail, :maturity, :string],
|
|
78
|
+
[:contract_detail, :issue_date, :string],
|
|
79
|
+
[:contract_detail, :ratings, :string],
|
|
80
|
+
[:contract_detail, :bond_type, :string],
|
|
81
|
+
[:contract_detail, :coupon_type, :string],
|
|
82
|
+
[:contract_detail, :convertible, :boolean],
|
|
83
|
+
[:contract_detail, :callable, :boolean],
|
|
84
|
+
[:contract_detail, :puttable, :boolean],
|
|
85
|
+
[:contract_detail, :desc_append, :string],
|
|
86
|
+
[:contract, :exchange, :string],
|
|
87
|
+
[:contract, :currency, :string],
|
|
88
|
+
[:contract_detail, :market_name, :string], # extended
|
|
89
|
+
[:contract_detail, :trading_class, :string],
|
|
90
|
+
[:contract, :con_id, :int],
|
|
91
|
+
[:contract_detail, :min_tick, :decimal],
|
|
92
|
+
[:contract_detail, :order_types, :string],
|
|
93
|
+
[:contract_detail, :valid_exchanges, :string],
|
|
94
|
+
[:contract_detail, :valid_next_option_date, :string],
|
|
95
|
+
[:contract_detail, :valid_next_option_type, :string],
|
|
96
|
+
[:contract_detail, :valid_next_option_partial, :string],
|
|
97
|
+
[:contract_detail, :notes, :string],
|
|
98
|
+
[:contract_detail, :long_name, :string],
|
|
99
|
+
[:contract_detail, :ev_rule, :decimal],
|
|
100
|
+
[:contract_detail, :ev_multipler, :string],
|
|
101
|
+
[:sec_id_list_count, :int]
|
|
102
|
+
|
|
103
|
+
end # module Incoming
|
|
104
|
+
end # module Messages
|
|
105
|
+
end # module IB
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
# used by PortfolioValue
|
|
6
|
+
class ContractMessage < AbstractMessage
|
|
7
|
+
def contract
|
|
8
|
+
@contract = IB::Contract.build @data[:contract]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end # module Incoming
|
|
12
|
+
end # module Messages
|
|
13
|
+
end # module IB
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
# The server sends this message upon accepting a Delta-Neutral DN RFQ
|
|
6
|
+
# - see API Reference p. 26
|
|
7
|
+
DeltaNeutralValidation = def_message 56,
|
|
8
|
+
[:request_id, :int],
|
|
9
|
+
[:underlying, :con_id, :int],
|
|
10
|
+
[:underlying, :delta, :decimal],
|
|
11
|
+
[:underlying, :price, :decimal]
|
|
12
|
+
class DeltaNeutralValidation
|
|
13
|
+
def underlying
|
|
14
|
+
@underlying = IB::Underlying.new @data[:underlying]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
alias under_comp underlying
|
|
18
|
+
|
|
19
|
+
end # DeltaNeutralValidation
|
|
20
|
+
|
|
21
|
+
end # module Incoming
|
|
22
|
+
end # module Messages
|
|
23
|
+
end # module IB
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
ExecutionData =
|
|
6
|
+
def_message [11, 0] , # [8, 9]],
|
|
7
|
+
# The reqID that was specified previously in the call to reqExecution()
|
|
8
|
+
[:request_id, :int],
|
|
9
|
+
[:execution, :local_id, :int],
|
|
10
|
+
[:contract, :contract],
|
|
11
|
+
[:execution, :exec_id, :string], # Weird format
|
|
12
|
+
[:execution, :time, :datetime],
|
|
13
|
+
[:execution, :account_name, :string],
|
|
14
|
+
[:execution, :exchange, :string],
|
|
15
|
+
[:execution, :side, :string],
|
|
16
|
+
[:execution, :quantity, :decimal],
|
|
17
|
+
[:execution, :price, :decimal],
|
|
18
|
+
[:execution, :perm_id, :int],
|
|
19
|
+
[:execution, :client_id, :int],
|
|
20
|
+
[:execution, :liquidation, :int],
|
|
21
|
+
[:execution, :cumulative_quantity, :int],
|
|
22
|
+
[:execution, :average_price, :decimal],
|
|
23
|
+
[:execution, :order_ref, :string],
|
|
24
|
+
[:execution, :ev_rule, :string],
|
|
25
|
+
[:execution, :ev_multiplier, :decimal],
|
|
26
|
+
[:execution, :model_code, :string],
|
|
27
|
+
[:execution, :last_liquidity, :int]
|
|
28
|
+
|
|
29
|
+
class ExecutionData
|
|
30
|
+
|
|
31
|
+
def load
|
|
32
|
+
simple_load
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def contract
|
|
36
|
+
@contract = IB::Contract.build @data[:contract]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def execution
|
|
40
|
+
@execution = IB::Execution.new @data[:execution]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_human
|
|
44
|
+
"<ExecutionData #{request_id}: #{contract.to_human}, #{execution}>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end # ExecutionData
|
|
48
|
+
end # module Incoming
|
|
49
|
+
end # module Messages
|
|
50
|
+
end # module IB
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
HistogramData = def_message( [89,0],
|
|
6
|
+
[:request_id, :int],
|
|
7
|
+
[ :number_of_points , :int ]) do
|
|
8
|
+
# to human
|
|
9
|
+
"<HistogramData: #{request_id}, #{number_of_points} read>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class HistogramData
|
|
13
|
+
attr_accessor :results
|
|
14
|
+
using IB::Support # extended Array-Class from abstract_message
|
|
15
|
+
|
|
16
|
+
def load
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
@results = Array.new(@data[:number_of_points]) do |_|
|
|
20
|
+
{ price: buffer.read_decimal,
|
|
21
|
+
count: buffer.read_int }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
end # module Incoming
|
|
29
|
+
end # module Messages
|
|
30
|
+
end # module IB
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
# HistoricalData contains following @data:
|
|
6
|
+
#
|
|
7
|
+
# _General_:
|
|
8
|
+
#
|
|
9
|
+
# - request_id - The ID of the request to which this is responding
|
|
10
|
+
# - count - Number of Historical data points returned (size of :results).
|
|
11
|
+
# - results - an Array of Historical Data Bars
|
|
12
|
+
# - start_date - beginning of returned Historical data period
|
|
13
|
+
# - end_date - end of returned Historical data period
|
|
14
|
+
#
|
|
15
|
+
# Each returned Bar in @data[:results] Array contains this data:
|
|
16
|
+
# - date - The date-time stamp of the start of the bar. The format is set to sec since EPOCHE
|
|
17
|
+
# in outgoing/bar_requests ReqHistoricalData.
|
|
18
|
+
# - open - The bar opening price.
|
|
19
|
+
# - high - The high price during the time covered by the bar.
|
|
20
|
+
# - low - The low price during the time covered by the bar.
|
|
21
|
+
# - close - The bar closing price.
|
|
22
|
+
# - volume - The volume during the time covered by the bar.
|
|
23
|
+
# - trades - When TRADES historical data is returned, represents number of trades
|
|
24
|
+
# that occurred during the time period the bar covers
|
|
25
|
+
# - wap - The weighted average price during the time covered by the bar.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
HistoricalData = def_message [17,0],
|
|
29
|
+
[:request_id, :int],
|
|
30
|
+
[:start_date, :datetime],
|
|
31
|
+
[:end_date, :datetime],
|
|
32
|
+
[:count, :int]
|
|
33
|
+
class HistoricalData
|
|
34
|
+
attr_accessor :results
|
|
35
|
+
using IB::Support # extended Array-Class from abstract_message
|
|
36
|
+
|
|
37
|
+
def load
|
|
38
|
+
super
|
|
39
|
+
|
|
40
|
+
@results = Array.new(@data[:count]) do |_|
|
|
41
|
+
IB::Bar.new :time => buffer.read_int_date, # conversion of epoche-time-integer to Dateime
|
|
42
|
+
# requires format_date in request to be "2"
|
|
43
|
+
# (outgoing/bar_requests # RequestHistoricalData#Encoding)
|
|
44
|
+
:open => buffer.read_float,
|
|
45
|
+
:high => buffer.read_float,
|
|
46
|
+
:low => buffer.read_float,
|
|
47
|
+
:close => buffer.read_float,
|
|
48
|
+
:volume => buffer.read_int,
|
|
49
|
+
:wap => buffer.read_float,
|
|
50
|
+
# :has_gaps => buffer.read_string, # only in ServerVersion < 124
|
|
51
|
+
:trades => buffer.read_int
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def to_human
|
|
56
|
+
"<HistoricalData: #{request_id}, #{count} items, #{start_date} to #{end_date}>"
|
|
57
|
+
end
|
|
58
|
+
end # HistoricalData
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
end # module Incoming
|
|
64
|
+
end # module Messages
|
|
65
|
+
end # module IB
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
module IB
|
|
3
|
+
module Messages
|
|
4
|
+
module Incoming
|
|
5
|
+
|
|
6
|
+
HistoricalDataUpdate = def_message [90, 0] ,
|
|
7
|
+
[:request_id, :int] ,
|
|
8
|
+
[:count, :int],
|
|
9
|
+
[:bar, :bar] # defined in support.rb
|
|
10
|
+
|
|
11
|
+
class HistoricalDataUpdate
|
|
12
|
+
attr_accessor :results
|
|
13
|
+
using IB::Support # extended Array-Class from abstract_message
|
|
14
|
+
|
|
15
|
+
def bar
|
|
16
|
+
@bar = IB::Bar.new @data[:bar]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_human
|
|
20
|
+
"<HistDataUpdate #{request_id} #{bar}>"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
#https://github.com/wizardofcrowds/ib-api/blob/3dd4851c838f61b2a6bbdc98a36b99499f90b701/lib/ib/messages/incoming/historical_data.rb HistoricalDataUpdate = def_message [90,0],
|
|
24
|
+
# [:request_id, :int],
|
|
25
|
+
# [:_, :int]
|
|
26
|
+
# # ["90", "2", "-1", "1612238280", "1.28285", "1.28275", "1.28285", "1.28275", "-1.0", "-1"]
|
|
27
|
+
# class HistoricalDataUpdate
|
|
28
|
+
# attr_accessor :results
|
|
29
|
+
# using IBSupport # extended Array-Class from abstract_message
|
|
30
|
+
#
|
|
31
|
+
# def load
|
|
32
|
+
# super
|
|
33
|
+
# # See Rust impl at https://github.com/sparkstartconsulting/IBKR-API-Rust/blob/d4e89c39a57a2b448bb912196ebc42acfb915be7/src/core/decoder.rs#L1097
|
|
34
|
+
# @results = [ IB::Bar.new(:time => buffer.read_int_date,
|
|
35
|
+
# :open => buffer.read_decimal,
|
|
36
|
+
# :close => buffer.read_decimal,
|
|
37
|
+
# :high => buffer.read_decimal,
|
|
38
|
+
# :low => buffer.read_decimal,
|
|
39
|
+
# :wap => buffer.read_decimal,
|
|
40
|
+
# :volume => buffer.read_int) ]
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# def to_human
|
|
44
|
+
# "<HistoricalDataUpdate: #{request_id} #{@results.inspect}>"
|
|
45
|
+
# end
|
|
46
|
+
#end # HistoricalDataUpdate
|
|
47
|
+
|
|
48
|
+
end # module Incoming
|
|
49
|
+
end # module Messages
|
|
50
|
+
end # module IB
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
ManagedAccounts =
|
|
7
|
+
def_message 15, [:accounts_list, :string]
|
|
8
|
+
|
|
9
|
+
class ManagedAccounts
|
|
10
|
+
def accounts
|
|
11
|
+
accounts_list.split(',').map{|a| Account.new account: a}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_human
|
|
15
|
+
"<ManagedAccounts: #{accounts.map(&:account).join(" - ")}>"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end # module Incoming
|
|
20
|
+
end # module Messages
|
|
21
|
+
end # module IB
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
MarketDepth =
|
|
6
|
+
def_message 12, [:request_id, :int],
|
|
7
|
+
[:position, :int], # The row Id of this market depth entry.
|
|
8
|
+
[:operation, :int], # How it should be applied to the market depth:
|
|
9
|
+
# 0 = insert this new order into the row identified by :position
|
|
10
|
+
# 1 = update the existing order in the row identified by :position
|
|
11
|
+
# 2 = delete the existing order at the row identified by :position
|
|
12
|
+
[:side, :int], # side of the book: 0 = ask, 1 = bid
|
|
13
|
+
[:price, :decimal],
|
|
14
|
+
[:size, :int]
|
|
15
|
+
|
|
16
|
+
class MarketDepth
|
|
17
|
+
def side
|
|
18
|
+
@data[:side] == 0 ? :ask : :bid
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def operation
|
|
22
|
+
@data[:operation] == 0 ? :insert : @data[:operation] == 1 ? :update : :delete
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_human
|
|
26
|
+
"<#{self.message_type}: #{operation} #{side} @ "+
|
|
27
|
+
"#{position} = #{price} x #{size}>"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
end # module Incoming
|
|
33
|
+
end # module Messages
|
|
34
|
+
end # module IB
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
MarketDepthL2 =
|
|
5
|
+
def_message 13, MarketDepth, # Fields descriptions - see above
|
|
6
|
+
[:request_id, :int],
|
|
7
|
+
[:position, :int],
|
|
8
|
+
[:market_maker, :string], # The exchange hosting this order.
|
|
9
|
+
[:operation, :int],
|
|
10
|
+
[:side, :int],
|
|
11
|
+
[:price, :decimal],
|
|
12
|
+
[:size, :int]
|
|
13
|
+
end # module Incoming
|
|
14
|
+
end # module Messages
|
|
15
|
+
end # module IB
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
module Messages
|
|
3
|
+
module Incoming
|
|
4
|
+
|
|
5
|
+
# This message is always sent by TWS automatically at connect.
|
|
6
|
+
# The IB::Connection class subscribes to it automatically and stores
|
|
7
|
+
# the order id in its @next_local_id attribute.
|
|
8
|
+
NextValidID = NextValidId = def_message(9, [:local_id, :int])
|
|
9
|
+
|
|
10
|
+
class NextValidId
|
|
11
|
+
using IB::Support
|
|
12
|
+
|
|
13
|
+
# Legacy accessor
|
|
14
|
+
alias order_id local_id
|
|
15
|
+
|
|
16
|
+
end # class NextValidId
|
|
17
|
+
end # module Incoming
|
|
18
|
+
end # module Messages
|
|
19
|
+
end # module IB
|