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,178 @@
|
|
|
1
|
+
#require 'active_support/hash_with_indifferent_access'
|
|
2
|
+
|
|
3
|
+
module IB
|
|
4
|
+
|
|
5
|
+
# Module adds prop Macro and
|
|
6
|
+
module BaseProperties
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
### Instance methods
|
|
10
|
+
|
|
11
|
+
# Default presentation
|
|
12
|
+
def to_human
|
|
13
|
+
"<#{self.class.to_s.demodulize}: " + attributes.map do |attr, value|
|
|
14
|
+
"#{attr}: #{value}" unless value.nil?
|
|
15
|
+
end.compact.sort.join(' ') + ">"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def table_header
|
|
19
|
+
[ self.class.to_s.demodulize ] + content_attributes.keys
|
|
20
|
+
end
|
|
21
|
+
def table_row
|
|
22
|
+
[ self.class.to_s.demodulize ] + content_attributes.values
|
|
23
|
+
end
|
|
24
|
+
# the optional block specifies a title
|
|
25
|
+
# i.e.
|
|
26
|
+
#s = Symbols::Spreads.stoxx_dez
|
|
27
|
+
# puts s.portfolio_value( U).as_table{ s.description[1..-2] }
|
|
28
|
+
#┌───────────┬─────────────────────────────────────────────┬─────┬────────┬─────────┬──────────┬────────────┬──────────┐
|
|
29
|
+
#│ │ Straddle ESTX50(4200.0)[Dec 2021] │ pos │ entry │ market │ value │ unrealized │ realized │
|
|
30
|
+
#╞═══════════╪═════════════════════════════════════════════╪═════╪════════╪═════════╪══════════╪════════════╪══════════╡
|
|
31
|
+
#│ U7274612 │ Option: ESTX50 20211217 put 4200.0 DTB EUR │ -4 │ 179.85 │ 169.831 │ -6793.22 │ 400.78 │ │
|
|
32
|
+
#│ U7274612 │ Option: ESTX50 20211217 call 4200.0 DTB EUR │ -4 │ 97.85 │ 131.438 │ -5257.51 │ -1343.51 │ │
|
|
33
|
+
#└───────────┴─────────────────────────────────────────────┴─────┴────────┴─────────┴──────────┴────────────┴──────────┘
|
|
34
|
+
#
|
|
35
|
+
def as_table &b
|
|
36
|
+
Terminal::Table.new headings: table_header(&b), rows: [table_row ], style: { border: :unicode }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Comparison support
|
|
40
|
+
def content_attributes
|
|
41
|
+
#NoMethodError if a Hash is assigned to an attribute
|
|
42
|
+
Hash[attributes.reject do |(attr, _)|
|
|
43
|
+
attr.to_s =~ /(_count)\z/ ||
|
|
44
|
+
[:created_at, :type, :updated_at,
|
|
45
|
+
:id, :order_id, :contract_id].include?(attr.to_sym)
|
|
46
|
+
end]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
=begin
|
|
50
|
+
Remove all Time-Stamps from the list of Attributes
|
|
51
|
+
=end
|
|
52
|
+
def invariant_attributes
|
|
53
|
+
attributes.reject{|x| x =~ /_at/}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Update nil attributes from given Hash or model
|
|
57
|
+
def update_missing attrs
|
|
58
|
+
attrs = attrs.content_attributes unless attrs.kind_of?(Hash)
|
|
59
|
+
|
|
60
|
+
attrs.each { |attr, val| send "#{attr}=", val if send(attr).blank? }
|
|
61
|
+
self # for chaining
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Default Model comparison
|
|
65
|
+
def == other
|
|
66
|
+
case other
|
|
67
|
+
when String # Probably a Rails URI, delegate to AR::Base
|
|
68
|
+
super(other)
|
|
69
|
+
else
|
|
70
|
+
content_attributes.keys.inject(true) { |res, key|
|
|
71
|
+
res && other.respond_to?(key) && (send(key) == other.send(key)) }
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
### Default attributes support
|
|
76
|
+
|
|
77
|
+
def default_attributes
|
|
78
|
+
{:created_at => Time.now
|
|
79
|
+
# :updated_at => Time.now,
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def set_attribute_defaults
|
|
84
|
+
default_attributes.each do |key, val|
|
|
85
|
+
self.send("#{key}=", val) if self.send(key).nil?
|
|
86
|
+
# self.send("#{key}=", val) if self[key].nil? # Problems with association defaults
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
included do
|
|
91
|
+
|
|
92
|
+
after_initialize :set_attribute_defaults
|
|
93
|
+
|
|
94
|
+
### Class macros
|
|
95
|
+
|
|
96
|
+
def self.prop *properties
|
|
97
|
+
prop_hash = properties.last.is_a?(Hash) ? properties.pop : {}
|
|
98
|
+
|
|
99
|
+
properties.each { |names| define_property names, nil }
|
|
100
|
+
prop_hash.each { |names, type| define_property names, type }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.define_property names, body
|
|
104
|
+
aliases = [names].flatten
|
|
105
|
+
name = aliases.shift
|
|
106
|
+
instance_eval do
|
|
107
|
+
|
|
108
|
+
define_property_methods name, body
|
|
109
|
+
|
|
110
|
+
aliases.each do |ali|
|
|
111
|
+
alias_method "#{ali}", name
|
|
112
|
+
alias_method "#{ali}=", "#{name}="
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def self.define_property_methods name, body={}
|
|
118
|
+
#p name, body
|
|
119
|
+
case body
|
|
120
|
+
when '' # default getter and setter
|
|
121
|
+
define_property_methods name
|
|
122
|
+
|
|
123
|
+
when Array # [setter, getter, validators]
|
|
124
|
+
define_property_methods name,
|
|
125
|
+
:get => body[0],
|
|
126
|
+
:set => body[1],
|
|
127
|
+
:validate => body[2]
|
|
128
|
+
|
|
129
|
+
when Hash # recursion base case
|
|
130
|
+
getter = case # Define getter
|
|
131
|
+
when body[:get].respond_to?(:call)
|
|
132
|
+
body[:get]
|
|
133
|
+
when body[:get]
|
|
134
|
+
proc { self[name].send "to_#{body[:get]}" }
|
|
135
|
+
when IB::VALUES[name] # property is encoded
|
|
136
|
+
proc { IB::VALUES[name][self[name]] }
|
|
137
|
+
else
|
|
138
|
+
proc { self[name] }
|
|
139
|
+
end
|
|
140
|
+
define_method name, &getter if getter
|
|
141
|
+
|
|
142
|
+
setter = case # Define setter
|
|
143
|
+
when body[:set].respond_to?(:call)
|
|
144
|
+
body[:set]
|
|
145
|
+
when body[:set]
|
|
146
|
+
proc { |value| self[name] = value.send "to_#{body[:set]}" }
|
|
147
|
+
when CODES[name] # property is encoded
|
|
148
|
+
proc { |value| self[name] = CODES[name][value] || value }
|
|
149
|
+
else
|
|
150
|
+
proc { |value| self[name] = value } # p name, value;
|
|
151
|
+
end
|
|
152
|
+
define_method "#{name}=", &setter if setter
|
|
153
|
+
|
|
154
|
+
# Define validator(s)
|
|
155
|
+
[body[:validate]].flatten.compact.each do |validator|
|
|
156
|
+
case validator
|
|
157
|
+
when Proc
|
|
158
|
+
validates_each name, &validator
|
|
159
|
+
when Hash
|
|
160
|
+
validates name, validator.dup
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# TODO define self[:name] accessors for :virtual and :flag properties
|
|
165
|
+
|
|
166
|
+
else # setter given
|
|
167
|
+
define_property_methods name, :set => body, :get => body
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Timestamps in lightweight models
|
|
172
|
+
# unless defined?(ActiveRecord::Base) && ancestors.include?(ActiveRecord::Base)
|
|
173
|
+
prop :created_at #, :updated_at
|
|
174
|
+
# end
|
|
175
|
+
|
|
176
|
+
end # included
|
|
177
|
+
end # module BaseProperties
|
|
178
|
+
end
|