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.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/Gemfile +2 -3
- data/Gemfile.lock +52 -67
- data/README.md +8 -60
- data/VERSION +1 -1
- data/api.gemspec +3 -10
- data/bin/console +38 -39
- data/bin/console.yml +2 -2
- data/changelog.md +0 -25
- data/example/README.md +76 -0
- data/example/account_info +54 -0
- data/example/account_positions +30 -0
- data/example/account_summary +88 -0
- data/example/cancel_orders +74 -0
- data/example/fa_accounts +25 -0
- data/example/fundamental_data +40 -0
- data/example/historic_data_cli +186 -0
- data/example/list_orders +45 -0
- data/example/portfolio_csv +81 -0
- data/example/scanner_data +62 -0
- data/example/template +19 -0
- data/example/tick_data +28 -0
- data/lib/extensions/class-extensions.rb +87 -0
- data/lib/ib/base.rb +1 -7
- data/lib/ib/base_properties.rb +12 -30
- data/lib/ib/connection.rb +269 -418
- data/lib/ib/constants.rb +22 -31
- data/lib/ib/errors.rb +1 -9
- data/lib/ib/logger.rb +26 -0
- data/lib/ib/messages/abstract_message.rb +43 -10
- data/lib/ib/messages/incoming/abstract_message.rb +98 -98
- data/lib/ib/messages/incoming/account_value.rb +78 -0
- data/lib/ib/messages/incoming/alert.rb +4 -4
- data/lib/ib/messages/incoming/contract_data.rb +29 -32
- data/lib/ib/messages/incoming/execution_data.rb +3 -3
- data/lib/ib/messages/incoming/historical_data.rb +33 -14
- data/lib/ib/messages/incoming/{market_depth.rb → market_depths.rb} +10 -0
- data/lib/ib/messages/incoming/next_valid_id.rb +0 -1
- data/lib/ib/messages/incoming/open_order.rb +201 -214
- data/lib/ib/messages/incoming/order_status.rb +1 -1
- data/lib/ib/messages/incoming/portfolio_value.rb +58 -27
- data/lib/ib/messages/incoming/scanner_data.rb +1 -1
- data/lib/ib/messages/incoming/ticks.rb +268 -0
- data/lib/ib/messages/incoming.rb +95 -136
- data/lib/ib/messages/outgoing/abstract_message.rb +22 -18
- data/lib/ib/messages/outgoing/{request_account_summary.rb → account_requests.rb} +40 -7
- data/lib/ib/messages/outgoing/{bar_request_message.rb → bar_requests.rb} +16 -13
- data/lib/ib/messages/outgoing/place_order.rb +198 -138
- data/lib/ib/messages/outgoing/{request_market_data.rb → request_marketdata.rb} +29 -32
- data/lib/ib/messages/outgoing/request_tick_data.rb +21 -0
- data/lib/ib/messages/outgoing.rb +160 -133
- data/lib/ib/messages.rb +7 -47
- data/lib/ib/model.rb +4 -0
- data/lib/ib/models.rb +14 -0
- data/lib/{server_versions.rb → ib/server_versions.rb} +9 -40
- data/lib/ib/socket.rb +147 -45
- data/lib/ib/support.rb +158 -240
- data/lib/ib/version.rb +1 -1
- data/lib/ib-api.rb +5 -42
- data/lib/models/ib/account.rb +85 -0
- data/{models → lib/models}/ib/account_value.rb +5 -5
- data/{models → lib/models}/ib/bag.rb +7 -7
- data/{models → lib/models}/ib/bar.rb +2 -2
- data/{models → lib/models}/ib/combo_leg.rb +4 -26
- data/lib/models/ib/condition.rb +245 -0
- data/{models → lib/models}/ib/contract.rb +170 -166
- data/{models → lib/models}/ib/contract_detail.rb +15 -25
- data/{models → lib/models}/ib/execution.rb +1 -1
- data/{models → lib/models}/ib/forex.rb +2 -1
- data/lib/models/ib/future.rb +15 -0
- data/{models → lib/models}/ib/index.rb +3 -2
- data/lib/models/ib/option.rb +78 -0
- data/lib/models/ib/option_detail.rb +55 -0
- data/{models → lib/models}/ib/order.rb +165 -366
- data/{models → lib/models}/ib/order_state.rb +22 -25
- data/lib/models/ib/portfolio_value.rb +64 -0
- data/lib/models/ib/stock.rb +16 -0
- data/{models → lib/models}/ib/underlying.rb +5 -3
- data/lib/models/ib/vertical.rb +96 -0
- data/lib/requires.rb +12 -0
- metadata +64 -188
- data/CLAUDE.md +0 -131
- data/LLM_GUIDE.md +0 -388
- data/bin/simple +0 -91
- data/conditions/ib/execution_condition.rb +0 -31
- data/conditions/ib/margin_condition.rb +0 -28
- data/conditions/ib/order_condition.rb +0 -29
- data/conditions/ib/percent_change_condition.rb +0 -34
- data/conditions/ib/price_condition.rb +0 -44
- data/conditions/ib/time_condition.rb +0 -42
- data/conditions/ib/volume_condition.rb +0 -36
- data/lib/class_extensions.rb +0 -167
- data/lib/ib/contract.rb +0 -30
- data/lib/ib/messages/incoming/abstract_tick.rb +0 -25
- data/lib/ib/messages/incoming/account_message.rb +0 -26
- data/lib/ib/messages/incoming/contract_message.rb +0 -13
- data/lib/ib/messages/incoming/histogram_data.rb +0 -30
- data/lib/ib/messages/incoming/historical_data_update.rb +0 -50
- data/lib/ib/messages/incoming/managed_accounts.rb +0 -21
- data/lib/ib/messages/incoming/market_depth_l2.rb +0 -15
- data/lib/ib/messages/incoming/position_data.rb +0 -21
- data/lib/ib/messages/incoming/positions_multi.rb +0 -15
- data/lib/ib/messages/incoming/receive_fa.rb +0 -30
- data/lib/ib/messages/incoming/tick_by_tick.rb +0 -77
- data/lib/ib/messages/incoming/tick_efp.rb +0 -18
- data/lib/ib/messages/incoming/tick_generic.rb +0 -12
- data/lib/ib/messages/incoming/tick_option.rb +0 -60
- data/lib/ib/messages/incoming/tick_price.rb +0 -60
- data/lib/ib/messages/incoming/tick_size.rb +0 -55
- data/lib/ib/messages/incoming/tick_string.rb +0 -13
- data/lib/ib/messages/outgoing/new-place-order.rb +0 -193
- data/lib/ib/messages/outgoing/old-place-order.rb +0 -147
- data/lib/ib/messages/outgoing/request_historical_data.rb +0 -182
- data/lib/ib/messages/outgoing/request_market_depth.rb +0 -57
- data/lib/ib/messages/outgoing/request_real_time_bars.rb +0 -48
- data/lib/ib/messages/outgoing/request_scanner_subscription.rb +0 -73
- data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +0 -21
- data/lib/ib/order_condition.rb +0 -26
- data/lib/ib/plugins.rb +0 -27
- data/lib/ib/prepare_data.rb +0 -61
- data/lib/ib/raw_message_parser.rb +0 -99
- data/lib/support/array_function.rb +0 -28
- data/lib/support/logging.rb +0 -45
- data/models/ib/account.rb +0 -72
- data/models/ib/future.rb +0 -64
- data/models/ib/option.rb +0 -149
- data/models/ib/option_detail.rb +0 -84
- data/models/ib/portfolio_value.rb +0 -86
- data/models/ib/spread.rb +0 -176
- data/models/ib/stock.rb +0 -25
- data/plugins/ib/advanced-account.rb +0 -442
- data/plugins/ib/alerts/base-alert.rb +0 -125
- data/plugins/ib/alerts/gateway-alerts.rb +0 -15
- data/plugins/ib/alerts/order-alerts.rb +0 -73
- data/plugins/ib/auto-adjust.rb +0 -0
- data/plugins/ib/connection-tools.rb +0 -122
- data/plugins/ib/eod.rb +0 -326
- data/plugins/ib/greeks.rb +0 -102
- data/plugins/ib/managed-accounts.rb +0 -274
- data/plugins/ib/market-price.rb +0 -150
- data/plugins/ib/option-chain.rb +0 -167
- data/plugins/ib/order-flow.rb +0 -157
- data/plugins/ib/order-prototypes/abstract.rb +0 -67
- data/plugins/ib/order-prototypes/adaptive.rb +0 -40
- data/plugins/ib/order-prototypes/all-in-one.rb +0 -46
- data/plugins/ib/order-prototypes/combo.rb +0 -46
- data/plugins/ib/order-prototypes/forex.rb +0 -40
- data/plugins/ib/order-prototypes/limit.rb +0 -193
- data/plugins/ib/order-prototypes/market.rb +0 -116
- data/plugins/ib/order-prototypes/pegged.rb +0 -169
- data/plugins/ib/order-prototypes/premarket.rb +0 -31
- data/plugins/ib/order-prototypes/stop.rb +0 -202
- data/plugins/ib/order-prototypes/volatility.rb +0 -39
- data/plugins/ib/order-prototypes.rb +0 -118
- data/plugins/ib/probability-of-expiring.rb +0 -109
- data/plugins/ib/process-orders.rb +0 -155
- data/plugins/ib/roll.rb +0 -86
- data/plugins/ib/spread-prototypes/butterfly.rb +0 -77
- data/plugins/ib/spread-prototypes/calendar.rb +0 -97
- data/plugins/ib/spread-prototypes/stock-spread.rb +0 -56
- data/plugins/ib/spread-prototypes/straddle.rb +0 -70
- data/plugins/ib/spread-prototypes/strangle.rb +0 -93
- data/plugins/ib/spread-prototypes/vertical.rb +0 -83
- data/plugins/ib/spread-prototypes.rb +0 -70
- data/plugins/ib/symbols/abstract.rb +0 -136
- data/plugins/ib/symbols/bonds.rb +0 -28
- data/plugins/ib/symbols/cfd.rb +0 -19
- data/plugins/ib/symbols/combo.rb +0 -46
- data/plugins/ib/symbols/commodity.rb +0 -17
- data/plugins/ib/symbols/forex.rb +0 -41
- data/plugins/ib/symbols/futures.rb +0 -127
- data/plugins/ib/symbols/index.rb +0 -43
- data/plugins/ib/symbols/options.rb +0 -99
- data/plugins/ib/symbols/stocks.rb +0 -44
- data/plugins/ib/symbols/version.rb +0 -5
- data/plugins/ib/symbols.rb +0 -118
- data/plugins/ib/verify.rb +0 -226
- data/symbols/w20.yml +0 -210
- data/t.txt +0 -20
- data/update.md +0 -71
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
|
|
3
|
-
class PercentChangeCondition < OrderCondition
|
|
4
|
-
using IB::Support # refine Array-method for decoding of IB-Messages
|
|
5
|
-
prop :percent_change
|
|
6
|
-
include BaseProperties
|
|
7
|
-
|
|
8
|
-
def condition_type
|
|
9
|
-
7
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.make buffer
|
|
13
|
-
m = self.new conjunction_connection: buffer.read_string,
|
|
14
|
-
operator: buffer.read_int,
|
|
15
|
-
percent_change: buffer.read_decimal
|
|
16
|
-
|
|
17
|
-
the_contract = IB::Contract.new con_id: buffer.read_int, exchange: buffer.read_string
|
|
18
|
-
m.contract = the_contract
|
|
19
|
-
m
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def serialize
|
|
23
|
-
super << self[:operator] << percent_change << serialize_contract_by_con_id
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
# dsl: PercentChangeCondition.fabricate some_contract, ">=", "5%"
|
|
27
|
-
def self.fabricate contract, operator, change
|
|
28
|
-
error "Condition Operator has to be \">=\" or \"<=\" " unless ["<=", ">="].include? operator
|
|
29
|
-
self.new operator: operator,
|
|
30
|
-
percent_change: change.to_i,
|
|
31
|
-
contract: verify_contract_if_necessary( contract )
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end # module
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class PriceCondition < OrderCondition
|
|
5
|
-
using IB::Support # refine Array-method for decoding of IB-Messages
|
|
6
|
-
include BaseProperties
|
|
7
|
-
prop :price,
|
|
8
|
-
:trigger_method # see /models/ib/order.rb# 51 ff and /lib/ib/constants # 210 ff
|
|
9
|
-
|
|
10
|
-
def default_attributes
|
|
11
|
-
super.merge( :trigger_method => :default )
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def condition_type
|
|
15
|
-
1
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def self.make buffer
|
|
19
|
-
m= self.new conjunction_connection: buffer.read_string,
|
|
20
|
-
operator: buffer.read_int,
|
|
21
|
-
price: buffer.read_decimal
|
|
22
|
-
|
|
23
|
-
the_contract = IB::Contract.new con_id: buffer.read_int, exchange: buffer.read_string
|
|
24
|
-
m.contract = the_contract
|
|
25
|
-
m.trigger_method = buffer.read_int
|
|
26
|
-
m
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def serialize
|
|
31
|
-
super << self[:operator] << price << serialize_contract_by_con_id << self[:trigger_method]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# dsl: PriceCondition.fabricate some_contract, ">=", 500
|
|
35
|
-
def self.fabricate contract, operator, price
|
|
36
|
-
error "Condition Operator has to be \">=\" or \"<=\" " unless ["<=", ">="].include? operator
|
|
37
|
-
self.new operator: operator,
|
|
38
|
-
price: price.to_i,
|
|
39
|
-
contract: verify_contract_if_necessary( contract )
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end # module
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class TimeCondition < OrderCondition
|
|
5
|
-
using IB::Support # refine Array-method for decoding of IB-Messages
|
|
6
|
-
include BaseProperties
|
|
7
|
-
prop :time
|
|
8
|
-
|
|
9
|
-
def condition_type
|
|
10
|
-
3
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.make buffer
|
|
14
|
-
self.new conjunction_connection: buffer.read_string,
|
|
15
|
-
operator: buffer.read_int,
|
|
16
|
-
time: buffer.read_parse_date
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def serialize
|
|
20
|
-
t = self[:time]
|
|
21
|
-
if t.is_a?(String) && t =~ /^\d{8}\z/ # expiry-format yyymmmdd
|
|
22
|
-
self.time = DateTime.new t[0..3],t[4..5],t[-2..-1]
|
|
23
|
-
end
|
|
24
|
-
serialized_time = case self[:time] # explicity formatting of time-object
|
|
25
|
-
when String
|
|
26
|
-
self[:time]
|
|
27
|
-
when DateTime
|
|
28
|
-
self[:time].gmtime.strftime("%Y%m%d %H:%M:%S %Z")
|
|
29
|
-
when Date, Time
|
|
30
|
-
self[:time].strftime("%Y%m%d %H:%M:%S")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
super << self[:operator] << serialized_time
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.fabricate operator, time
|
|
37
|
-
self.new operator: operator,
|
|
38
|
-
time: time
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end # module
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
class VolumeCondition < OrderCondition
|
|
3
|
-
using IB::Support # refine Array-method for decoding of IB-Messages
|
|
4
|
-
include BaseProperties
|
|
5
|
-
|
|
6
|
-
prop :volume
|
|
7
|
-
|
|
8
|
-
def condition_type
|
|
9
|
-
6
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.make buffer
|
|
13
|
-
m = self.new conjunction_connection: buffer.read_string,
|
|
14
|
-
operator: buffer.read_int,
|
|
15
|
-
volumne: buffer.read_int
|
|
16
|
-
|
|
17
|
-
the_contract = IB::Contract.new con_id: buffer.read_int, exchange: buffer.read_string
|
|
18
|
-
m.contract = the_contract
|
|
19
|
-
m
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def serialize
|
|
23
|
-
|
|
24
|
-
super << self[:operator] << volume << serialize_contract_by.con_id
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# dsl: VolumeCondition.fabricate some_contract, ">=", 50000
|
|
28
|
-
def self.fabricate contract, operator, volume
|
|
29
|
-
error "Condition Operator has to be \">=\" or \"<=\" " unless ["<=", ">="].include? operator
|
|
30
|
-
self.new operator: operator,
|
|
31
|
-
volume: volume,
|
|
32
|
-
contract: verify_contract_if_necessary( contract )
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end # module
|
data/lib/class_extensions.rb
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# Include the method `to_bool` to some basic classes
|
|
2
|
-
#
|
|
3
|
-
# Prepare the output of arrays via Terminal::Table
|
|
4
|
-
#
|
|
5
|
-
# Define the method `count_duplicates` for Arrays
|
|
6
|
-
#
|
|
7
|
-
require 'date'
|
|
8
|
-
|
|
9
|
-
module ClassExtensions
|
|
10
|
-
module Array
|
|
11
|
-
module DuplicatesCounter
|
|
12
|
-
def count_duplicates
|
|
13
|
-
self.each_with_object(Hash.new(0)) { |element, counter| counter[element] += 1 }.sort_by{|k,v| -v}.to_h
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
module TablePresenter
|
|
18
|
-
def as_table(&b)
|
|
19
|
-
the_table_header = first.table_header(&b)
|
|
20
|
-
the_table_rows = map &:table_row
|
|
21
|
-
Terminal::Table.new headings: the_table_header, rows: the_table_rows , style: { border: :unicode }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
module Date
|
|
27
|
-
# Render datetime in IB format (zero padded "yyyymmdd 12:00:00")
|
|
28
|
-
|
|
29
|
-
def to_ib timezone = 'UTC'
|
|
30
|
-
t = to_time + 12 * 60 * 60 # convert to time (noon)
|
|
31
|
-
s= "#{t.year}#{sprintf("%02d", t.month)}#{sprintf("%02d", t.day)}"
|
|
32
|
-
|
|
33
|
-
if timezone == 'UTC'
|
|
34
|
-
s + "-#{sprintf("%02d", t.hour)}:#{sprintf("%02d", t.min)}:#{sprintf("%02d", t.sec)}"
|
|
35
|
-
else
|
|
36
|
-
s + " #{sprintf("%02d", t.hour)}:#{sprintf("%02d", t.min)}:#{sprintf("%02d", t.sec)} #{timezone}"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
module Time
|
|
43
|
-
# Render datetime in IB format (zero padded "yyyymmdd HH:mm:ss")
|
|
44
|
-
# Without specifying the timezone utc is used
|
|
45
|
-
|
|
46
|
-
def to_ib timezone = 'UTC'
|
|
47
|
-
s= "#{year}#{sprintf("%02d", month)}#{sprintf("%02d", day)}"
|
|
48
|
-
if timezone == 'UTC'
|
|
49
|
-
unless utc?
|
|
50
|
-
self.clone.utc.to_ib
|
|
51
|
-
else
|
|
52
|
-
s + "-#{sprintf("%02d", hour)}:#{sprintf("%02d", min)}:#{sprintf("%02d", sec)}"
|
|
53
|
-
end
|
|
54
|
-
else
|
|
55
|
-
s + " #{sprintf("%02d", hour)}:#{sprintf("%02d", min)}:#{sprintf("%02d", sec)} #{timezone}"
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
module Numeric
|
|
61
|
-
# Conversion 0/1 into true/false
|
|
62
|
-
module Bool
|
|
63
|
-
def to_bool
|
|
64
|
-
self == 0 ? false : true
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
module Extensions
|
|
68
|
-
def blank?
|
|
69
|
-
false
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
module BoolClass
|
|
75
|
-
# Conversion 0/1 into true/false
|
|
76
|
-
module Bool
|
|
77
|
-
def to_bool
|
|
78
|
-
self
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
module Extensions
|
|
82
|
-
def blank?
|
|
83
|
-
to_bool
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
module String
|
|
88
|
-
|
|
89
|
-
module Extensions
|
|
90
|
-
def blank?
|
|
91
|
-
size > 0
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
module Bool
|
|
95
|
-
def to_bool
|
|
96
|
-
case self.chomp.upcase
|
|
97
|
-
when 'TRUE', 'T', '1'
|
|
98
|
-
true
|
|
99
|
-
when 'FALSE', 'F', '0', '', Float::MAX
|
|
100
|
-
false
|
|
101
|
-
else
|
|
102
|
-
error "Unable to convert #{self} to bool"
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
module Symbol
|
|
108
|
-
module Float
|
|
109
|
-
def to_f
|
|
110
|
-
0
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
module Extensions
|
|
114
|
-
def blank?
|
|
115
|
-
false
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
module Sort
|
|
120
|
-
# ActiveModel serialization depends on this method
|
|
121
|
-
def <=> other
|
|
122
|
-
to_s <=> other.to_s
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
module Object
|
|
127
|
-
# We still need to pass on nil, meaning: no value
|
|
128
|
-
def to_sup
|
|
129
|
-
self.to_s.upcase unless self.nil?
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
Array.include ClassExtensions::Array::DuplicatesCounter
|
|
136
|
-
Array.include ClassExtensions::Array::TablePresenter
|
|
137
|
-
FalseClass.include ClassExtensions::BoolClass::Bool
|
|
138
|
-
FalseClass.include ClassExtensions::BoolClass::Extensions
|
|
139
|
-
Date.include ClassExtensions::Date
|
|
140
|
-
NilClass.include ClassExtensions::BoolClass::Bool
|
|
141
|
-
NilClass.include ClassExtensions::BoolClass::Extensions
|
|
142
|
-
Numeric.include ClassExtensions::Numeric::Bool
|
|
143
|
-
Numeric.include ClassExtensions::Numeric::Extensions
|
|
144
|
-
Object.include ClassExtensions::Object
|
|
145
|
-
String.include ClassExtensions::String::Bool
|
|
146
|
-
String.include ClassExtensions::String::Extensions
|
|
147
|
-
Symbol.include ClassExtensions::Symbol::Float
|
|
148
|
-
Symbol.include ClassExtensions::Symbol::Sort
|
|
149
|
-
Symbol.include ClassExtensions::Symbol::Extensions
|
|
150
|
-
Time.include ClassExtensions::Time
|
|
151
|
-
TrueClass.include ClassExtensions::BoolClass::Bool
|
|
152
|
-
TrueClass.include ClassExtensions::BoolClass::Extensions
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
### Patching Object#error in ib/errors
|
|
162
|
-
# def error message, type=:standard
|
|
163
|
-
|
|
164
|
-
### Patching Object#log, #default_logger= in ib/logger
|
|
165
|
-
# def default_logger
|
|
166
|
-
# def default_logger= logger
|
|
167
|
-
# def log *args
|
data/lib/ib/contract.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
|
|
3
|
-
# Here we reopen IB::Contract and implenent the dynamic build facility
|
|
4
|
-
# This file is required after zeitwerk processed the basic includes.
|
|
5
|
-
#
|
|
6
|
-
class Contract
|
|
7
|
-
# Contract subclasses representing specialized security types.
|
|
8
|
-
using IB::Support
|
|
9
|
-
|
|
10
|
-
Subclasses = Hash.new(Contract)
|
|
11
|
-
Subclasses[:bag] = IB::Bag
|
|
12
|
-
Subclasses[:option] = IB::Option
|
|
13
|
-
Subclasses[:futures_option] = IB::FutureOption
|
|
14
|
-
Subclasses[:future] = IB::Future
|
|
15
|
-
Subclasses[:stock] = IB::Stock
|
|
16
|
-
Subclasses[:forex] = IB::Forex
|
|
17
|
-
Subclasses[:index] = IB::Index
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# This builds an appropriate Contract subclass based on its type
|
|
21
|
-
#
|
|
22
|
-
# the method is also used to copy Contract.values to new instances
|
|
23
|
-
def self.build opts = {}
|
|
24
|
-
subclass =( VALUES[:sec_type][opts[:sec_type]] || opts['sec_type'] || opts[:sec_type]).to_sym
|
|
25
|
-
Contract::Subclasses[subclass].new opts
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end # class Contract
|
|
30
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
|
|
5
|
-
PositionData =
|
|
6
|
-
def_message( [61,3] , ContractMessage,
|
|
7
|
-
[:account, :string],
|
|
8
|
-
[:contract, :contract], # read standard-contract
|
|
9
|
-
# [ con_id, symbol,. sec_type, expiry, strike, right, multiplier,
|
|
10
|
-
# primary_exchange, currency, local_symbol, trading_class ]
|
|
11
|
-
[:position, :decimal], # changed from int after Server Vers. MIN_SERVER_VER_FRACTIONAL_POSITIONS
|
|
12
|
-
[:price, :decimal]
|
|
13
|
-
) do
|
|
14
|
-
# def to_human
|
|
15
|
-
"<PositionValue: #{account} -> #{contract.to_human} ( Amount #{position}) : Market-Price #{price} >"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end # module Incoming
|
|
20
|
-
end # module Messages
|
|
21
|
-
end # module IB
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
PositionsMulti = def_message( 71, ContractMessage,
|
|
7
|
-
[ :request_id, :int ],
|
|
8
|
-
[ :account, :string ],
|
|
9
|
-
[:contract, :contract], # read standard-contract
|
|
10
|
-
[ :position, :decimal], # changed from int after Server Vers. MIN_SERVER_VER_FRACTIONAL_POSITIONS
|
|
11
|
-
[ :average_cost, :decimal],
|
|
12
|
-
[ :model_code, :string ])
|
|
13
|
-
end # module Incoming
|
|
14
|
-
end # module Messages
|
|
15
|
-
end # module IB
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
ReceiveFA =
|
|
10
|
-
def_message 16, [:type, :int], # type of Financial Advisor configuration data
|
|
11
|
-
# being received from TWS. Valid values include:
|
|
12
|
-
# 1 = GROUPS, 2 = PROFILE, 3 = ACCOUNT ALIASES
|
|
13
|
-
[:xml, :xml] # XML string with requested FA configuration information.
|
|
14
|
-
|
|
15
|
-
class ReceiveFA
|
|
16
|
-
def accounts
|
|
17
|
-
if( a= xml[:ListOfAccountAliases][:AccountAlias]).is_a? Array
|
|
18
|
-
a.map{|x| Account.new x }
|
|
19
|
-
elsif a.is_a? Hash ## only one account (soley financial advisor)
|
|
20
|
-
[ Account.new( a ) ]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def to_human
|
|
25
|
-
"<FA: #{accounts.map(&:to_human).join(" - ")}>"
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
TickByTick = def_message [99, 0], [:ticker_id, :int ],
|
|
7
|
-
[ :tick_type, :int],
|
|
8
|
-
[ :time, :int_date ]
|
|
9
|
-
|
|
10
|
-
## error messages: (10189) "Failed to request tick-by-tick data:Historical data request pacing violation"
|
|
11
|
-
#
|
|
12
|
-
class TickByTick
|
|
13
|
-
using IB::Support # extended Array-Class from abstract_message
|
|
14
|
-
def resolve_mask
|
|
15
|
-
@data[:mask].present? ? [ @data[:mask] & 1 , @data[:mask] & 2 ] : []
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def load
|
|
19
|
-
super
|
|
20
|
-
case @data[:tick_type ]
|
|
21
|
-
when 0
|
|
22
|
-
# do nothing
|
|
23
|
-
when 1, 2 # Last, AllLast
|
|
24
|
-
load_map [ :price, :decimal ] ,
|
|
25
|
-
[ :size, :int ] ,
|
|
26
|
-
[ :mask, :int ] ,
|
|
27
|
-
[ :exchange, :string ],
|
|
28
|
-
[ :special_conditions, :string ]
|
|
29
|
-
when 3 # bid/ask
|
|
30
|
-
load_map [ :bid_price, :decimal ],
|
|
31
|
-
[ :ask_price, :decimal],
|
|
32
|
-
[ :bid_size, :int ],
|
|
33
|
-
[ :ask_size, :int] ,
|
|
34
|
-
[ :mask, :int ]
|
|
35
|
-
when 4
|
|
36
|
-
load_map [ :mid_point, :decimal ]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
@out_labels = case @data[ :tick_tpye ]
|
|
40
|
-
when 1, 2
|
|
41
|
-
[ "PastLimit", "Unreported" ]
|
|
42
|
-
when 3
|
|
43
|
-
[ "BitPastLow", "BidPastHigh" ]
|
|
44
|
-
else
|
|
45
|
-
[]
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
def to_human
|
|
49
|
-
"< TickByTick:" + case @data[ :tick_type ]
|
|
50
|
-
when 1,2
|
|
51
|
-
"(Last) #{size} @ #{price} [#{exchange}] "
|
|
52
|
-
when 3
|
|
53
|
-
"(Bid/Ask) #{bid_size} @ #{bid_price} / #{ask_size } @ #{ask_price} "
|
|
54
|
-
when 4
|
|
55
|
-
"(Midpoint) #{mid_point } "
|
|
56
|
-
else
|
|
57
|
-
""
|
|
58
|
-
end + @out_labels.zip(resolve_mask).join( "/" )
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
[:price, :size, :mask, :exchange, :specialConditions, :bid_price, :ask_price, :bid_size, :ask_size, :mid_point].each do |name|
|
|
62
|
-
define_method name do
|
|
63
|
-
@data[name]
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
# def method_missing method, *args
|
|
67
|
-
# if @data.keys.include? method
|
|
68
|
-
# @data[method]
|
|
69
|
-
# else
|
|
70
|
-
# error "method #{method} not known"
|
|
71
|
-
# end
|
|
72
|
-
# end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|