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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'models/ib/contract'
|
|
2
|
+
require 'models/ib/option_detail'
|
|
3
|
+
|
|
4
|
+
module IB
|
|
5
|
+
class Option < Contract
|
|
6
|
+
|
|
7
|
+
validates_numericality_of :strike, :greater_than => 0
|
|
8
|
+
validates_format_of :sec_type, :with => /\Aoption\z/,
|
|
9
|
+
:message => "should be an option"
|
|
10
|
+
validates_format_of :local_symbol, :with => /\A\w+\s*\d{6}[pcPC]\d{8}$|\A\z/,
|
|
11
|
+
:message => "invalid OSI code"
|
|
12
|
+
validates_format_of :right, :with => /\Aput$|^call\z/,
|
|
13
|
+
:message => "should be put or call"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# introduce Option.greek with reference to IB::OptionDetail-dataset
|
|
17
|
+
#
|
|
18
|
+
has_one :greek , as: :option_detail
|
|
19
|
+
# For Options, this is contract's OSI (Option Symbology Initiative) name/code
|
|
20
|
+
alias osi local_symbol
|
|
21
|
+
|
|
22
|
+
def osi= value
|
|
23
|
+
# Normalize to 21 char
|
|
24
|
+
self.local_symbol = value.sub(/ /, ' '*(22-value.size))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Make valid IB Contract definition from OSI (Option Symbology Initiative) code.
|
|
28
|
+
# NB: Simply making a new Contract with *local_symbol* (osi) property set to a
|
|
29
|
+
# valid OSI code works just as well, just do NOT set *expiry*, *right* or
|
|
30
|
+
# *strike* properties in this case.
|
|
31
|
+
# This class method provided as a backup and shows how to analyse OSI codes.
|
|
32
|
+
def self.from_osi osi
|
|
33
|
+
|
|
34
|
+
# Parse contract's OSI (OCC Option Symbology Initiative) code
|
|
35
|
+
args = osi.match(/(\w+)\s?(\d\d)(\d\d)(\d\d)([pcPC])(\d+)/).to_a.drop(1)
|
|
36
|
+
symbol = args.shift
|
|
37
|
+
year = 2000 + args.shift.to_i
|
|
38
|
+
month = args.shift.to_i
|
|
39
|
+
day = args.shift.to_i
|
|
40
|
+
right = args.shift.upcase
|
|
41
|
+
strike = args.shift.to_i/1000.0
|
|
42
|
+
|
|
43
|
+
# Set correct expiry date - IB expiry date differs from OSI if expiry date
|
|
44
|
+
# falls on Saturday (see https://github.com/arvicco/option_mower/issues/4)
|
|
45
|
+
expiry_date = Time.utc(year, month, day)
|
|
46
|
+
expiry_date = Time.utc(year, month, day-1) if expiry_date.wday == 6
|
|
47
|
+
|
|
48
|
+
new :symbol => symbol,
|
|
49
|
+
:exchange => "SMART",
|
|
50
|
+
:expiry => expiry_date.to_ib[2..7], # YYMMDD
|
|
51
|
+
:right => right,
|
|
52
|
+
:strike => strike
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def default_attributes
|
|
56
|
+
super.merge :sec_type => :option
|
|
57
|
+
#self[:description] ||= osi ? osi : "#{symbol} #{strike} #{right} #{expiry}"
|
|
58
|
+
end
|
|
59
|
+
def == other
|
|
60
|
+
super(other) || ( # finish positive, if contract#== is true
|
|
61
|
+
# otherwise, we most probably compare the response from IB with our selfmade input
|
|
62
|
+
exchange == other.exchange &&
|
|
63
|
+
include_expired == other.include_expired &&
|
|
64
|
+
sec_type == other.sec_type &&
|
|
65
|
+
multiplier == other.multiplier &&
|
|
66
|
+
strike == other.strike &&
|
|
67
|
+
right == other.right &&
|
|
68
|
+
multiplier == other.multiplier &&
|
|
69
|
+
expiry == other.expiry )
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def to_human
|
|
74
|
+
"<Option: " + [symbol, expiry, right, strike, exchange, currency].join(" ") + ">"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end # class Option
|
|
78
|
+
end # module IB
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module IB
|
|
2
|
+
|
|
3
|
+
# Additional Option properties and Option-Calculations
|
|
4
|
+
class OptionDetail < IB::Model
|
|
5
|
+
include BaseProperties
|
|
6
|
+
|
|
7
|
+
prop :delta, :gamma, :vega, :theta, # greeks
|
|
8
|
+
:implied_volatility,
|
|
9
|
+
:pv_dividend, # anticipated Dividend
|
|
10
|
+
:under_price, # price of the Underlying
|
|
11
|
+
:option_price,
|
|
12
|
+
:close_price,
|
|
13
|
+
:open_tick,
|
|
14
|
+
:bid_price,
|
|
15
|
+
:ask_price,
|
|
16
|
+
:prev_strike,
|
|
17
|
+
:next_strike,
|
|
18
|
+
:prev_expiry,
|
|
19
|
+
:next_expiry,
|
|
20
|
+
:option_price
|
|
21
|
+
belongs_to :option
|
|
22
|
+
|
|
23
|
+
# returns true if all datafields are filled with reasonal data
|
|
24
|
+
def complete?
|
|
25
|
+
fields= [ :delta, :gamma, :vega, :theta,
|
|
26
|
+
:implied_volatility, :pv_dividend, :open_tick,
|
|
27
|
+
:under_price, :option_price, :close_price, :bid_price, :ask_price]
|
|
28
|
+
|
|
29
|
+
!fields.detect{|y| self.send(y).nil?}
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def greeks?
|
|
34
|
+
fields= [ :delta, :gamma, :vega, :theta,
|
|
35
|
+
:implied_volatility, :pv_dividend]
|
|
36
|
+
|
|
37
|
+
!fields.detect{|y| self.send(y).nil?}
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_human
|
|
42
|
+
outstr= ->( item ) { if item.nil? then "--" else sprintf("%g" , item) end }
|
|
43
|
+
att = " optionPrice: #{ outstr[ option_price ]}, UnderlyingPrice: #{ outstr[ under_price] } impl.Vola: #{ outstr[ implied_volatility ]} ; dividend: #{ outstr[ pv_dividend ]}; "
|
|
44
|
+
greeks = "Greeks:: delta: #{ outstr[ delta ] }; gamma: #{ outstr[ gamma ]}, vega: #{ outstr[ vega ] }; theta: #{ outstr[ theta ]}"
|
|
45
|
+
prices= " close: #{ outstr[ close_price ]}; bid: #{ outstr[ bid_price ]}; ask: #{ outstr[ ask_price ]} "
|
|
46
|
+
if complete?
|
|
47
|
+
"< "+ prices + "\n" + att + "\n" + greeks + " >"
|
|
48
|
+
else
|
|
49
|
+
"< " + greeks + " >"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end # class
|
|
55
|
+
end # module
|