ib-symbols 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/README.md +98 -0
- data/Rakefile +6 -0
- data/bin/console +108 -0
- data/bin/console.yml +3 -0
- data/bin/setup +8 -0
- data/build.md +28 -0
- data/examples/contract_details +71 -0
- data/examples/contract_sample_details +50 -0
- data/examples/contract_samples.rb +716 -0
- data/examples/depth_of_market +45 -0
- data/examples/head_time_stamp +35 -0
- data/examples/historic_data +102 -0
- data/examples/market_data +57 -0
- data/examples/option_data +63 -0
- data/examples/real_time_data +35 -0
- data/examples/snapshot_market_data +105 -0
- data/examples/time_and_sales +51 -0
- data/ib-symbols.gemspec +38 -0
- data/lib/ib/symbols.rb +112 -0
- data/lib/ib/symbols/abstract.rb +137 -0
- data/lib/ib/symbols/bonds.rb +28 -0
- data/lib/ib/symbols/cfd.rb +19 -0
- data/lib/ib/symbols/combo.rb +52 -0
- data/lib/ib/symbols/commodity.rb +17 -0
- data/lib/ib/symbols/forex.rb +41 -0
- data/lib/ib/symbols/futures.rb +137 -0
- data/lib/ib/symbols/index.rb +43 -0
- data/lib/ib/symbols/options.rb +82 -0
- data/lib/ib/symbols/stocks.rb +38 -0
- data/lib/ib/symbols/version.rb +5 -0
- data/lib/ib/symbols_base.rb +58 -0
- data/symbols/README.md +20 -0
- data/symbols/test.yml +12 -0
- metadata +196 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This script gets details for specific contract from IB
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'ib/symbols'
|
7
|
+
require './contract_samples'
|
8
|
+
include IB
|
9
|
+
# Definition of what we want market data for. We have to keep track of what ticker id
|
10
|
+
# corresponds to what symbol ourselves, because the ticks don't include any other
|
11
|
+
# identifying information. The choice of ticker ids is, as far as I can tell, arbitrary.
|
12
|
+
contract_definitions = ContractSamples.public_instance_methods
|
13
|
+
|
14
|
+
# get contracts from contract_samples db
|
15
|
+
include ContractSamples
|
16
|
+
the_contracts = contract_definitions.map{ | method | self.send( method )}
|
17
|
+
|
18
|
+
|
19
|
+
# Connect to IB TWS.
|
20
|
+
ib = Connection.new( :client_id => 11912, :port => 4002 ) do | gw| # 7496 # TWS
|
21
|
+
# subscribe to TWS alerts/errors and contract data end marker
|
22
|
+
gw.subscribe(:Alert, :ContractDataEnd) { |msg| puts msg.to_human }
|
23
|
+
|
24
|
+
# subscribe to ContractData incoming events. The code passed in the block
|
25
|
+
# will be executed when a message of that type is received, with the received
|
26
|
+
# message as its argument. In this case, we just print out the data.
|
27
|
+
gw.subscribe(:ContractData, :BondContractData) do |msg|
|
28
|
+
puts "------------------> Recieved Contract Confirmation <----------------------------"
|
29
|
+
puts msg.contract.to_human + "\n"
|
30
|
+
puts "Attributes: "
|
31
|
+
puts "\t"+ msg.contract.attributes.map{ |k,v| "#{k} : #{v}" unless v.blank? }.join("\n\t")
|
32
|
+
end
|
33
|
+
# Set log level
|
34
|
+
gw.logger.level = Logger::DEBUG #FATAL
|
35
|
+
end
|
36
|
+
|
37
|
+
ib.wait_for :NextValidOrderId
|
38
|
+
|
39
|
+
|
40
|
+
the_contracts.each do | contract|
|
41
|
+
puts "\nRequesting contract data: #{contract_definitions}: #{contract.to_human}"
|
42
|
+
|
43
|
+
# Request Contract details for the symbols we're interested in. TWS will
|
44
|
+
# respond with ContractData messages, which will be processed by the code above.
|
45
|
+
ib.send_message :RequestContractData, contract: contract
|
46
|
+
|
47
|
+
# Wait for IB to respond to our request
|
48
|
+
ib.wait_for :ContractDataEnd, 1 #sec
|
49
|
+
ib.clear_received :ContractDataEnd
|
50
|
+
end
|
@@ -0,0 +1,716 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ---------------------------------------------------------------------------------- #
|
3
|
+
# C O N T R A C T S A M P L E S #
|
4
|
+
#
|
5
|
+
# Sample Contracts for ib-ruby with 1:1 comparism to python code
|
6
|
+
#
|
7
|
+
# based on »ContractSamples.py« (python-implementation of the tws-api)
|
8
|
+
# which is protected by the following copyright
|
9
|
+
#
|
10
|
+
#Copyright (C) 2016 Interactive Brokers LLC. All rights reserved. This code is
|
11
|
+
#subject to the terms and conditions of the IB API Non-Commercial License or the
|
12
|
+
# IB API Commercial License, as applicable.
|
13
|
+
#
|
14
|
+
#
|
15
|
+
|
16
|
+
# This script just generates contracts
|
17
|
+
# If called from the command line, it prints a list
|
18
|
+
|
19
|
+
require 'bundler/setup'
|
20
|
+
require 'yaml'
|
21
|
+
require 'ib/symbols'
|
22
|
+
include IB
|
23
|
+
|
24
|
+
module ContractSamples
|
25
|
+
|
26
|
+
""" Usually, the easiest way to define a Stock/CASH contract is through
|
27
|
+
these four attributes. """
|
28
|
+
|
29
|
+
def rEurGbpFx
|
30
|
+
Symbols::Forex[:eurgbp]
|
31
|
+
end
|
32
|
+
=begin
|
33
|
+
[cashcontract]
|
34
|
+
contract = Contract()
|
35
|
+
contract.symbol = "EUR"
|
36
|
+
contract.secType = "CASH"
|
37
|
+
contract.currency = "GBP"
|
38
|
+
contract.exchange = "IDEALPRO"
|
39
|
+
=end
|
40
|
+
|
41
|
+
def rIndex
|
42
|
+
Contract.new symbol: 'DAX', sec_type: :index, currency: 'EUR', exchange: 'DTB'
|
43
|
+
end
|
44
|
+
=begin
|
45
|
+
[indcontract]
|
46
|
+
contract = Contract()
|
47
|
+
contract.symbol = "DAX"
|
48
|
+
contract.secType = "IND"
|
49
|
+
contract.currency = "EUR"
|
50
|
+
contract.exchange = "DTB"
|
51
|
+
=end
|
52
|
+
|
53
|
+
|
54
|
+
def rCFD
|
55
|
+
Contract.new symbol: 'IBDE30', sec_type: :cfd, currency: 'EUR'
|
56
|
+
end
|
57
|
+
=begin
|
58
|
+
#! [cfdcontract]
|
59
|
+
contract = Contract()
|
60
|
+
contract.symbol = "IBDE30"
|
61
|
+
contract.secType = "CFD"
|
62
|
+
contract.currency = "EUR"
|
63
|
+
contract.exchange = "SMART"
|
64
|
+
=end
|
65
|
+
|
66
|
+
|
67
|
+
def rEuropeanStock
|
68
|
+
Stock.new symbol: 'SIE', currency: 'EUR'
|
69
|
+
end
|
70
|
+
=begin
|
71
|
+
contract = Contract()
|
72
|
+
contract.symbol = "SIE"
|
73
|
+
contract.secType = "STK"
|
74
|
+
contract.currency = "EUR"
|
75
|
+
contract.exchange = "SMART"
|
76
|
+
=end
|
77
|
+
|
78
|
+
def rOptionAtIse
|
79
|
+
Option.new symbol: 'ARGO',
|
80
|
+
currency: "USD",
|
81
|
+
exchange: "ISE",
|
82
|
+
expiry: Symbols::Futures.next_expiry,
|
83
|
+
right: :call,
|
84
|
+
strike: 10,
|
85
|
+
multiplier: 100
|
86
|
+
end
|
87
|
+
=begin
|
88
|
+
contract = Contract()
|
89
|
+
contract.symbol = "BPX"
|
90
|
+
contract.secType = "OPT"
|
91
|
+
contract.currency = "USD"
|
92
|
+
contract.exchange = "ISE"
|
93
|
+
contract.lastTradeDateOrContractMonth = "20160916"
|
94
|
+
contract.right = "C"
|
95
|
+
contract.strike = 65
|
96
|
+
contract.multiplier = "100"
|
97
|
+
=end
|
98
|
+
|
99
|
+
def rBondWithCusip
|
100
|
+
Contract.new symbol: '912828C57', sec_type: :bond, currency: 'USD'
|
101
|
+
end
|
102
|
+
=begin
|
103
|
+
#! [bondwithcusip]
|
104
|
+
contract = Contract()
|
105
|
+
# enter CUSIP as symbol
|
106
|
+
contract.symbol= "912828C57"
|
107
|
+
contract.secType = "BOND"
|
108
|
+
contract.exchange = "SMART"
|
109
|
+
contract.currency = "USD"
|
110
|
+
=end
|
111
|
+
|
112
|
+
def rBond
|
113
|
+
Contract.new con_id: 267433416
|
114
|
+
end
|
115
|
+
=begin
|
116
|
+
#! [bond]
|
117
|
+
contract = Contract()
|
118
|
+
contract.conId = 267433416
|
119
|
+
contract.exchange = "SMART"
|
120
|
+
=end
|
121
|
+
|
122
|
+
|
123
|
+
def rMutualFund
|
124
|
+
Contract.new symbol: 'VINIX', sec_type: :fund, exchange: 'FUNDSERV', currency: 'USD'
|
125
|
+
end
|
126
|
+
=begin
|
127
|
+
#! [fundcontract]
|
128
|
+
contract = Contract()
|
129
|
+
contract.symbol = "VINIX"
|
130
|
+
contract.secType = "FUND"
|
131
|
+
contract.exchange = "FUNDSERV"
|
132
|
+
contract.currency = "USD"
|
133
|
+
=end
|
134
|
+
|
135
|
+
def rCommodity
|
136
|
+
Contract.new symbol: 'XAUUSD', sec_type: :commodity, currency: 'USD'
|
137
|
+
end
|
138
|
+
=begin
|
139
|
+
#! [commoditycontract]
|
140
|
+
contract = Contract()
|
141
|
+
contract.symbol = "XAUUSD"
|
142
|
+
contract.secType = "CMDTY"
|
143
|
+
contract.exchange = "SMART"
|
144
|
+
contract.currency = "USD"
|
145
|
+
=end
|
146
|
+
|
147
|
+
|
148
|
+
def rUSStock
|
149
|
+
#In the API side, NASDAQ is always defined as ISLAND in the exchange field
|
150
|
+
Stock.new symbol: 'IBKR', exchange: 'ISLAND'
|
151
|
+
end
|
152
|
+
=begin
|
153
|
+
#! [stkcontract]
|
154
|
+
contract = Contract()
|
155
|
+
contract.symbol = "IBKR"
|
156
|
+
contract.secType = "STK"
|
157
|
+
contract.currency = "USD"
|
158
|
+
contract.exchange = "ISLAND"
|
159
|
+
=end
|
160
|
+
|
161
|
+
def rUSStockWithPrimaryExch
|
162
|
+
#Specify the Primary Exchange attribute to avoid contract ambiguity
|
163
|
+
#(there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
|
164
|
+
Stock.new symbol: 'MSFT', primary_exchange: 'ISLAND'
|
165
|
+
end
|
166
|
+
=begin
|
167
|
+
#! [stkcontractwithprimary]
|
168
|
+
contract = Contract()
|
169
|
+
contract.symbol = "MSFT"
|
170
|
+
contract.secType = "STK"
|
171
|
+
contract.currency = "USD"
|
172
|
+
contract.exchange = "SMART"
|
173
|
+
contract.primaryExchange = "ISLAND"
|
174
|
+
=end
|
175
|
+
|
176
|
+
def rUSStockAtSmart
|
177
|
+
Stock.new symbol: 'IBKR'
|
178
|
+
end
|
179
|
+
=begin
|
180
|
+
contract = Contract()
|
181
|
+
contract.symbol = "IBKR"
|
182
|
+
contract.secType = "STK"
|
183
|
+
contract.currency = "USD"
|
184
|
+
contract.exchange = "SMART"
|
185
|
+
return contract
|
186
|
+
=end
|
187
|
+
|
188
|
+
def rUSOptionContract
|
189
|
+
Option.new symbol: 'GOOG',
|
190
|
+
strike: 1100,
|
191
|
+
multiplier: 100,
|
192
|
+
right: :call,
|
193
|
+
expiry: Symbols::Futures.next_expiry
|
194
|
+
end
|
195
|
+
=begin
|
196
|
+
#! [optcontract_us]
|
197
|
+
contract = Contract()
|
198
|
+
contract.symbol = "GOOG"
|
199
|
+
contract.secType = "OPT"
|
200
|
+
contract.exchange = "SMART"
|
201
|
+
contract.currency = "USD"
|
202
|
+
contract.lastTradeDateOrContractMonth = "20170120"
|
203
|
+
contract.strike = 615
|
204
|
+
contract.right = "C"
|
205
|
+
contract.multiplier = "100"
|
206
|
+
=end
|
207
|
+
|
208
|
+
def rOptionAtBOX
|
209
|
+
Option.new symbol: 'GOOG',
|
210
|
+
strike: 1200,
|
211
|
+
multiplier: 100,
|
212
|
+
right: :call,
|
213
|
+
expiry: Symbols::Futures.next_expiry ,
|
214
|
+
exchange: 'BOX'
|
215
|
+
end
|
216
|
+
=begin
|
217
|
+
#! [optcontract]
|
218
|
+
contract = Contract()
|
219
|
+
contract.symbol = "GOOG"
|
220
|
+
contract.secType = "OPT"
|
221
|
+
contract.exchange = "BOX"
|
222
|
+
contract.currency = "USD"
|
223
|
+
contract.lastTradeDateOrContractMonth = "20170120"
|
224
|
+
contract.strike = 615
|
225
|
+
contract.right = "C"
|
226
|
+
contract.multiplier = "100"
|
227
|
+
=end
|
228
|
+
|
229
|
+
=begin
|
230
|
+
""" Option contracts require far more information since there are many
|
231
|
+
contracts having the exact same attributes such as symbol, currency,
|
232
|
+
strike, etc. This can be overcome by adding more details such as the
|
233
|
+
trading class"""
|
234
|
+
=end
|
235
|
+
def rOptionWithTradingClass
|
236
|
+
Option.new symbol: 'SANT',
|
237
|
+
exchange: "MEFFRV",
|
238
|
+
currency: "EUR",
|
239
|
+
expiry: Symbols::Futures.next_expiry,
|
240
|
+
strike: 7.5,
|
241
|
+
right: :call,
|
242
|
+
multiplier: 100,
|
243
|
+
trading_class: "SANEU"
|
244
|
+
end
|
245
|
+
=begin
|
246
|
+
#! [optcontract_tradingclass]
|
247
|
+
contract = Contract()
|
248
|
+
contract.symbol = "SANT"
|
249
|
+
contract.secType = "OPT"
|
250
|
+
contract.exchange = "MEFFRV"
|
251
|
+
contract.currency = "EUR"
|
252
|
+
contract.lastTradeDateOrContractMonth = "20190621"
|
253
|
+
contract.strike = 7.5
|
254
|
+
contract.right = "C"
|
255
|
+
contract.multiplier = "100"
|
256
|
+
contract.tradingClass = "SANEU"
|
257
|
+
=end
|
258
|
+
|
259
|
+
=begin
|
260
|
+
""" Using the contract's own symbol (localSymbol) can greatly simplify a
|
261
|
+
contract description """
|
262
|
+
=end
|
263
|
+
|
264
|
+
def rOptionWithLocalSymbol
|
265
|
+
#Watch out for the spaces within the local symbol!
|
266
|
+
Option.new local_symbol: "C DBK DEC 20 1600",
|
267
|
+
exchange: 'DTB',
|
268
|
+
currency: 'EUR'
|
269
|
+
end
|
270
|
+
=begin
|
271
|
+
#! [optcontract_localsymbol]
|
272
|
+
contract = Contract()
|
273
|
+
contract.localSymbol = "C DBK DEC 20 1600"
|
274
|
+
contract.secType = "OPT"
|
275
|
+
contract.exchange = "DTB"
|
276
|
+
contract.currency = "EUR"
|
277
|
+
=end
|
278
|
+
|
279
|
+
=begin
|
280
|
+
Dutch Warrants (IOPTs) can be defined using the local symbol or conid
|
281
|
+
=end
|
282
|
+
|
283
|
+
def rDutchWarrant
|
284
|
+
Contract.new sec_type: :dutch_option,
|
285
|
+
exchange: 'SBF',
|
286
|
+
currency: 'EUR',
|
287
|
+
local_symbol: 'B881G'
|
288
|
+
end
|
289
|
+
=begin
|
290
|
+
#! [ioptcontract]
|
291
|
+
contract = Contract()
|
292
|
+
contract.localSymbol = "B881G"
|
293
|
+
contract.secType = "IOPT"
|
294
|
+
contract.exchange = "SBF"
|
295
|
+
contract.currency = "EUR"
|
296
|
+
#! [ioptcontract]
|
297
|
+
return contract
|
298
|
+
=end
|
299
|
+
|
300
|
+
=begin
|
301
|
+
Future contracts also require an expiration date but are less
|
302
|
+
complicated than options.
|
303
|
+
=end
|
304
|
+
|
305
|
+
def rSimpleFuture
|
306
|
+
Future.new symbol: 'ES', exchange: 'GLOBEX',
|
307
|
+
expiry: Symbols::Futures.next_expiry,
|
308
|
+
currency: 'USD'
|
309
|
+
end
|
310
|
+
=begin
|
311
|
+
#! [futcontract]
|
312
|
+
contract = Contract()
|
313
|
+
contract.symbol = "ES"
|
314
|
+
contract.secType = "FUT"
|
315
|
+
contract.exchange = "GLOBEX"
|
316
|
+
contract.currency = "USD"
|
317
|
+
contract.lastTradeDateOrContractMonth = "201612"
|
318
|
+
=end
|
319
|
+
|
320
|
+
=begin
|
321
|
+
Rather than giving expiration dates we can also provide the local symbol
|
322
|
+
attributes such as symbol, currency, strike, etc.
|
323
|
+
=end
|
324
|
+
|
325
|
+
def rFutureWithLocalSymbol
|
326
|
+
Future.new symbol: 'ES', exchange: 'GLOBEX',
|
327
|
+
currency: 'USD',
|
328
|
+
local_symbol: 'ESU8'
|
329
|
+
end
|
330
|
+
=begin
|
331
|
+
#! [futcontract_local_symbol]
|
332
|
+
contract = Contract()
|
333
|
+
contract.secType = "FUT"
|
334
|
+
contract.exchange = "GLOBEX"
|
335
|
+
contract.currency = "USD"
|
336
|
+
contract.localSymbol = "ESU6"
|
337
|
+
=end
|
338
|
+
|
339
|
+
|
340
|
+
def rFutureWithMultiplier
|
341
|
+
Future.new symbol: 'DAX', exchange: 'DTB',
|
342
|
+
expiry: Symbols::Futures.next_expiry,
|
343
|
+
currency: 'EUR',
|
344
|
+
multiplier: 5
|
345
|
+
end
|
346
|
+
=begin
|
347
|
+
#! [futcontract_multiplier]
|
348
|
+
contract = Contract()
|
349
|
+
contract.symbol = "DAX"
|
350
|
+
contract.secType = "FUT"
|
351
|
+
contract.exchange = "DTB"
|
352
|
+
contract.currency = "EUR"
|
353
|
+
contract.lastTradeDateOrContractMonth = "201609"
|
354
|
+
contract.multiplier = "5"
|
355
|
+
=end
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
def rFuturesOnOptions
|
360
|
+
Contract.new sec_type: :future_option,
|
361
|
+
expiry: Symbols::Futures.next_expiry,
|
362
|
+
exchange: 'GLOBEX',
|
363
|
+
currency: 'USD',
|
364
|
+
strike: 1400,
|
365
|
+
right: :call,
|
366
|
+
multiplier: 250
|
367
|
+
end
|
368
|
+
=begin
|
369
|
+
#! [fopcontract]
|
370
|
+
contract = Contract()
|
371
|
+
contract.symbol = "SPX"
|
372
|
+
contract.secType = "FOP"
|
373
|
+
contract.exchange = "GLOBEX"
|
374
|
+
contract.currency = "USD"
|
375
|
+
contract.lastTradeDateOrContractMonth = "20180315"
|
376
|
+
contract.strike = 1025
|
377
|
+
contract.right = "C"
|
378
|
+
contract.multiplier = "250"
|
379
|
+
=end
|
380
|
+
|
381
|
+
=begin
|
382
|
+
It is also possible to define contracts based on their ISIN (IBKR STK sample).
|
383
|
+
=end
|
384
|
+
def rByISIN
|
385
|
+
Stock.new sec_id_type: 'ISIN', sec_id: "US45841N1072"
|
386
|
+
end
|
387
|
+
=begin
|
388
|
+
contract = Contract()
|
389
|
+
contract.secIdType = "ISIN"
|
390
|
+
contract.secId = "US45841N1072"
|
391
|
+
contract.exchange = "SMART"
|
392
|
+
contract.currency = "USD"
|
393
|
+
contract.secType = "STK"
|
394
|
+
=end
|
395
|
+
|
396
|
+
=begin
|
397
|
+
Or their conId (EUR.uSD sample).
|
398
|
+
Note: passing a contract containing the conId can cause problems if one of
|
399
|
+
the other provided attributes does not match 100% with what is in IB's
|
400
|
+
database. This is particularly important for contracts such as Bonds which
|
401
|
+
may change their description from one day to another.
|
402
|
+
If the conId is provided, it is best not to give too much information as
|
403
|
+
in the example below.
|
404
|
+
=end
|
405
|
+
|
406
|
+
def rByConId
|
407
|
+
Contract.new sec_type: :forex, con_id: 12087792, exchange: 'IDEALPRO'
|
408
|
+
end
|
409
|
+
=begin
|
410
|
+
contract = Contract()
|
411
|
+
contract.secType = "CASH"
|
412
|
+
contract.conId = 12087792
|
413
|
+
contract.exchange = "IDEALPRO"
|
414
|
+
=end
|
415
|
+
|
416
|
+
=begin
|
417
|
+
Ambiguous contracts are great to use with reqContractDetails. This way
|
418
|
+
you can query the whole option chain for an underlying. Bear in mind that
|
419
|
+
there are pacing mechanisms in place which will delay any further responses
|
420
|
+
from the TWS to prevent abuse.
|
421
|
+
=end
|
422
|
+
|
423
|
+
def rOptionForQuery
|
424
|
+
Option.new symbol: 'FISV'
|
425
|
+
end
|
426
|
+
=begin
|
427
|
+
#! [optionforquery]
|
428
|
+
contract = Contract()
|
429
|
+
contract.symbol = "FISV"
|
430
|
+
contract.secType = "OPT"
|
431
|
+
contract.exchange = "SMART"
|
432
|
+
contract.currency = "USD"
|
433
|
+
=end
|
434
|
+
# def rOptionComboContract
|
435
|
+
#
|
436
|
+
# Bag.new symbol: 'DBK', currency: 'EUR', exchange: 'DTB', legs:
|
437
|
+
# [ ComboLeg.new( con_id: 197397509 , action: :buy, exchange: 'DTB', ratio: 1), #DBK JUN 15 2018 C
|
438
|
+
# ComboLeg.new( con_id: 197397584, action: :sell, exchange: 'DTB', ratio: 1 ) ] #DBK JUN 15 2018 P
|
439
|
+
# end
|
440
|
+
|
441
|
+
=begin
|
442
|
+
contract = Contract()
|
443
|
+
contract.symbol = "DBK"
|
444
|
+
contract.secType = "BAG"
|
445
|
+
contract.currency = "EUR"
|
446
|
+
contract.exchange = "DTB"
|
447
|
+
|
448
|
+
leg1 = ComboLeg()
|
449
|
+
leg1.conId = 197397509 #DBK JUN 15 2018 C
|
450
|
+
leg1.ratio = 1
|
451
|
+
leg1.action = "BUY"
|
452
|
+
leg1.exchange = "DTB"
|
453
|
+
|
454
|
+
|
455
|
+
leg2 = ComboLeg()
|
456
|
+
leg2.conId = 197397584 #DBK JUN 15 2018 P
|
457
|
+
leg2.ratio = 1
|
458
|
+
leg2.action = "SELL"
|
459
|
+
leg2.exchange = "DTB"
|
460
|
+
|
461
|
+
contract.comboLegs = []
|
462
|
+
contract.comboLegs.append(leg1)
|
463
|
+
contract.comboLegs.append(leg2)
|
464
|
+
#! [bagoptcontract]
|
465
|
+
return contract
|
466
|
+
|
467
|
+
|
468
|
+
""" STK Combo contract
|
469
|
+
Leg 1: 43645865 - IBKR's STK
|
470
|
+
Leg 2: 9408 - McDonald's STK """
|
471
|
+
#=end
|
472
|
+
def rStockComboContract
|
473
|
+
Bag.new symbol: 'IBKR,MCD', currency: 'USD', legs:
|
474
|
+
[ ComboLeg.new( con_id: 43645865, action: :buy, ratio: 1), # IKBR STK
|
475
|
+
ComboLeg.new( con_id: 9408, action: :sell,ratio: 1 ) ] # MCD STK
|
476
|
+
end
|
477
|
+
#=begin
|
478
|
+
#! [bagstkcontract]
|
479
|
+
contract = Contract()
|
480
|
+
contract.symbol = "IBKR,MCD"
|
481
|
+
contract.secType = "BAG"
|
482
|
+
contract.currency = "USD"
|
483
|
+
contract.exchange = "SMART"
|
484
|
+
|
485
|
+
leg1 = ComboLeg()
|
486
|
+
leg1.conId = 43645865#IBKR STK
|
487
|
+
leg1.ratio = 1
|
488
|
+
leg1.action = "BUY"
|
489
|
+
leg1.exchange = "SMART"
|
490
|
+
|
491
|
+
leg2 = ComboLeg()
|
492
|
+
leg2.conId = 9408#MCD STK
|
493
|
+
leg2.ratio = 1
|
494
|
+
leg2.action = "SELL"
|
495
|
+
leg2.exchange = "SMART"
|
496
|
+
|
497
|
+
contract.comboLegs = []
|
498
|
+
contract.comboLegs.append(leg1)
|
499
|
+
contract.comboLegs.append(leg2)
|
500
|
+
#! [bagstkcontract]
|
501
|
+
return contract
|
502
|
+
=end
|
503
|
+
|
504
|
+
|
505
|
+
=begin
|
506
|
+
|
507
|
+
""" CBOE Volatility Index Future combo contract """
|
508
|
+
=end
|
509
|
+
# def rFutureComboContract
|
510
|
+
# Bag.new symbol: 'VIX', currency: 'USD', exchange: 'CFE', legs:
|
511
|
+
# [ ComboLeg.new( con_id: 256038899, action: :buy, exchange: 'CFE', ratio: 1), # VIX FUT 201708
|
512
|
+
# ComboLeg.new( con_id: 260564703, action: :sell, exchange: 'CFE', ratio: 1 ) ] # VIX FUT 201709
|
513
|
+
# end
|
514
|
+
=begin
|
515
|
+
#! [bagfutcontract]
|
516
|
+
contract = Contract()
|
517
|
+
contract.symbol = "VIX"
|
518
|
+
contract.secType = "BAG"
|
519
|
+
contract.currency = "USD"
|
520
|
+
contract.exchange = "CFE"
|
521
|
+
|
522
|
+
leg1 = ComboLeg()
|
523
|
+
leg1.conId = 256038899 # VIX FUT 201708
|
524
|
+
leg1.ratio = 1
|
525
|
+
leg1.action = "BUY"
|
526
|
+
leg1.exchange = "CFE"
|
527
|
+
|
528
|
+
leg2 = ComboLeg()
|
529
|
+
leg2.conId = 260564703 # VIX FUT 201709
|
530
|
+
leg2.ratio = 1
|
531
|
+
leg2.action = "SELL"
|
532
|
+
leg2.exchange = "CFE"
|
533
|
+
|
534
|
+
contract.comboLegs = []
|
535
|
+
contract.comboLegs.append(leg1)
|
536
|
+
contract.comboLegs.append(leg2)
|
537
|
+
#! [bagfutcontract]
|
538
|
+
return contract
|
539
|
+
|
540
|
+
=end
|
541
|
+
# def SmartFutureComboContract()
|
542
|
+
# Bag.new symbol: 'WTI', currency: 'USD', exchange: 'SMART', legs:
|
543
|
+
# [ ComboLeg.new( con_id: 55928698, action: :buy, exchange: 'IPE', ratio: 1), # WTI future June 2017
|
544
|
+
# ComboLeg.new( con_id: 55850663, action: :sell, exchange: 'IPE', ratio: 1 ) ] # COIL future June 2017
|
545
|
+
# end
|
546
|
+
=begin
|
547
|
+
#! [smartfuturespread]
|
548
|
+
contract = Contract()
|
549
|
+
contract.symbol = "WTI" # WTI,COIL spread. Symbol can be defined as first leg symbol ("WTI") or currency ("USD")
|
550
|
+
contract.secType = "BAG"
|
551
|
+
contract.currency = "USD"
|
552
|
+
contract.exchange = "SMART"
|
553
|
+
|
554
|
+
leg1 = ComboLeg()
|
555
|
+
leg1.conId = 55928698 # WTI future June 2017
|
556
|
+
leg1.ratio = 1
|
557
|
+
leg1.action = "BUY"
|
558
|
+
leg1.exchange = "IPE"
|
559
|
+
|
560
|
+
leg2 = ComboLeg()
|
561
|
+
leg2.conId = 55850663 # COIL future June 2017
|
562
|
+
leg2.ratio = 1
|
563
|
+
leg2.action = "SELL"
|
564
|
+
leg2.exchange = "IPE"
|
565
|
+
|
566
|
+
contract.comboLegs = []
|
567
|
+
contract.comboLegs.append(leg1)
|
568
|
+
contract.comboLegs.append(leg2)
|
569
|
+
#! [smartfuturespread]
|
570
|
+
return contract
|
571
|
+
=end
|
572
|
+
# def rInterCmdtyFuturesContract()
|
573
|
+
# Bag.new symbol: 'CL.BZ', currency: 'USD', exchange: 'NYMEX', legs:
|
574
|
+
# [ ComboLeg.new( con_id: 47207310, action: :buy, exchange: 'NYMEX', ratio: 1), # CL Dec'16 @NYMEX
|
575
|
+
# ComboLeg.new( con_id: 47195961, action: :sell, exchange: 'NYMEX', ratio: 1 ) ] # #BZ Dec'16 @NYMEX
|
576
|
+
# end
|
577
|
+
=begin
|
578
|
+
#! [intcmdfutcontract]
|
579
|
+
#
|
580
|
+
contract = Contract()
|
581
|
+
contract.symbol = "CL.BZ" #symbol is 'local symbol' of intercommodity spread.
|
582
|
+
contract.secType = "BAG"
|
583
|
+
contract.currency = "USD"
|
584
|
+
contract.exchange = "NYMEX"
|
585
|
+
|
586
|
+
leg1 = ComboLeg()
|
587
|
+
leg1.conId = 47207310 #CL Dec'16 @NYMEX
|
588
|
+
leg1.ratio = 1
|
589
|
+
leg1.action = "BUY"
|
590
|
+
leg1.exchange = "NYMEX"
|
591
|
+
|
592
|
+
leg2 = ComboLeg()
|
593
|
+
leg2.conId = 47195961 #BZ Dec'16 @NYMEX
|
594
|
+
leg2.ratio = 1
|
595
|
+
leg2.action = "SELL"
|
596
|
+
leg2.exchange = "NYMEX"
|
597
|
+
|
598
|
+
contract.comboLegs = []
|
599
|
+
contract.comboLegs.append(leg1)
|
600
|
+
contract.comboLegs.append(leg2)
|
601
|
+
#! [intcmdfutcontract]
|
602
|
+
return contract
|
603
|
+
|
604
|
+
|
605
|
+
@staticmethod
|
606
|
+
def NewsFeedForQuery():
|
607
|
+
#! [newsfeedforquery]
|
608
|
+
contract = Contract()
|
609
|
+
contract.secType = "NEWS"
|
610
|
+
contract.exchange = "BT" #Briefing Trader
|
611
|
+
#! [newsfeedforquery]
|
612
|
+
return contract
|
613
|
+
|
614
|
+
|
615
|
+
@staticmethod
|
616
|
+
def BTbroadtapeNewsFeed():
|
617
|
+
#! [newscontractbt]
|
618
|
+
contract = Contract()
|
619
|
+
contract.symbol = "BT:BT_ALL" #BroadTape All News
|
620
|
+
contract.secType = "NEWS"
|
621
|
+
contract.exchange = "BT" #Briefing Trader
|
622
|
+
#! [newscontractbt]
|
623
|
+
return contract
|
624
|
+
|
625
|
+
|
626
|
+
@staticmethod
|
627
|
+
def BZbroadtapeNewsFeed():
|
628
|
+
#! [newscontractbz]
|
629
|
+
contract = Contract()
|
630
|
+
contract.symbol = "BZ:BZ_ALL" #BroadTape All News
|
631
|
+
contract.secType = "NEWS"
|
632
|
+
contract.exchange = "BZ" #Benzinga Pro
|
633
|
+
#! [newscontractbz]
|
634
|
+
return contract
|
635
|
+
|
636
|
+
|
637
|
+
@staticmethod
|
638
|
+
def FLYbroadtapeNewsFeed():
|
639
|
+
#! [newscontractfly]
|
640
|
+
contract = Contract()
|
641
|
+
contract.symbol = "FLY:FLY_ALL" #BroadTape All News
|
642
|
+
contract.secType = "NEWS"
|
643
|
+
contract.exchange = "FLY" #Fly on the Wall
|
644
|
+
#! [newscontractfly]
|
645
|
+
return contract
|
646
|
+
|
647
|
+
|
648
|
+
@staticmethod
|
649
|
+
def MTbroadtapeNewsFeed():
|
650
|
+
#! [newscontractmt]
|
651
|
+
contract = Contract()
|
652
|
+
contract.symbol = "MT:MT_ALL" #BroadTape All News
|
653
|
+
contract.secType = "NEWS"
|
654
|
+
contract.exchange = "MT" #Midnight Trader
|
655
|
+
#! [newscontractmt]
|
656
|
+
return contract
|
657
|
+
|
658
|
+
@staticmethod
|
659
|
+
def ContFut():
|
660
|
+
#! [continuousfuturescontract]
|
661
|
+
contract = Contract()
|
662
|
+
contract.symbol = "ES"
|
663
|
+
contract.secType = "CONTFUT"
|
664
|
+
contract.exchange = "GLOBEX"
|
665
|
+
#! [continuousfuturescontract]
|
666
|
+
return contract
|
667
|
+
|
668
|
+
@staticmethod
|
669
|
+
def ContAndExpiringFut():
|
670
|
+
#! [contandexpiringfut]
|
671
|
+
contract = Contract()
|
672
|
+
contract.symbol = "ES"
|
673
|
+
contract.secType = "FUT+CONTFUT"
|
674
|
+
contract.exchange = "GLOBEX"
|
675
|
+
#! [contandexpiringfut]
|
676
|
+
return contract
|
677
|
+
|
678
|
+
@staticmethod
|
679
|
+
def JefferiesContract():
|
680
|
+
#! [jefferies_contract]
|
681
|
+
contract = Contract()
|
682
|
+
contract.symbol = "AAPL"
|
683
|
+
contract.secType = "STK"
|
684
|
+
contract.exchange = "JEFFALGO"
|
685
|
+
contract.currency = "USD"
|
686
|
+
#! [jefferies_contract]
|
687
|
+
return contract
|
688
|
+
|
689
|
+
@staticmethod
|
690
|
+
def CSFBContract():
|
691
|
+
#! [csfb_contract]
|
692
|
+
contract = Contract()
|
693
|
+
contract.symbol = "IBKR"
|
694
|
+
contract.secType = "STK"
|
695
|
+
contract.exchange = "CSFBALGO"
|
696
|
+
contract.currency = "USD"
|
697
|
+
#! [csfb_contract]
|
698
|
+
return contract
|
699
|
+
=end
|
700
|
+
|
701
|
+
end # module
|
702
|
+
|
703
|
+
## execute if called from OS
|
704
|
+
if $0 == __FILE__
|
705
|
+
|
706
|
+
mod_methods= ContractSamples.public_instance_methods
|
707
|
+
include ContractSamples
|
708
|
+
any_contracts = mod_methods.map do | method |
|
709
|
+
self.send( method )
|
710
|
+
end
|
711
|
+
puts "Defined Contracts:"
|
712
|
+
puts "------------------"
|
713
|
+
puts any_contracts.map.with_index{|x,i| i.to_s + ": " + mod_methods[i][1..-1] + "\t->" + x.to_human }.join( "\n" )
|
714
|
+
|
715
|
+
|
716
|
+
end
|