ib-ruby 0.4.3 → 0.4.20
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +32 -0
- data/HISTORY +68 -0
- data/README.rdoc +9 -6
- data/VERSION +1 -1
- data/bin/account_info +29 -0
- data/bin/contract_details +37 -0
- data/bin/depth_of_market +43 -0
- data/bin/historic_data +62 -0
- data/bin/{RequestHistoricData → historic_data_cli} +46 -91
- data/bin/market_data +49 -0
- data/bin/option_data +45 -0
- data/bin/template +21 -0
- data/bin/time_and_sales +63 -0
- data/lib/ib-ruby/connection.rb +166 -0
- data/lib/ib-ruby/constants.rb +91 -0
- data/lib/ib-ruby/messages/incoming.rb +807 -0
- data/lib/ib-ruby/messages/outgoing.rb +573 -0
- data/lib/ib-ruby/messages.rb +8 -1445
- data/lib/ib-ruby/models/bar.rb +26 -0
- data/lib/ib-ruby/models/contract.rb +335 -0
- data/lib/ib-ruby/models/execution.rb +55 -0
- data/lib/ib-ruby/models/model.rb +20 -0
- data/lib/ib-ruby/models/order.rb +262 -0
- data/lib/ib-ruby/models.rb +11 -0
- data/lib/ib-ruby/socket.rb +50 -0
- data/lib/ib-ruby/symbols/forex.rb +32 -72
- data/lib/ib-ruby/symbols/futures.rb +47 -68
- data/lib/ib-ruby/symbols/options.rb +30 -0
- data/lib/ib-ruby/symbols/stocks.rb +23 -0
- data/lib/ib-ruby/symbols.rb +9 -0
- data/lib/ib-ruby.rb +7 -8
- data/lib/legacy/bin/account_info_old +36 -0
- data/lib/legacy/bin/historic_data_old +81 -0
- data/lib/legacy/bin/market_data_old +68 -0
- data/lib/legacy/datatypes.rb +485 -0
- data/lib/legacy/ib-ruby.rb +10 -0
- data/lib/legacy/ib.rb +226 -0
- data/lib/legacy/messages.rb +1458 -0
- data/lib/version.rb +2 -3
- data/spec/ib-ruby/models/contract_spec.rb +261 -0
- data/spec/ib-ruby/models/order_spec.rb +64 -0
- data/spec/ib-ruby_spec.rb +0 -131
- metadata +106 -76
- data/bin/AccountInfo +0 -67
- data/bin/HistoricToCSV +0 -111
- data/bin/RequestMarketData +0 -78
- data/bin/SimpleTimeAndSales +0 -98
- data/bin/ib-ruby +0 -8
- data/lib/ib-ruby/datatypes.rb +0 -400
- data/lib/ib-ruby/ib.rb +0 -242
@@ -0,0 +1,262 @@
|
|
1
|
+
require 'ib-ruby/models/model'
|
2
|
+
|
3
|
+
# TODO: Implement equals() according to the criteria in IB's Java client.
|
4
|
+
|
5
|
+
module IB
|
6
|
+
module Models
|
7
|
+
class Order < Model
|
8
|
+
|
9
|
+
# Constants used in Order objects. Drawn from Order.java
|
10
|
+
Origin_Customer = 0
|
11
|
+
Origin_Firm = 1
|
12
|
+
|
13
|
+
Opt_Unknown = '?'
|
14
|
+
Opt_Broker_Dealer = 'b'
|
15
|
+
Opt_Customer = 'c'
|
16
|
+
Opt_Firm = 'f'
|
17
|
+
Opt_Isemm = 'm'
|
18
|
+
Opt_Farmm = 'n'
|
19
|
+
Opt_Specialist = 'y'
|
20
|
+
|
21
|
+
OCA_Cancel_with_block = 1
|
22
|
+
OCA_Reduce_with_block = 2
|
23
|
+
OCA_Reduce_non_block = 3
|
24
|
+
|
25
|
+
# Box orders consts:
|
26
|
+
Box_Auction_Match = 1
|
27
|
+
Box_Auction_Improvement = 2
|
28
|
+
Box_Auction_Transparent = 3
|
29
|
+
|
30
|
+
# Volatility orders consts:
|
31
|
+
Volatility_Type_Daily = 1
|
32
|
+
Volatility_Type_Annual = 2
|
33
|
+
Volatility_Ref_Price_Average = 1
|
34
|
+
Volatility_Ref_Price_BidOrAsk = 2
|
35
|
+
|
36
|
+
# No idea why IB uses a large number as the default for some fields
|
37
|
+
Max_Value = 99999999
|
38
|
+
|
39
|
+
# Main order fields
|
40
|
+
attr_accessor :id, # int: m_orderId? The id for this order.
|
41
|
+
:client_id, # int: The id of the client that placed this order.
|
42
|
+
:perm_id, # int: TWS id used to identify orders, remains
|
43
|
+
# the same over TWS sessions.
|
44
|
+
:action, # String: Identifies the side. Valid values: BUY/SELL/SSHORT
|
45
|
+
:total_quantity, # int: The order quantity.
|
46
|
+
:order_type, # String: Identifies the order type. Valid values are:
|
47
|
+
# MKT / MKTCLS / LMT / LMTCLS / PEGMKT / SCALE
|
48
|
+
# STP / STPLMT / TRAIL / REL / VWAP / TRAILLIMIT
|
49
|
+
:limit_price, # double: This is the LIMIT price, used for limit,
|
50
|
+
# stop-limit and relative orders. In all other cases
|
51
|
+
# specify zero. For relative orders with no limit price,
|
52
|
+
# also specify zero.
|
53
|
+
:aux_price, # double: This is the STOP price for stop-limit orders,
|
54
|
+
# and the offset amount for relative orders. In all other
|
55
|
+
# cases, specify zero.
|
56
|
+
#:shares_allocation, # deprecated sharesAllocation field
|
57
|
+
|
58
|
+
# Extended order fields
|
59
|
+
:tif, # String: Time in Force - DAY / GTC / IOC / GTD
|
60
|
+
:oca_group, # String: one cancels all group name
|
61
|
+
:oca_type, # int: Tells how to handle remaining orders in an OCA group
|
62
|
+
# when one order or part of an order executes. Valid values:
|
63
|
+
# - 1 = Cancel all remaining orders with block
|
64
|
+
# - 2 = Remaining orders are reduced in size with block
|
65
|
+
# - 3 = Remaining orders are reduced in size with no block
|
66
|
+
# If you use a value "with block" your order has
|
67
|
+
# overfill protection. This means that only one order in
|
68
|
+
# the group will be routed at a time to remove the
|
69
|
+
# possibility of an overfill.
|
70
|
+
:transmit, # bool:if false, order will be created but not transmitted.
|
71
|
+
:parent_id, # int: The order ID of the parent (original) order, used
|
72
|
+
# for bracket (STP) and auto trailing stop (TRAIL) orders.
|
73
|
+
:block_order, # bool: the order is an ISE Block order.
|
74
|
+
:sweep_to_fill, # bool: the order is a Sweep-to-Fill order.
|
75
|
+
:display_size, # int: publicly disclosed order size for Iceberg orders.
|
76
|
+
|
77
|
+
:trigger_method, # Specifies how Simulated Stop, Stop-Limit and Trailing
|
78
|
+
# Stop orders are triggered. Valid values are:
|
79
|
+
# 0 - Default, "double bid/ask" method will be used for OTC stocks
|
80
|
+
# and US options orders, "last" method will be used all others.
|
81
|
+
# 1 - "double bid/ask" method, stop orders are triggered based on
|
82
|
+
# two consecutive bid or ask prices.
|
83
|
+
# 2 - "last" method, stops are triggered based on the last price.
|
84
|
+
# 3 - double last method.
|
85
|
+
# 4 - bid/ask method.
|
86
|
+
# 7 - last or bid/ask method.
|
87
|
+
# 8 - mid-point method.
|
88
|
+
|
89
|
+
:outside_rth, # bool: allows orders to also trigger or fill outside
|
90
|
+
# of regular trading hours. (WAS: ignore_rth)
|
91
|
+
:hidden, # bool: the order will not be visible when viewing
|
92
|
+
# the market depth. Only for ISLAND exchange.
|
93
|
+
:good_after_time, # FORMAT: 20060505 08:00:00 {time zone}
|
94
|
+
# Use an empty String if not applicable.
|
95
|
+
:good_till_date, # FORMAT: 20060505 08:00:00 {time zone}
|
96
|
+
# Use an empty String if not applicable.
|
97
|
+
:override_percentage_constraints, # bool: Precautionary constraints
|
98
|
+
# are defined on the TWS Presets page, and help ensure that your
|
99
|
+
# price and size order values are reasonable. Orders sent from the API
|
100
|
+
# are also validated against these safety constraints, and may be
|
101
|
+
# rejected if any constraint is violated. To override validation,
|
102
|
+
# set this parameter�s value to True.
|
103
|
+
|
104
|
+
:rule_80a, # Individual = 'I', Agency = 'A', AgentOtherMember = 'W',
|
105
|
+
# IndividualPTIA = 'J', AgencyPTIA = 'U', AgentOtherMemberPTIA = 'M',
|
106
|
+
# IndividualPT = 'K', AgencyPT = 'Y', AgentOtherMemberPT = 'N'
|
107
|
+
:all_or_none, # bool: yes=1, no=0
|
108
|
+
:min_quantity, # int: Identifies a minimum quantity order type.
|
109
|
+
:percent_offset, # double: percent offset amount for relative (REL)orders only
|
110
|
+
:trail_stop_price, # double: for TRAILLIMIT orders only
|
111
|
+
|
112
|
+
# Financial advisors only - use an empty String if not applicable.
|
113
|
+
:fa_group, :fa_profile, :fa_method, :fa_percentage,
|
114
|
+
|
115
|
+
# Institutional orders only!
|
116
|
+
:open_close, # String: O=Open, C=Close
|
117
|
+
:origin, # 0=Customer, 1=Firm
|
118
|
+
:order_ref, # String: The order reference. For institutional customers only.
|
119
|
+
:short_sale_slot, # 1 - you hold the shares,
|
120
|
+
# 2 - they will be delivered from elsewhere.
|
121
|
+
# Only for Action="SSHORT
|
122
|
+
:designated_location, # String: set when slot==2 only
|
123
|
+
:exempt_code, # int
|
124
|
+
|
125
|
+
# Clearing info
|
126
|
+
:account, # String: The account. For institutional customers only.
|
127
|
+
:settling_firm, # String: Institutional only
|
128
|
+
:clearing_account, # String: For IBExecution customers: Specifies the
|
129
|
+
# true beneficiary of the order. This value is required
|
130
|
+
# for FUT/FOP orders for reporting to the exchange.
|
131
|
+
:clearing_intent, # For IBExecution customers: "", IB, Away,
|
132
|
+
# and PTA (post trade allocation).
|
133
|
+
|
134
|
+
# SMART routing only
|
135
|
+
:discretionary_amount, # double: The amount off the limit price
|
136
|
+
# allowed for discretionary orders.
|
137
|
+
:etrade_only, # bool: Trade with electronic quotes.
|
138
|
+
:firm_quote_only, # bool: Trade with firm quotes.
|
139
|
+
:nbbo_price_cap, # double: Maximum Smart order distance from the NBBO.
|
140
|
+
|
141
|
+
# BOX or VOL ORDERS ONLY
|
142
|
+
:auction_strategy, # For BOX exchange only. Valid values:
|
143
|
+
# 1=AUCTION_MATCH, 2=AUCTION_IMPROVEMENT, 3=AUCTION_TRANSPARENT
|
144
|
+
:starting_price, # double: Starting price. Valid on BOX orders only.
|
145
|
+
:stock_ref_price, # double: The stock reference price, used for VOL
|
146
|
+
# orders to compute the limit price sent to an exchange (whether or not
|
147
|
+
# Continuous Update is selected), and for price range monitoring.
|
148
|
+
:delta, # double: Stock delta. Valid on BOX orders only.
|
149
|
+
|
150
|
+
# Pegged to stock or VOL orders. For price improvement option orders
|
151
|
+
# on BOX and VOL orders with dynamic management:
|
152
|
+
:stock_range_lower, # double: The lower value for the acceptable
|
153
|
+
# underlying stock price range.
|
154
|
+
:stock_range_upper, # double The upper value for the acceptable
|
155
|
+
# underlying stock price range.
|
156
|
+
|
157
|
+
# VOLATILITY ORDERS ONLY:
|
158
|
+
:volatility, # double: What the price is, computed via TWSs Options
|
159
|
+
# Analytics. For VOL orders, the limit price sent to an
|
160
|
+
# exchange is not editable, as it is the output of a
|
161
|
+
# function. Volatility is expressed as a percentage.
|
162
|
+
:volatility_type, # int: How the volatility is calculated: 1=daily, 2=annual
|
163
|
+
:reference_price_type, # int: For dynamic management of volatility orders:
|
164
|
+
# - 1 = Average of National Best Bid or Ask,
|
165
|
+
# - 2 = National Best Bid when buying a call or selling a put;
|
166
|
+
# and National Best Ask when selling a call or buying a put.
|
167
|
+
:delta_neutral_order_type, # String: Enter an order type to instruct TWS
|
168
|
+
# to submit a delta neutral trade on full or partial execution of the
|
169
|
+
# VOL order. For no hedge delta order to be sent, specify NONE.
|
170
|
+
:delta_neutral_aux_price, # double: Use this field to enter a value if
|
171
|
+
# the value in the deltaNeutralOrderType field is an order
|
172
|
+
# type that requires an Aux price, such as a REL order.
|
173
|
+
:continuous_update, # int: Used for dynamic management of volatility
|
174
|
+
# orders. Determines whether TWS is supposed to update the order price
|
175
|
+
# as the underlying moves. If selected, the limit price sent to an
|
176
|
+
# exchange is modified by TWS if the computed price of the option
|
177
|
+
# changes enough to warrant doing so. This is very helpful in keeping
|
178
|
+
# the limit price sent to the exchange up to date as the underlying price changes.
|
179
|
+
|
180
|
+
# COMBO ORDERS ONLY
|
181
|
+
:basis_points, # double: EFP orders only
|
182
|
+
:basis_points_type, # double: EFP orders only
|
183
|
+
|
184
|
+
# SCALE ORDERS ONLY
|
185
|
+
:scale_init_level_size, # int: Defines the size of the first, or initial,
|
186
|
+
# order component.
|
187
|
+
:scale_subs_level_size, # int: Defines the order size of the subsequent
|
188
|
+
# scale order components. Used in conjunction with scaleInitLevelSize().
|
189
|
+
:scale_price_increment, # double: Defines the price increment between
|
190
|
+
# scale components. This field is required for Scale orders.
|
191
|
+
|
192
|
+
# ALGO ORDERS ONLY
|
193
|
+
:algo_strategy, # String
|
194
|
+
:algo_params, # public Vector<TagValue> m_algoParams; ?!
|
195
|
+
|
196
|
+
# WTF?!
|
197
|
+
:what_if, #bool: Use to request pre-trade commissions and margin
|
198
|
+
# information. If set to true, margin and commissions data is received
|
199
|
+
# back via the OrderState() object for the openOrder() callback.
|
200
|
+
:not_held #public boolean m_notHeld; // Not Held
|
201
|
+
|
202
|
+
# Some Order properties (received back from IB)are separated into
|
203
|
+
# OrderState object. Here, they are lumped into Order proper: see OrderState.java
|
204
|
+
attr_accessor :status, # String: Displays the order status.
|
205
|
+
:init_margin, # String: Shows the impact the order would have on your
|
206
|
+
# initial margin.
|
207
|
+
:maint_margin, # String: Shows the impact the order would have on your
|
208
|
+
# maintenance margin.
|
209
|
+
:equity_with_loan, # String: Shows the impact the order would have on
|
210
|
+
# your equity with loan value.
|
211
|
+
:commission, # double: Shows the commission amount on the order.
|
212
|
+
:commission_currency, # String: Shows the currency of the commissio.
|
213
|
+
|
214
|
+
#These fields define the possible range of the actual order commission:
|
215
|
+
:min_commission,
|
216
|
+
:max_commission,
|
217
|
+
|
218
|
+
:warning_text # String: Displays a warning message if warranted.
|
219
|
+
|
220
|
+
def initialize opts = {}
|
221
|
+
# Assign defaults first!
|
222
|
+
@outside_rth = false
|
223
|
+
@open_close = "O"
|
224
|
+
@origin = Origin_Customer
|
225
|
+
@transmit = true
|
226
|
+
@designated_location = ''
|
227
|
+
@exempt_code = -1
|
228
|
+
@delta_neutral_order_type = ''
|
229
|
+
@what_if = false
|
230
|
+
@not_held = false
|
231
|
+
|
232
|
+
# TODO: Initialize with nil instead of Max_Value, or change
|
233
|
+
# Order sending code in IB::Messages::Outgoing::PlaceOrder
|
234
|
+
#@min_quantity = Max_Value
|
235
|
+
#@percent_offset = Max_Value # -"-
|
236
|
+
#@nbbo_price_cap = Max_Value # -"-
|
237
|
+
#@starting_price = Max_Value # -"-
|
238
|
+
#@stock_ref_price = Max_Value # -"-
|
239
|
+
#@delta = Max_Value
|
240
|
+
#@stock_range_lower = Max_Value # -"-
|
241
|
+
#@stock_range_upper = Max_Value # -"-
|
242
|
+
#@volatility = Max_Value # -"-
|
243
|
+
#@volatility_type = Max_Value # -"-
|
244
|
+
#@delta_neutral_aux_price = Max_Value # -"-
|
245
|
+
#@reference_price_type = Max_Value # -"-
|
246
|
+
#@trail_stop_price = Max_Value # -"-
|
247
|
+
#@basis_points = Max_Value # -"-
|
248
|
+
#@basis_points_type = Max_Value # -"-
|
249
|
+
#@scale_init_level_size = Max_Value # -"-
|
250
|
+
#@scale_subs_level_size = Max_Value # -"-
|
251
|
+
#@scale_price_increment = Max_Value # -"-
|
252
|
+
#@reference_price_type = Max_Value # -"-
|
253
|
+
#@reference_price_type = Max_Value # -"-
|
254
|
+
#@reference_price_type = Max_Value # -"-
|
255
|
+
#@reference_price_type = Max_Value # -"-
|
256
|
+
|
257
|
+
super opts
|
258
|
+
end
|
259
|
+
|
260
|
+
end # class Order
|
261
|
+
end # module Models
|
262
|
+
end # module IB
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module IB
|
4
|
+
class IBSocket < TCPSocket
|
5
|
+
|
6
|
+
# send nice null terminated binary data
|
7
|
+
def send(data)
|
8
|
+
self.syswrite(data.to_s + EOL)
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_string
|
12
|
+
str = self.gets(EOL).chop
|
13
|
+
#if str.nil?
|
14
|
+
# p 'NIL! FReaking NILLLLLLLLLLLLLLLLLLLLLLLL!'
|
15
|
+
# ''
|
16
|
+
#else
|
17
|
+
# str.chop
|
18
|
+
#end
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_int
|
22
|
+
self.read_string.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_int_max
|
26
|
+
str = self.read_string
|
27
|
+
str.nil? || str.empty? ? nil : str.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_boolean
|
31
|
+
self.read_string.to_i != 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_decimal
|
35
|
+
# Floating-point numbers shouldn't be used to store money...
|
36
|
+
# ...but BigDecimals are too unwieldy to use in this case... maybe later
|
37
|
+
# self.read_string.to_d
|
38
|
+
self.read_string.to_f
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_decimal_max
|
42
|
+
str = self.read_string
|
43
|
+
# Floating-point numbers shouldn't be used to store money...
|
44
|
+
# ...but BigDecimals are too unwieldy to use in this case... maybe later
|
45
|
+
# str.nil? || str.empty? ? nil : str.to_d
|
46
|
+
str.nil? || str.empty? ? nil : str.to_f
|
47
|
+
end
|
48
|
+
end # class IBSocket
|
49
|
+
|
50
|
+
end # module IB
|
@@ -1,109 +1,69 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Wes Devauld
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU Lesser General Public License as
|
6
|
-
# published by the Free Software Foundation; either version 2.1 of the
|
7
|
-
# License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful, but
|
10
|
-
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
17
|
-
# 02110-1301 USA
|
18
|
-
#
|
19
1
|
|
20
|
-
#
|
21
2
|
# Note that the :description field is particular to ib-ruby, and is NOT part of the standard TWS API.
|
22
3
|
# It is never transmitted to IB. It's purely used clientside, and you can store any arbitrary string that
|
23
4
|
# you may find useful there.
|
24
|
-
#
|
25
|
-
|
26
5
|
module IB
|
27
6
|
module Symbols
|
28
7
|
Forex = {
|
29
|
-
|
30
|
-
:symbol => "AUD",
|
8
|
+
:audusd => Models::Contract.new(:symbol => "AUD",
|
31
9
|
:exchange => "IDEALPRO",
|
32
10
|
:currency => "USD",
|
33
|
-
:sec_type =>
|
34
|
-
:description => "AUDUSD"
|
35
|
-
|
36
|
-
|
37
|
-
:symbol => "GBP",
|
11
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
12
|
+
:description => "AUDUSD"),
|
13
|
+
|
14
|
+
:gbpusd => Models::Contract.new(:symbol => "GBP",
|
38
15
|
:exchange => "IDEALPRO",
|
39
16
|
:currency => "USD",
|
40
|
-
:sec_type =>
|
41
|
-
:description => "GBPUSD"
|
42
|
-
}),
|
17
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
18
|
+
:description => "GBPUSD"),
|
43
19
|
|
44
|
-
|
45
|
-
:symbol => "EUR",
|
20
|
+
:euraud => Models::Contract.new(:symbol => "EUR",
|
46
21
|
:exchange => "IDEALPRO",
|
47
22
|
:currency => "AUD",
|
48
|
-
:sec_type =>
|
49
|
-
:description => "EURAUD"
|
50
|
-
}),
|
23
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
24
|
+
:description => "EURAUD"),
|
51
25
|
|
52
|
-
|
53
|
-
:symbol => "EUR",
|
26
|
+
:eurgbp => Models::Contract.new(:symbol => "EUR",
|
54
27
|
:exchange => "IDEALPRO",
|
55
28
|
:currency => "GBP",
|
56
|
-
:sec_type =>
|
57
|
-
:description => "EURGBP"
|
58
|
-
}),
|
29
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
30
|
+
:description => "EURGBP"),
|
59
31
|
|
60
|
-
|
61
|
-
:symbol => "EUR",
|
32
|
+
:eurjpy => Models::Contract.new(:symbol => "EUR",
|
62
33
|
:exchange => "IDEALPRO",
|
63
34
|
:currency => "JPY",
|
64
|
-
:sec_type =>
|
65
|
-
:description => "EURJPY"
|
66
|
-
}),
|
35
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
36
|
+
:description => "EURJPY"),
|
67
37
|
|
68
|
-
|
69
|
-
:symbol => "EUR",
|
38
|
+
:eurusd => Models::Contract.new(:symbol => "EUR",
|
70
39
|
:exchange => "IDEALPRO",
|
71
40
|
:currency => "USD",
|
72
|
-
:sec_type =>
|
73
|
-
:description => "EURUSD"
|
74
|
-
}),
|
41
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
42
|
+
:description => "EURUSD"),
|
75
43
|
|
76
|
-
|
77
|
-
:symbol => "EUR",
|
44
|
+
:eurcad => Models::Contract.new(:symbol => "EUR",
|
78
45
|
:exchange => "IDEALPRO",
|
79
46
|
:currency => "CAD",
|
80
|
-
:sec_type =>
|
81
|
-
:description => "EURCAD"
|
82
|
-
}),
|
47
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
48
|
+
:description => "EURCAD"),
|
83
49
|
|
84
|
-
|
85
|
-
:symbol => "USD",
|
50
|
+
:usdchf => Models::Contract.new(:symbol => "USD",
|
86
51
|
:exchange => "IDEALPRO",
|
87
52
|
:currency => "CHF",
|
88
|
-
:sec_type =>
|
89
|
-
:description => "USDCHF"
|
90
|
-
}),
|
53
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
54
|
+
:description => "USDCHF"),
|
91
55
|
|
92
|
-
|
93
|
-
:symbol => "USD",
|
56
|
+
:usdcad => Models::Contract.new(:symbol => "USD",
|
94
57
|
:exchange => "IDEALPRO",
|
95
58
|
:currency => "CAD",
|
96
|
-
:sec_type =>
|
97
|
-
:description => "USDCAD"
|
98
|
-
}),
|
59
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
60
|
+
:description => "USDCAD"),
|
99
61
|
|
100
|
-
|
101
|
-
:symbol => "USD",
|
62
|
+
:usdjpy => Models::Contract.new(:symbol => "USD",
|
102
63
|
:exchange => "IDEALPRO",
|
103
64
|
:currency => "JPY",
|
104
|
-
:sec_type =>
|
105
|
-
:description => "USDJPY"
|
106
|
-
|
107
|
-
}
|
65
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:forex],
|
66
|
+
:description => "USDJPY")
|
67
|
+
}
|
108
68
|
end # Contracts
|
109
69
|
end
|
@@ -1,23 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Wes Devauld
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU Lesser General Public License as
|
6
|
-
# published by the Free Software Foundation; either version 2.1 of the
|
7
|
-
# License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful, but
|
10
|
-
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
17
|
-
# 02110-1301 USA
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
1
|
# The Futures constant is currently for testing purposes. It guesses the front month
|
22
2
|
# currency future using a crude algorithm that does not take into account expiry/rollover day.
|
23
3
|
# This will be valid most of the time, but near/after expiry day the next quarter's contract
|
@@ -41,7 +21,7 @@ module IB
|
|
41
21
|
|
42
22
|
|
43
23
|
def self.next_quarter_month(time)
|
44
|
-
sprintf("%02d", [3, 6, 9, 12].find{|month| month >= time.month })
|
24
|
+
sprintf("%02d", [3, 6, 9, 12].find { |month| month >= time.month })
|
45
25
|
end
|
46
26
|
|
47
27
|
def self.next_quarter_year(time)
|
@@ -56,54 +36,53 @@ module IB
|
|
56
36
|
"#{ self.next_quarter_year(time) }#{ self.next_quarter_month(time) }"
|
57
37
|
end
|
58
38
|
|
59
|
-
Futures =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
39
|
+
Futures ={
|
40
|
+
:ym => Models::Contract.new(:symbol => "YM",
|
41
|
+
:expiry => self.next_expiry(Time.now),
|
42
|
+
:exchange => "ECBOT",
|
43
|
+
:currency => "USD",
|
44
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
45
|
+
:description => "Mini Dow Jones Industrial"),
|
46
|
+
|
47
|
+
:es => Models::Contract.new(:symbol => "ES",
|
48
|
+
:expiry => self.next_expiry(Time.now),
|
49
|
+
:exchange => "GLOBEX",
|
50
|
+
:currency => "USD",
|
51
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
52
|
+
:multiplier => 50,
|
53
|
+
:description => "E-Mini S&P 500"),
|
54
|
+
|
55
|
+
:gbp => Models::Contract.new(:symbol => "GBP",
|
56
|
+
:expiry => self.next_expiry(Time.now),
|
57
|
+
:exchange => "GLOBEX",
|
58
|
+
:currency => "USD",
|
59
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
60
|
+
:multiplier => 62500,
|
61
|
+
:description => "British Pounds"),
|
62
|
+
|
63
|
+
:eur => Models::Contract.new(:symbol => "EUR",
|
64
|
+
:expiry => self.next_expiry(Time.now),
|
65
|
+
:exchange => "GLOBEX",
|
66
|
+
:currency => "USD",
|
67
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
68
|
+
:multiplier => 12500,
|
69
|
+
:description => "Euro FX"),
|
70
|
+
|
71
|
+
:jpy => Models::Contract.new(:symbol => "JPY",
|
72
|
+
:expiry => self.next_expiry(Time.now),
|
73
|
+
:exchange => "GLOBEX",
|
74
|
+
:currency => "USD",
|
75
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
76
|
+
:multiplier => 12500000,
|
77
|
+
:description => "Japanese Yen"),
|
70
78
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
:description => "British Pounds"
|
79
|
-
}),
|
80
|
-
:eur => Datatypes::Contract.new({
|
81
|
-
:symbol => "EUR",
|
82
|
-
:expiry => self.next_expiry(Time.now),
|
83
|
-
:exchange => "GLOBEX",
|
84
|
-
:currency => "USD",
|
85
|
-
:sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
|
86
|
-
:multiplier => 12500,
|
87
|
-
:description => "Euro FX"
|
88
|
-
}),
|
89
|
-
:jpy => Datatypes::Contract.new({
|
90
|
-
:symbol => "JPY",
|
91
|
-
:expiry => self.next_expiry(Time.now),
|
92
|
-
:exchange => "GLOBEX",
|
93
|
-
:currency => "USD",
|
94
|
-
:sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
|
95
|
-
:multiplier => 12500000,
|
96
|
-
:description => "Japanese Yen"
|
97
|
-
}),
|
98
|
-
:hsi => Datatypes::Contract.new({
|
99
|
-
:symbol => "HSI",
|
100
|
-
:expiry => self.next_expiry(Time.now),
|
101
|
-
:exchange => "HKFE",
|
102
|
-
:currency => "HKD",
|
103
|
-
:sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
|
104
|
-
:multiplier => 50,
|
105
|
-
:description => "Hang Seng Index"
|
106
|
-
})
|
79
|
+
:hsi => Models::Contract.new(:symbol => "HSI",
|
80
|
+
:expiry => self.next_expiry(Time.now),
|
81
|
+
:exchange => "HKFE",
|
82
|
+
:currency => "HKD",
|
83
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:future],
|
84
|
+
:multiplier => 50,
|
85
|
+
:description => "Hang Seng Index")
|
107
86
|
}
|
108
87
|
end
|
109
88
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Stock contracts definitions
|
2
|
+
#
|
3
|
+
# Note that the :description field is particular to ib-ruby, and is NOT part of the
|
4
|
+
# standard TWS API. It is never transmitted to IB. It's purely used clientside, and
|
5
|
+
# you can store any arbitrary string that you may find useful there.
|
6
|
+
|
7
|
+
module IB
|
8
|
+
module Symbols
|
9
|
+
|
10
|
+
Options =
|
11
|
+
{:wfc20 => Models::Contract.new(:symbol => "WFC",
|
12
|
+
:exchange => "SMART",
|
13
|
+
#:currency => "USD",
|
14
|
+
:expiry => "201110",
|
15
|
+
:right => "CALL",
|
16
|
+
:strike => 20.0,
|
17
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:option],
|
18
|
+
:description => "Wells Fargo 20 Call 2011-10"),
|
19
|
+
:z50 => Models::Contract.new(:symbol => "Z",
|
20
|
+
:exchange => "LIFFE",
|
21
|
+
#:currency => "USD",
|
22
|
+
:expiry => "201110",
|
23
|
+
:right => "CALL",
|
24
|
+
:strike => 50.0,
|
25
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:option],
|
26
|
+
:description => " FTSE-100 index 50 Call 2011-10"),
|
27
|
+
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Stock contracts definitions
|
2
|
+
#
|
3
|
+
# Note that the :description field is particular to ib-ruby, and is NOT part of the
|
4
|
+
# standard TWS API. It is never transmitted to IB. It's purely used clientside, and
|
5
|
+
# you can store any arbitrary string that you may find useful there.
|
6
|
+
|
7
|
+
module IB
|
8
|
+
module Symbols
|
9
|
+
|
10
|
+
Stocks =
|
11
|
+
{:wfc => Models::Contract.new(:symbol => "WFC",
|
12
|
+
:exchange => "NYSE",
|
13
|
+
:currency => "USD",
|
14
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:stock],
|
15
|
+
:description => "Wells Fargo"),
|
16
|
+
:wrong => Models::Contract.new(:symbol => "QEEUUE",
|
17
|
+
:exchange => "NYSE",
|
18
|
+
:currency => "USD",
|
19
|
+
:sec_type => Models::Contract::SECURITY_TYPES[:stock],
|
20
|
+
:description => "Inexistent stock"),
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|