-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontract_samples.go
774 lines (600 loc) · 16.3 KB
/
contract_samples.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
package ibapi
/*
Contracts can be defined in multiple ways. The TWS/IB Gateway will always perform a query on the available contracts
and find which one is the best candidate:
- More than a single candidate will yield an ambiguity error message.
- No suitable candidates will produce a "contract not found" message.
How do I find my contract though?
- Often the quickest way is by looking for it in the TWS and looking at its description there (double click).
- The TWS' symbol corresponds to the API's localSymbol. Keep this in mind when defining Futures or Options.
- The TWS' underlying's symbol can usually be mapped to the API's symbol.
Any stock or option symbols displayed are for illustrative purposes only and are not intended to portray a recommendation.
Usually, the easiest way to define a Stock/CASH contract is through these four attributes.
*/
// IBMBond .
func IBMBond() *Contract {
contract := NewContract()
contract.Symbol = "IBM"
contract.SecType = "BOND"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// IBKRStk .
func IBKRStk() *Contract {
contract := NewContract()
contract.Symbol = "IBKR"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// HKStk
func HKStk() *Contract {
contract := NewContract()
contract.Symbol = "1"
contract.SecType = "STK"
contract.Currency = "HKD"
contract.Exchange = "SEHK"
return contract
}
// EurGbpFx .
func EurGbpFx() *Contract {
contract := NewContract()
contract.Symbol = "EUR"
contract.SecType = "CASH"
contract.Currency = "GBP"
contract.Exchange = "IDEALPRO"
return contract
}
// Index .
func Index() *Contract {
contract := NewContract()
contract.Symbol = "DAX"
contract.SecType = "IND"
contract.Currency = "EUR"
contract.Exchange = "EUREX"
return contract
}
// CFD .
func CFD() *Contract {
contract := NewContract()
contract.Symbol = "IBDE30"
contract.SecType = "CFD"
contract.Currency = "EUR"
contract.Exchange = "SMART"
return contract
}
// USStockCFD .
func USStockCFD() *Contract {
contract := NewContract()
contract.Symbol = "IBM"
contract.SecType = "CFD"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// EuropeanStockCFD .
func EuropeanStockCFD() *Contract {
contract := NewContract()
contract.Symbol = "BMW"
contract.SecType = "CFD"
contract.Currency = "EUR"
contract.Exchange = "SMART"
return contract
}
// CashCFD .
func CashCFD() *Contract {
contract := NewContract()
contract.Symbol = "EUR"
contract.SecType = "CFD"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// EuropeanStock .
func EuropeanStock() *Contract {
contract := NewContract()
contract.Symbol = "NOKIA"
contract.SecType = "STK"
contract.Currency = "EUR"
contract.Exchange = "SMART"
contract.PrimaryExchange = "HEX"
return contract
}
// OptionAtIse .
func OptionAtIse() *Contract {
contract := NewContract()
contract.Symbol = "BPX"
contract.SecType = "OPT"
contract.Currency = "USD"
contract.Exchange = "ISE"
contract.LastTradeDateOrContractMonth = "20160916"
contract.Right = "C"
contract.Strike = 65
contract.Multiplier = "100"
return contract
}
// USStock .
func USStock() *Contract {
contract := NewContract()
contract.Symbol = "SPY"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "ARCA"
return contract
}
// ETF .
func ETF() *Contract {
contract := NewContract()
contract.Symbol = "QQQ"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// USStockAtSmart .
func USStockAtSmart() *Contract {
contract := NewContract()
contract.Symbol = "IBM"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// IBMUSStockAtSmart .
func IBMUSStockAtSmart() *Contract {
contract := NewContract()
contract.Symbol = "IBM"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "SMART"
return contract
}
// USStockWithPrimaryExch .
func USStockWithPrimaryExch() *Contract {
contract := NewContract()
contract.Symbol = "SPY"
contract.SecType = "STK"
contract.Currency = "USD"
contract.Exchange = "SMART"
contract.PrimaryExchange = "ARCA"
return contract
}
// BondWithCusip .
func BondWithCusip() *Contract {
contract := NewContract()
// enter CUSIP as symbol
contract.Symbol = "449276AA2"
contract.SecType = "BOND"
contract.Exchange = "SMART"
contract.Currency = "USD"
return contract
}
// Bond .
func Bond() *Contract {
contract := NewContract()
contract.ConID = 456467716
contract.Exchange = "SMART"
return contract
}
// MutualFund .
func MutualFund() *Contract {
contract := NewContract()
contract.Symbol = "VINIX"
contract.SecType = "FUND"
contract.Exchange = "FUNDSERV"
contract.Currency = "USD"
return contract
}
// Commodity
func Commodity() *Contract {
contract := NewContract()
contract.Symbol = "XAUUSD"
contract.SecType = "CMDTY"
contract.Exchange = "SMART"
contract.Currency = "USD"
return contract
}
// USOptionContract .
func USOptionContract() *Contract {
contract := NewContract()
contract.Symbol = "GOOG"
contract.SecType = "OPT"
contract.Exchange = "SMART"
contract.Currency = "USD"
contract.LastTradeDateOrContractMonth = "20170120"
contract.Strike = 615
contract.Right = "C"
contract.Multiplier = "100"
return contract
}
// OptionAtBox
func OptionAtBox() *Contract {
contract := NewContract()
contract.Symbol = "GOOG"
contract.SecType = "OPT"
contract.Exchange = "BOX"
contract.Currency = "USD"
contract.LastTradeDateOrContractMonth = "20170120"
contract.Strike = 615
contract.Right = "C"
contract.Multiplier = "100"
return contract
}
// OptionWithTradingClass .
// Option contracts require far more information since there are many contracts having the exact same
// attributes such as symbol, currency, strike, etc.
func OptionWithTradingClass() *Contract {
contract := NewContract()
contract.Symbol = "SANT"
contract.SecType = "OPT"
contract.Exchange = "MEFFRV"
contract.Currency = "EUR"
contract.LastTradeDateOrContractMonth = "20190621"
contract.Strike = 7.5
contract.Right = "C"
contract.Multiplier = "100"
contract.TradingClass = "SANEU"
return contract
}
// OptionWithLocalSymbol .
// Using the contract's own symbol (localSymbol) can greatly simplify a contract description
func OptionWithLocalSymbol() *Contract {
contract := NewContract()
//Watch out for the spaces within the local symbol!
contract.LocalSymbol = "P BMW 20221216 72 M"
contract.SecType = "OPT"
contract.Exchange = "EUREX"
contract.Currency = "EUR"
//! [optcontract_localsymbol]
return contract
}
// DutchWarrant .
// Dutch Warrants (IOPTs) can be defined using the local symbol or conid
func DutchWarrant() *Contract {
contract := NewContract()
contract.LocalSymbol = "B881G"
contract.SecType = "IOPT"
contract.Exchange = "SBF"
contract.Currency = "EUR"
return contract
}
// SimpleFuture .
// Future contracts also require an expiration date but are less complicated than options.
func SimpleFuture() *Contract {
contract := NewContract()
contract.Symbol = "ES"
contract.SecType = "FUT"
contract.Exchange = "CME"
contract.Currency = "USD"
contract.LastTradeDateOrContractMonth = "202503"
return contract
}
// FutureWithLocalSymbol .
// Rather than giving expiration dates we can also provide the local symbol
// attributes such as symbol, currency, strike, etc.
func FutureWithLocalSymbol() *Contract {
contract := NewContract()
contract.SecType = "FUT"
contract.Exchange = "EUREX"
contract.Currency = "EUR"
contract.LocalSymbol = "FGBL MAR 23"
return contract
}
// FutureWithMultiplier .
func FutureWithMultiplier() *Contract {
contract := NewContract()
contract.Symbol = "DAX"
contract.SecType = "FUT"
contract.Exchange = "EUREX"
contract.Currency = "EUR"
contract.LastTradeDateOrContractMonth = "202303"
contract.Multiplier = "1"
return contract
}
// WrongContract .
// Note the space in the symbol!
func WrongContract() *Contract {
contract := NewContract()
contract.Symbol = " IJR "
contract.ConID = 9579976
contract.SecType = "STK"
contract.Exchange = "SMART"
contract.Currency = "USD"
return contract
}
// FuturesOnOptions .
func FuturesOnOptions() *Contract {
contract := NewContract()
contract.Symbol = "GBL"
contract.SecType = "FOP"
contract.Exchange = "EUREX"
contract.Currency = "EUR"
contract.LastTradeDateOrContractMonth = "20230224"
contract.Strike = 138
contract.Right = "C"
contract.Multiplier = "1000"
return contract
}
// Warrants .
func Warrants() *Contract {
contract := NewContract()
contract.Symbol = "GOOG"
contract.SecType = "WAR"
contract.Exchange = "FWB"
contract.Currency = "EUR"
contract.LastTradeDateOrContractMonth = "20201117"
contract.Strike = 1500.0
contract.Right = "C"
contract.Multiplier = "0.01"
return contract
}
// ByISIN .
// It is also possible to define contracts based on their ISIN (IBKR STK sample).
func ByISIN() *Contract {
contract := NewContract()
contract.SecIDType = "ISIN"
contract.SecID = "US45841N1072"
contract.Exchange = "SMART"
contract.Currency = "USD"
contract.SecType = "STK"
return contract
}
// ByConId .
// It is also possible to define contracts based on their ConID (EUR.USD sample).
// Note: passing a contract containing the conId can cause problems if one of the other provided
// attributes does not match 100% with what is in IB's database. This is particularly important
// for contracts such as Bonds which may change their description from one day to another.
// If the conId is provided, it is best not to give too much information as in the example below.
func ByConId() *Contract {
contract := NewContract()
contract.ConID = 12087792
contract.Exchange = "IDEALPRO"
contract.SecType = "CASH"
return contract
}
// OptionForQuery .
// Ambiguous contracts are great to use with reqContractDetails. This way you can
// query the whole option chain for an underlying. Bear in mind that there are
// pacing mechanisms in place which will delay any further responses from the TWS
// to prevent abuse.
func OptionForQuery() *Contract {
contract := NewContract()
contract.Symbol = "FISV"
contract.SecType = "OPT"
contract.Exchange = "SMART"
contract.Currency = "USD"
return contract
}
// OptionComboContract .
func OptionComboContract() *Contract {
contract := NewContract()
contract.Symbol = "DBK"
contract.SecType = "BAG"
contract.Currency = "EUR"
contract.Exchange = "EUREX"
leg1 := NewComboLeg()
leg1.ConID = 577164786 //DBK Jun21'24 CALL @EUREX
leg1.Action = "BUY"
leg1.Ratio = 1
leg1.Exchange = "EUREX"
leg2 := NewComboLeg()
leg2.ConID = 577164767 //DBK Dec15'23 CALL @EUREX
leg2.Action = "SELL"
leg2.Ratio = 1
leg2.Exchange = "EUREX"
contract.ComboLegs = []ComboLeg{}
contract.ComboLegs = append(contract.ComboLegs, leg1)
contract.ComboLegs = append(contract.ComboLegs, leg2)
return contract
}
// StockComboContract .
// STK Combo contract
// Leg 1: 43645865 - IBKR's STK
// Leg 2: 9408 - McDonald's STK
func StockComboContract() *Contract {
contract := NewContract()
contract.Symbol = "MCD"
contract.SecType = "BAG"
contract.Currency = "USD"
contract.Exchange = "SMART"
leg1 := NewComboLeg()
leg1.ConID = 43645865
leg1.Action = "BUY"
leg1.Ratio = 1
leg1.Exchange = "SMART"
leg2 := NewComboLeg()
leg2.ConID = 9408
leg2.Action = "SELL"
leg2.Ratio = 1
leg2.Exchange = "SMART"
contract.ComboLegs = []ComboLeg{}
contract.ComboLegs = append(contract.ComboLegs, leg1)
contract.ComboLegs = append(contract.ComboLegs, leg2)
return contract
}
// FutureComboContract .
// CBOE Volatility Index Future combo contract
// Leg 1: 195538625 - FUT expiring 2016/02/17
// Leg 2: 197436571 - FUT expiring 2016/03/16
func FutureComboContract() *Contract {
contract := NewContract()
contract.Symbol = "VIX"
contract.SecType = "BAG"
contract.Currency = "USD"
contract.Exchange = "CFE"
leg1 := NewComboLeg()
leg1.ConID = 195538625
leg1.Action = "BUY"
leg1.Ratio = 1
leg1.Exchange = "CFE"
leg2 := NewComboLeg()
leg2.ConID = 197436571
leg2.Action = "SELL"
leg2.Ratio = 1
leg2.Exchange = "CFE"
contract.ComboLegs = []ComboLeg{}
contract.ComboLegs = append(contract.ComboLegs, leg1)
contract.ComboLegs = append(contract.ComboLegs, leg2)
return contract
}
// SmartFutureComboContract .
func SmartFutureComboContract() *Contract {
contract := NewContract()
contract.Symbol = "WTI" // WTI,COIL spread. Symbol can be defined as first leg symbol ("WTI") or currency ("USD").
contract.SecType = "BAG"
contract.Currency = "USD"
contract.Exchange = "SMART"
leg1 := NewComboLeg()
leg1.ConID = 55928698 // WTI future June 2017
leg1.Action = "BUY"
leg1.Ratio = 1
leg1.Exchange = "IPE"
leg2 := NewComboLeg()
leg2.ConID = 55850663 // COIL future June 2017
leg2.Action = "SELL"
leg2.Ratio = 1
leg2.Exchange = "IPE"
contract.ComboLegs = []ComboLeg{}
contract.ComboLegs = append(contract.ComboLegs, leg1)
contract.ComboLegs = append(contract.ComboLegs, leg2)
return contract
}
// InterCmdtyFuturesContract .
func InterCmdtyFuturesContract() *Contract {
contract := NewContract()
contract.Symbol = "COIL.WTI"
contract.SecType = "BAG"
contract.Currency = "USD"
contract.Exchange = "IPE"
leg1 := NewComboLeg()
leg1.ConID = 183405603 //WTI Dec'23 @IPE
leg1.Action = "BUY"
leg1.Ratio = 1
leg1.Exchange = "IPE"
leg2 := NewComboLeg()
leg2.ConID = 254011009 //COIL Dec'23 @IPE
leg2.Action = "SELL"
leg2.Ratio = 1
leg2.Exchange = "IPE"
contract.ComboLegs = []ComboLeg{}
contract.ComboLegs = append(contract.ComboLegs, leg1)
contract.ComboLegs = append(contract.ComboLegs, leg2)
return contract
}
// NewsFeedForQuery .
func NewsFeedForQuery() *Contract {
contract := NewContract()
contract.SecType = "NEWS"
contract.Exchange = "BRF" //Briefing Trader
return contract
}
// BTbroadtapeNewsFeed .
func BTbroadtapeNewsFeed() *Contract {
contract := NewContract()
contract.Symbol = "BRF:BRF_ALL" //BroadTape All News
contract.SecType = "NEWS"
contract.Exchange = "BRF" //Briefing Trader
return contract
}
// BZbroadtapeNewsFeed .
func BZbroadtapeNewsFeed() *Contract {
contract := NewContract()
contract.Symbol = "BZ:BZ_ALL" //BroadTape All News
contract.SecType = "NEWS"
contract.Exchange = "BZ" //Benzinga Pro
return contract
}
// FLYbroadtapeNewsFeed .
func FLYbroadtapeNewsFeed() *Contract {
contract := NewContract()
contract.Symbol = "FLY:FLY_ALL" //BroadTape All News
contract.SecType = "NEWS"
contract.Exchange = "FLY" //Fly on the Wall
return contract
}
// ContFut .
func ContFut() *Contract {
contract := NewContract()
contract.Symbol = "GBL"
contract.SecType = "CONTFUT"
contract.Exchange = "EUREX"
return contract
}
// ContAndExpiringFut .
func ContAndExpiringFut() *Contract {
contract := NewContract()
contract.Symbol = "GBL"
contract.SecType = "FUT+CONTFUT"
contract.Exchange = "EUREX"
return contract
}
// JefferiesContract .
func JefferiesContract() *Contract {
contract := NewContract()
contract.Symbol = "AAPL"
contract.SecType = "STK"
contract.Exchange = "JEFFALGO" // must be direct-routed to JEFALGO
contract.Currency = "USD" // only available for US stocks
return contract
}
// CSFBContract .
func CSFBContract() *Contract {
contract := NewContract()
contract.Symbol = "IBKR"
contract.SecType = "STK"
contract.Exchange = "CSFBALGO"
contract.Currency = "USD"
return contract
}
// IBKRATSContract .
func IBKRATSContract() *Contract {
contract := NewContract()
contract.Symbol = "SPY"
contract.SecType = "STK"
contract.Exchange = "IBKRATS"
contract.Currency = "USD"
return contract
}
// CryptoContract .
func CryptoContract() *Contract {
contract := NewContract()
contract.Symbol = "BTC"
contract.SecType = "CRYPTO"
contract.Exchange = "PAXOS"
contract.Currency = "USD"
return contract
}
// StockWithIPOPrice .
func StockWithIPOPrice() *Contract {
contract := NewContract()
contract.Symbol = "EMCGU"
contract.SecType = "STK"
contract.Exchange = "SMART"
contract.Currency = "USD"
return contract
}
// ByFIGI .
func ByFIGI() *Contract {
contract := NewContract()
contract.SecIDType = "FIGI"
contract.SecID = "BBG000B9XRY4"
contract.Exchange = "SMART"
return contract
}
// ByIssuerId .
func ByIssuerId() *Contract {
contract := NewContract()
contract.IssuerID = "e1453318"
return contract
}
// Fund .
func Fund() *Contract {
contract := NewContract()
contract.Symbol = "I406801954"
contract.SecType = "FUND"
contract.Exchange = "ALLFUNDS"
contract.Currency = "USD"
return contract
}