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
|
@@ -2,25 +2,22 @@ module IB
|
|
|
2
2
|
|
|
3
3
|
# OrderState represents dynamic (changeable) info about a single Order,
|
|
4
4
|
# isolating these changes and making Order essentially immutable
|
|
5
|
-
class OrderState < IB::
|
|
5
|
+
class OrderState < IB::Model
|
|
6
6
|
include BaseProperties
|
|
7
7
|
|
|
8
8
|
#p column_names
|
|
9
9
|
belongs_to :order
|
|
10
10
|
|
|
11
11
|
# Properties arriving via OpenOrder message
|
|
12
|
-
prop :
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:init_margin_before, :maint_margin_before, :equity_with_loan_before,
|
|
16
|
-
:init_margin_change, :maint_margin_change, :equity_with_loan_change,
|
|
12
|
+
prop :init_margin, # Float: The impact the order would have on your initial margin.
|
|
13
|
+
:maint_margin, # Float: The impact the order would have on your maintenance margin.
|
|
14
|
+
:equity_with_loan, # Float: The impact the order would have on your equity
|
|
17
15
|
:commission, # double: Shows the commission amount on the order.
|
|
18
16
|
:min_commission, # The possible min range of the actual order commission.
|
|
19
17
|
:max_commission, # The possible max range of the actual order commission.
|
|
20
|
-
|
|
21
18
|
:commission_currency, # String: Shows the currency of the commission.
|
|
22
19
|
:warning_text, # String: Displays a warning message if warranted.
|
|
23
|
-
|
|
20
|
+
|
|
24
21
|
:market_cap_price # messages#incomming#orderstae#vers. 11
|
|
25
22
|
|
|
26
23
|
# Properties arriving via OrderStatus message:
|
|
@@ -37,7 +34,7 @@ module IB
|
|
|
37
34
|
:parent_id, # int: The order ID of the parent (original) order, used
|
|
38
35
|
:status => :s # String: one of
|
|
39
36
|
# ApiCancelled, PreSubmitted, PendingCancel, Cancelled, Submitted, Filled,
|
|
40
|
-
#
|
|
37
|
+
# Inactive, PendingSubmit, Unknown, ApiPending,
|
|
41
38
|
#
|
|
42
39
|
# Displays the order status. Possible values include:
|
|
43
40
|
# - PendingSubmit - indicates that you have transmitted the order, but
|
|
@@ -74,8 +71,8 @@ module IB
|
|
|
74
71
|
|
|
75
72
|
def self.valid_status? the_message
|
|
76
73
|
valid_stati = %w( ApiCancelled PreSubmitted PendingCancel Cancelled Submitted Filled
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
Inactive PendingSubmit Unknown ApiPending)
|
|
75
|
+
valid_stati.include?( the_message )
|
|
79
76
|
end
|
|
80
77
|
|
|
81
78
|
## Testing Order state:
|
|
@@ -119,9 +116,9 @@ module IB
|
|
|
119
116
|
filled == other.filled &&
|
|
120
117
|
remaining == other.remaining &&
|
|
121
118
|
last_fill_price == other.last_fill_price &&
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
init_margin == other.init_margin &&
|
|
120
|
+
maint_margin == other.maint_margin &&
|
|
121
|
+
equity_with_loan == other.equity_with_loan &&
|
|
125
122
|
why_held == other.why_held &&
|
|
126
123
|
warning_text == other.warning_text &&
|
|
127
124
|
commission == other.commission
|
|
@@ -131,8 +128,8 @@ module IB
|
|
|
131
128
|
"<OrderState: #{status} ##{local_id}/#{perm_id} from #{client_id}" +
|
|
132
129
|
(filled ? " filled #{filled}/#{remaining}" : '') +
|
|
133
130
|
(last_fill_price ? " at #{last_fill_price}/#{average_fill_price}" : '') +
|
|
134
|
-
(
|
|
135
|
-
(
|
|
131
|
+
(init_margin ? " margin #{init_margin}/#{maint_margin}" : '') +
|
|
132
|
+
(equity_with_loan ? " equity #{equity_with_loan}" : '') +
|
|
136
133
|
(commission && commission > 0 ? " fee #{commission}" : "") +
|
|
137
134
|
(why_held ? " why_held #{why_held}" : '') +
|
|
138
135
|
((warning_text && warning_text != '') ? " warning #{warning_text}" : '') + ">"
|
|
@@ -140,16 +137,16 @@ module IB
|
|
|
140
137
|
|
|
141
138
|
alias to_s to_human
|
|
142
139
|
=begin
|
|
143
|
-
If an Order is submitted with the :what_if-Flag set, commission and margin are returned
|
|
140
|
+
If an Order is submitted with the :what_if-Flag set, commission and margin are returned
|
|
144
141
|
via the order_state-Object.
|
|
145
142
|
=end
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
143
|
+
def forcast
|
|
144
|
+
{ :init_margin => init_margin,
|
|
145
|
+
:maint_margin => maint_margin,
|
|
146
|
+
:equity_with_loan => equity_with_loan ,
|
|
147
|
+
:commission => commission,
|
|
148
|
+
:commission_currency=> commission_currency,
|
|
149
|
+
:warning => warning_text }
|
|
150
|
+
end
|
|
154
151
|
end # class Order
|
|
155
152
|
end # module IB
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
class PortfolioValue < IB::Model
|
|
3
|
+
include BaseProperties
|
|
4
|
+
# belongs_to :currency
|
|
5
|
+
belongs_to :account
|
|
6
|
+
belongs_to :contract
|
|
7
|
+
|
|
8
|
+
# scope :single, ->(key) { where :schluessel => key } rescue nil
|
|
9
|
+
|
|
10
|
+
prop :position,
|
|
11
|
+
:market_price,
|
|
12
|
+
:market_value,
|
|
13
|
+
:average_cost,
|
|
14
|
+
:unrealized_pnl,
|
|
15
|
+
:realized_pnl
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Order comparison
|
|
19
|
+
def == other
|
|
20
|
+
super(other) ||
|
|
21
|
+
other.is_a?(self.class) &&
|
|
22
|
+
market_price == other.market_price &&
|
|
23
|
+
average_cost == other.average_cost &&
|
|
24
|
+
position == other.position &&
|
|
25
|
+
unrealized_pnl == other.unrealized_pnl &&
|
|
26
|
+
realized_pnl == other.realized_pnl &&
|
|
27
|
+
contract == other.contract
|
|
28
|
+
end
|
|
29
|
+
def to_human
|
|
30
|
+
the_account = if account.present?
|
|
31
|
+
if account.is_a?(String)
|
|
32
|
+
account + " "
|
|
33
|
+
else
|
|
34
|
+
account.account+" "
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
""
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
"<PortfolioValue: "+
|
|
41
|
+
the_account +
|
|
42
|
+
"Pos=#{ position.to_i } @ #{market_price.to_f.round(3)};" +
|
|
43
|
+
"Value=#{market_value.to_f.round(2)};PNL=" +
|
|
44
|
+
( unrealized_pnl.to_i.zero? ? "": "#{unrealized_pnl} unrealized;") +
|
|
45
|
+
( realized_pnl.to_i.zero? ? "" : "#{realized_pnl} realized;>" ) +
|
|
46
|
+
contract.to_human
|
|
47
|
+
end
|
|
48
|
+
alias to_s to_human
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# def to_invest
|
|
52
|
+
# a=attributes
|
|
53
|
+
# a.delete "created_at"
|
|
54
|
+
# a.delete "updated_at"
|
|
55
|
+
# a.delete "id"
|
|
56
|
+
# a.delete "account_id"
|
|
57
|
+
# a.delete "currency_id"
|
|
58
|
+
# a[:currency] = currency.symbol.presence || currency.name.presence || nil unless currency.nil?
|
|
59
|
+
# a #return_value
|
|
60
|
+
#
|
|
61
|
+
#
|
|
62
|
+
# end
|
|
63
|
+
end # class
|
|
64
|
+
end # module
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative 'contract'
|
|
2
|
+
module IB
|
|
3
|
+
class Stock < IB::Contract
|
|
4
|
+
validates_format_of :sec_type, :with => /\Astock\z/,
|
|
5
|
+
:message => "should be a Stock"
|
|
6
|
+
def default_attributes
|
|
7
|
+
super.merge :sec_type => :stock, currency:'USD', exchange:'SMART'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_human
|
|
11
|
+
att = [ symbol, currency, ( exchange == 'SMART' ? nil: exchange ), (primary_exchange.present? && !primary_exchange.empty? ? primary_exchange : nil)].compact
|
|
12
|
+
"<Stock: " + att.join(" ") + ">"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module IB
|
|
2
|
+
|
|
2
3
|
# Calculated characteristics of underlying Contract (volatile)
|
|
3
|
-
class Underlying < IB::
|
|
4
|
+
class Underlying < IB::Model
|
|
4
5
|
include BaseProperties
|
|
5
6
|
|
|
6
7
|
has_one :contract
|
|
@@ -17,7 +18,7 @@ module IB
|
|
|
17
18
|
|
|
18
19
|
# Serialize under_comp parameters
|
|
19
20
|
def serialize
|
|
20
|
-
[con_id, delta, price]
|
|
21
|
+
[true, con_id, delta, price]
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
# Comparison
|
|
@@ -29,4 +30,5 @@ module IB
|
|
|
29
30
|
|
|
30
31
|
end # class Underlying
|
|
31
32
|
UnderComp = Underlying
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
end # module IB
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require_relative 'contract'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module IB
|
|
5
|
+
class Vertical < Spread
|
|
6
|
+
|
|
7
|
+
=begin
|
|
8
|
+
Macro-Class to simplify the definition of Vertical-Spreads
|
|
9
|
+
|
|
10
|
+
Initialize with
|
|
11
|
+
|
|
12
|
+
calendar = IB::Vertical.new underlying: Symbols::Index.stoxx,
|
|
13
|
+
buy: 3000, sell: 2900, right: :put
|
|
14
|
+
expiry: 201901, back: 291903
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
master = IB::Option.new symbol: :Estx50, right: :put, multiplier: 10, exchange: 'DTB', currency: 'EUR'
|
|
18
|
+
strike: 3000, expiry: 201812
|
|
19
|
+
calendar = IB::Vertical.new sell: master, buy: 3100
|
|
20
|
+
|
|
21
|
+
=end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def initialize master=nil, # provides strike, front-month, right, trading-class
|
|
26
|
+
underlying: nil,
|
|
27
|
+
right: :put,
|
|
28
|
+
expiry: IB::Symbols::Futures.next_expiry,
|
|
29
|
+
buy: 0 , # has to be specified
|
|
30
|
+
sell: 0,
|
|
31
|
+
# trading_class: nil,
|
|
32
|
+
**args # trading-class and others
|
|
33
|
+
|
|
34
|
+
master_option, side, msg = if master.present?
|
|
35
|
+
if master.is_a?(IB::Option)
|
|
36
|
+
[ master.essential,-1, nil ]
|
|
37
|
+
else
|
|
38
|
+
[ nil, 0,"First Argument is no IB::Option" ]
|
|
39
|
+
end
|
|
40
|
+
elsif buy.is_a?(IB::Option) && !sell.zero?
|
|
41
|
+
[ buy.essentail,1, nil ]
|
|
42
|
+
elsif sell.is_a?(IB::Option) && !buy.zero?
|
|
43
|
+
[ sell.essential, -1, nil ]
|
|
44
|
+
elsif underlying.present?
|
|
45
|
+
if underlying.is_a?(IB::Contract)
|
|
46
|
+
master = IB::Option.new underlying.attributes.slice( :currency, :symbol, :exchange ).merge(args)
|
|
47
|
+
master.sec_type = 'FOP' if underlying.is_a?(IB::Future)
|
|
48
|
+
master.strike, master.expiry, master.right = buy, expiry, right
|
|
49
|
+
[master, 1, buy.to_i >0 && sell.to_i >0 ? nil : "buy and sell strikes have to be specified"]
|
|
50
|
+
else
|
|
51
|
+
[nil, 0, "Underlying has to be an IB::Contract"]
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
[ nil, 0, "Required parameters: Master-Option or Underlying, buy and sell-strikes" ]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
error msg, :args, nil if msg.present?
|
|
58
|
+
master_option.trading_class = args[:trading_class] if args[:trading_class].present?
|
|
59
|
+
l=[] ; master_option.verify{|x| x.contract_detail = nil; l << x }
|
|
60
|
+
if l.empty?
|
|
61
|
+
error "Invalid Parameters. No Contract found #{master_option.to_human}"
|
|
62
|
+
elsif l.size > 2
|
|
63
|
+
Connection.logger.error "ambigous contract-specification: #{l.map(&:to_human).join(';')}"
|
|
64
|
+
available_trading_classes = l.map( &:trading_class ).uniq
|
|
65
|
+
if available_trading_classes.size >1
|
|
66
|
+
error "Refine Specification with trading_class: #{available_trading_classes.join('; ')} (details in log)"
|
|
67
|
+
else
|
|
68
|
+
error "Respecify expiry, verification reveals #{l.size} contracts (only 2 are allowed) #{master_option.to_human}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
master_option.strike = side ==1 ? sell : buy
|
|
73
|
+
master_option.verify{|x| x.contract_detail = nil; l << x }
|
|
74
|
+
error "Two legs are required, \n Verifiying the master-option exposed #{l.size} legs" unless l.size ==2
|
|
75
|
+
|
|
76
|
+
master_option.exchange ||= l.first.exchange
|
|
77
|
+
master_option.currency ||= l.first.currency
|
|
78
|
+
|
|
79
|
+
# i=0 + side = -1 --> -1 sell
|
|
80
|
+
# i=0 + side = 1 --> 1 buy
|
|
81
|
+
# i=1 + side = -1 --> 0 buy
|
|
82
|
+
# i.1 + side = 1 --> 2 sell
|
|
83
|
+
c_l = l.map.with_index{ |l,i| ComboLeg.new con_id: l.con_id, action: i+side ==2 || i+side <0 ? :sell : :buy , exchange: l.exchange, ratio: 1 }
|
|
84
|
+
|
|
85
|
+
super exchange: master_option.exchange,
|
|
86
|
+
symbol: master_option.symbol.to_s,
|
|
87
|
+
currency: master_option.currency,
|
|
88
|
+
legs: l,
|
|
89
|
+
combo_legs: c_l
|
|
90
|
+
end
|
|
91
|
+
def to_human
|
|
92
|
+
x= [ combo_legs.map(&:weight) , legs.map( &:strike )].transpose
|
|
93
|
+
"<Vertical #{symbol} #{legs.first.right}(#{x.map{|w,strike| "#{w} :#{strike} "}.join( '|+|' )} )[#{Date.parse(legs.first.last_trading_day).strftime("%b %Y")}]>"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
data/lib/requires.rb
ADDED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ib-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: '972.0'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hartmut Bischoff
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: bundler
|
|
@@ -15,14 +16,14 @@ dependencies:
|
|
|
15
16
|
requirements:
|
|
16
17
|
- - "~>"
|
|
17
18
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
19
|
+
version: '1.17'
|
|
19
20
|
type: :development
|
|
20
21
|
prerelease: false
|
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
23
|
requirements:
|
|
23
24
|
- - "~>"
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
26
|
+
version: '1.17'
|
|
26
27
|
- !ruby/object:Gem::Dependency
|
|
27
28
|
name: rake
|
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -55,86 +56,30 @@ dependencies:
|
|
|
55
56
|
name: activesupport
|
|
56
57
|
requirement: !ruby/object:Gem::Requirement
|
|
57
58
|
requirements:
|
|
58
|
-
- - "
|
|
59
|
+
- - ">="
|
|
59
60
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
61
|
+
version: '6.0'
|
|
61
62
|
type: :runtime
|
|
62
63
|
prerelease: false
|
|
63
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
65
|
requirements:
|
|
65
|
-
- - "
|
|
66
|
+
- - ">="
|
|
66
67
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '
|
|
68
|
+
version: '6.0'
|
|
68
69
|
- !ruby/object:Gem::Dependency
|
|
69
70
|
name: activemodel
|
|
70
71
|
requirement: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements:
|
|
72
|
-
- - "
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '7.0'
|
|
75
|
-
type: :runtime
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - "~>"
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '7.0'
|
|
82
|
-
- !ruby/object:Gem::Dependency
|
|
83
|
-
name: ox
|
|
84
|
-
requirement: !ruby/object:Gem::Requirement
|
|
85
|
-
requirements:
|
|
86
|
-
- - "~>"
|
|
73
|
+
- - ">="
|
|
87
74
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: '
|
|
75
|
+
version: '0'
|
|
89
76
|
type: :runtime
|
|
90
77
|
prerelease: false
|
|
91
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
79
|
requirements:
|
|
93
|
-
- - "
|
|
94
|
-
- !ruby/object:Gem::Version
|
|
95
|
-
version: '2.14'
|
|
96
|
-
- !ruby/object:Gem::Dependency
|
|
97
|
-
name: terminal-table
|
|
98
|
-
requirement: !ruby/object:Gem::Requirement
|
|
99
|
-
requirements:
|
|
100
|
-
- - "~>"
|
|
80
|
+
- - ">="
|
|
101
81
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: '
|
|
103
|
-
type: :runtime
|
|
104
|
-
prerelease: false
|
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
-
requirements:
|
|
107
|
-
- - "~>"
|
|
108
|
-
- !ruby/object:Gem::Version
|
|
109
|
-
version: '3.0'
|
|
110
|
-
- !ruby/object:Gem::Dependency
|
|
111
|
-
name: zeitwerk
|
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
|
113
|
-
requirements:
|
|
114
|
-
- - "~>"
|
|
115
|
-
- !ruby/object:Gem::Version
|
|
116
|
-
version: '2.6'
|
|
117
|
-
type: :runtime
|
|
118
|
-
prerelease: false
|
|
119
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
-
requirements:
|
|
121
|
-
- - "~>"
|
|
122
|
-
- !ruby/object:Gem::Version
|
|
123
|
-
version: '2.6'
|
|
124
|
-
- !ruby/object:Gem::Dependency
|
|
125
|
-
name: workflow
|
|
126
|
-
requirement: !ruby/object:Gem::Requirement
|
|
127
|
-
requirements:
|
|
128
|
-
- - "~>"
|
|
129
|
-
- !ruby/object:Gem::Version
|
|
130
|
-
version: '3.1'
|
|
131
|
-
type: :runtime
|
|
132
|
-
prerelease: false
|
|
133
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
-
requirements:
|
|
135
|
-
- - "~>"
|
|
136
|
-
- !ruby/object:Gem::Version
|
|
137
|
-
version: '3.1'
|
|
82
|
+
version: '0'
|
|
138
83
|
description: Ruby Implementation of the Interactive Brokers TWS API
|
|
139
84
|
email:
|
|
140
85
|
- topofocus@gmail.com
|
|
@@ -145,13 +90,11 @@ files:
|
|
|
145
90
|
- ".gitignore"
|
|
146
91
|
- ".rspec"
|
|
147
92
|
- ".travis.yml"
|
|
148
|
-
- CLAUDE.md
|
|
149
93
|
- CODE_OF_CONDUCT.md
|
|
150
94
|
- Gemfile
|
|
151
95
|
- Gemfile.lock
|
|
152
96
|
- Guardfile
|
|
153
97
|
- LICENSE
|
|
154
|
-
- LLM_GUIDE.md
|
|
155
98
|
- README.md
|
|
156
99
|
- Rakefile
|
|
157
100
|
- VERSION
|
|
@@ -159,154 +102,86 @@ files:
|
|
|
159
102
|
- bin/console
|
|
160
103
|
- bin/console.yml
|
|
161
104
|
- bin/setup
|
|
162
|
-
- bin/simple
|
|
163
105
|
- changelog.md
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
106
|
+
- example/README.md
|
|
107
|
+
- example/account_info
|
|
108
|
+
- example/account_positions
|
|
109
|
+
- example/account_summary
|
|
110
|
+
- example/cancel_orders
|
|
111
|
+
- example/fa_accounts
|
|
112
|
+
- example/fundamental_data
|
|
113
|
+
- example/historic_data_cli
|
|
114
|
+
- example/list_orders
|
|
115
|
+
- example/portfolio_csv
|
|
116
|
+
- example/scanner_data
|
|
117
|
+
- example/template
|
|
118
|
+
- example/tick_data
|
|
119
|
+
- lib/extensions/class-extensions.rb
|
|
172
120
|
- lib/ib-api.rb
|
|
173
121
|
- lib/ib/base.rb
|
|
174
122
|
- lib/ib/base_properties.rb
|
|
175
123
|
- lib/ib/connection.rb
|
|
176
124
|
- lib/ib/constants.rb
|
|
177
|
-
- lib/ib/contract.rb
|
|
178
125
|
- lib/ib/errors.rb
|
|
126
|
+
- lib/ib/logger.rb
|
|
179
127
|
- lib/ib/messages.rb
|
|
180
128
|
- lib/ib/messages/abstract_message.rb
|
|
181
129
|
- lib/ib/messages/incoming.rb
|
|
182
130
|
- lib/ib/messages/incoming/abstract_message.rb
|
|
183
|
-
- lib/ib/messages/incoming/
|
|
184
|
-
- lib/ib/messages/incoming/account_message.rb
|
|
131
|
+
- lib/ib/messages/incoming/account_value.rb
|
|
185
132
|
- lib/ib/messages/incoming/alert.rb
|
|
186
133
|
- lib/ib/messages/incoming/contract_data.rb
|
|
187
|
-
- lib/ib/messages/incoming/contract_message.rb
|
|
188
134
|
- lib/ib/messages/incoming/delta_neutral_validation.rb
|
|
189
135
|
- lib/ib/messages/incoming/execution_data.rb
|
|
190
|
-
- lib/ib/messages/incoming/histogram_data.rb
|
|
191
136
|
- lib/ib/messages/incoming/historical_data.rb
|
|
192
|
-
- lib/ib/messages/incoming/
|
|
193
|
-
- lib/ib/messages/incoming/managed_accounts.rb
|
|
194
|
-
- lib/ib/messages/incoming/market_depth.rb
|
|
195
|
-
- lib/ib/messages/incoming/market_depth_l2.rb
|
|
137
|
+
- lib/ib/messages/incoming/market_depths.rb
|
|
196
138
|
- lib/ib/messages/incoming/next_valid_id.rb
|
|
197
139
|
- lib/ib/messages/incoming/open_order.rb
|
|
198
140
|
- lib/ib/messages/incoming/order_status.rb
|
|
199
141
|
- lib/ib/messages/incoming/portfolio_value.rb
|
|
200
|
-
- lib/ib/messages/incoming/position_data.rb
|
|
201
|
-
- lib/ib/messages/incoming/positions_multi.rb
|
|
202
142
|
- lib/ib/messages/incoming/real_time_bar.rb
|
|
203
|
-
- lib/ib/messages/incoming/receive_fa.rb
|
|
204
143
|
- lib/ib/messages/incoming/scanner_data.rb
|
|
205
|
-
- lib/ib/messages/incoming/
|
|
206
|
-
- lib/ib/messages/incoming/tick_efp.rb
|
|
207
|
-
- lib/ib/messages/incoming/tick_generic.rb
|
|
208
|
-
- lib/ib/messages/incoming/tick_option.rb
|
|
209
|
-
- lib/ib/messages/incoming/tick_price.rb
|
|
210
|
-
- lib/ib/messages/incoming/tick_size.rb
|
|
211
|
-
- lib/ib/messages/incoming/tick_string.rb
|
|
144
|
+
- lib/ib/messages/incoming/ticks.rb
|
|
212
145
|
- lib/ib/messages/outgoing.rb
|
|
213
146
|
- lib/ib/messages/outgoing/abstract_message.rb
|
|
214
|
-
- lib/ib/messages/outgoing/
|
|
215
|
-
- lib/ib/messages/outgoing/
|
|
216
|
-
- lib/ib/messages/outgoing/old-place-order.rb
|
|
147
|
+
- lib/ib/messages/outgoing/account_requests.rb
|
|
148
|
+
- lib/ib/messages/outgoing/bar_requests.rb
|
|
217
149
|
- lib/ib/messages/outgoing/place_order.rb
|
|
218
|
-
- lib/ib/messages/outgoing/
|
|
219
|
-
- lib/ib/messages/outgoing/
|
|
220
|
-
- lib/ib/
|
|
221
|
-
- lib/ib/
|
|
222
|
-
- lib/ib/
|
|
223
|
-
- lib/ib/messages/outgoing/request_scanner_subscription.rb
|
|
224
|
-
- lib/ib/messages/outgoing/request_tick_by_tick_data.rb
|
|
225
|
-
- lib/ib/order_condition.rb
|
|
226
|
-
- lib/ib/plugins.rb
|
|
227
|
-
- lib/ib/prepare_data.rb
|
|
228
|
-
- lib/ib/raw_message_parser.rb
|
|
150
|
+
- lib/ib/messages/outgoing/request_marketdata.rb
|
|
151
|
+
- lib/ib/messages/outgoing/request_tick_data.rb
|
|
152
|
+
- lib/ib/model.rb
|
|
153
|
+
- lib/ib/models.rb
|
|
154
|
+
- lib/ib/server_versions.rb
|
|
229
155
|
- lib/ib/socket.rb
|
|
230
156
|
- lib/ib/support.rb
|
|
231
157
|
- lib/ib/version.rb
|
|
232
|
-
- lib/
|
|
233
|
-
- lib/
|
|
234
|
-
- lib/
|
|
235
|
-
- models/ib/
|
|
236
|
-
- models/ib/
|
|
237
|
-
- models/ib/
|
|
238
|
-
- models/ib/
|
|
239
|
-
- models/ib/
|
|
240
|
-
- models/ib/
|
|
241
|
-
- models/ib/
|
|
242
|
-
- models/ib/
|
|
243
|
-
- models/ib/
|
|
244
|
-
- models/ib/
|
|
245
|
-
- models/ib/
|
|
246
|
-
- models/ib/
|
|
247
|
-
- models/ib/
|
|
248
|
-
- models/ib/
|
|
249
|
-
- models/ib/
|
|
250
|
-
- models/ib/
|
|
251
|
-
- models/ib/
|
|
252
|
-
-
|
|
253
|
-
- models/ib/underlying.rb
|
|
254
|
-
- plugins/ib/advanced-account.rb
|
|
255
|
-
- plugins/ib/alerts/base-alert.rb
|
|
256
|
-
- plugins/ib/alerts/gateway-alerts.rb
|
|
257
|
-
- plugins/ib/alerts/order-alerts.rb
|
|
258
|
-
- plugins/ib/auto-adjust.rb
|
|
259
|
-
- plugins/ib/connection-tools.rb
|
|
260
|
-
- plugins/ib/eod.rb
|
|
261
|
-
- plugins/ib/greeks.rb
|
|
262
|
-
- plugins/ib/managed-accounts.rb
|
|
263
|
-
- plugins/ib/market-price.rb
|
|
264
|
-
- plugins/ib/option-chain.rb
|
|
265
|
-
- plugins/ib/order-flow.rb
|
|
266
|
-
- plugins/ib/order-prototypes.rb
|
|
267
|
-
- plugins/ib/order-prototypes/abstract.rb
|
|
268
|
-
- plugins/ib/order-prototypes/adaptive.rb
|
|
269
|
-
- plugins/ib/order-prototypes/all-in-one.rb
|
|
270
|
-
- plugins/ib/order-prototypes/combo.rb
|
|
271
|
-
- plugins/ib/order-prototypes/forex.rb
|
|
272
|
-
- plugins/ib/order-prototypes/limit.rb
|
|
273
|
-
- plugins/ib/order-prototypes/market.rb
|
|
274
|
-
- plugins/ib/order-prototypes/pegged.rb
|
|
275
|
-
- plugins/ib/order-prototypes/premarket.rb
|
|
276
|
-
- plugins/ib/order-prototypes/stop.rb
|
|
277
|
-
- plugins/ib/order-prototypes/volatility.rb
|
|
278
|
-
- plugins/ib/probability-of-expiring.rb
|
|
279
|
-
- plugins/ib/process-orders.rb
|
|
280
|
-
- plugins/ib/roll.rb
|
|
281
|
-
- plugins/ib/spread-prototypes.rb
|
|
282
|
-
- plugins/ib/spread-prototypes/butterfly.rb
|
|
283
|
-
- plugins/ib/spread-prototypes/calendar.rb
|
|
284
|
-
- plugins/ib/spread-prototypes/stock-spread.rb
|
|
285
|
-
- plugins/ib/spread-prototypes/straddle.rb
|
|
286
|
-
- plugins/ib/spread-prototypes/strangle.rb
|
|
287
|
-
- plugins/ib/spread-prototypes/vertical.rb
|
|
288
|
-
- plugins/ib/symbols.rb
|
|
289
|
-
- plugins/ib/symbols/abstract.rb
|
|
290
|
-
- plugins/ib/symbols/bonds.rb
|
|
291
|
-
- plugins/ib/symbols/cfd.rb
|
|
292
|
-
- plugins/ib/symbols/combo.rb
|
|
293
|
-
- plugins/ib/symbols/commodity.rb
|
|
294
|
-
- plugins/ib/symbols/forex.rb
|
|
295
|
-
- plugins/ib/symbols/futures.rb
|
|
296
|
-
- plugins/ib/symbols/index.rb
|
|
297
|
-
- plugins/ib/symbols/options.rb
|
|
298
|
-
- plugins/ib/symbols/stocks.rb
|
|
299
|
-
- plugins/ib/symbols/version.rb
|
|
300
|
-
- plugins/ib/verify.rb
|
|
301
|
-
- symbols/w20.yml
|
|
302
|
-
- t.txt
|
|
303
|
-
- update.md
|
|
158
|
+
- lib/models/ib/account.rb
|
|
159
|
+
- lib/models/ib/account_value.rb
|
|
160
|
+
- lib/models/ib/bag.rb
|
|
161
|
+
- lib/models/ib/bar.rb
|
|
162
|
+
- lib/models/ib/combo_leg.rb
|
|
163
|
+
- lib/models/ib/condition.rb
|
|
164
|
+
- lib/models/ib/contract.rb
|
|
165
|
+
- lib/models/ib/contract_detail.rb
|
|
166
|
+
- lib/models/ib/execution.rb
|
|
167
|
+
- lib/models/ib/forex.rb
|
|
168
|
+
- lib/models/ib/future.rb
|
|
169
|
+
- lib/models/ib/index.rb
|
|
170
|
+
- lib/models/ib/option.rb
|
|
171
|
+
- lib/models/ib/option_detail.rb
|
|
172
|
+
- lib/models/ib/order.rb
|
|
173
|
+
- lib/models/ib/order_state.rb
|
|
174
|
+
- lib/models/ib/portfolio_value.rb
|
|
175
|
+
- lib/models/ib/stock.rb
|
|
176
|
+
- lib/models/ib/underlying.rb
|
|
177
|
+
- lib/models/ib/vertical.rb
|
|
178
|
+
- lib/requires.rb
|
|
304
179
|
homepage: https://github.com/ib-ruby
|
|
305
|
-
licenses:
|
|
306
|
-
- MIT
|
|
180
|
+
licenses: []
|
|
307
181
|
metadata:
|
|
308
182
|
homepage_uri: https://github.com/ib-ruby
|
|
309
183
|
source_code_uri: https://github.com/ib-ruby/ib-api
|
|
184
|
+
post_install_message:
|
|
310
185
|
rdoc_options: []
|
|
311
186
|
require_paths:
|
|
312
187
|
- lib
|
|
@@ -314,14 +189,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
314
189
|
requirements:
|
|
315
190
|
- - ">="
|
|
316
191
|
- !ruby/object:Gem::Version
|
|
317
|
-
version: '
|
|
192
|
+
version: '0'
|
|
318
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
319
194
|
requirements:
|
|
320
195
|
- - ">="
|
|
321
196
|
- !ruby/object:Gem::Version
|
|
322
197
|
version: '0'
|
|
323
198
|
requirements: []
|
|
324
|
-
rubygems_version: 3.
|
|
199
|
+
rubygems_version: 3.0.4
|
|
200
|
+
signing_key:
|
|
325
201
|
specification_version: 4
|
|
326
202
|
summary: Ruby Implementation of the Interactive Brokers TWS API
|
|
327
203
|
test_files: []
|