-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.py
224 lines (194 loc) · 6.12 KB
/
contract.py
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
#!/usr/bin/env python3
"""
Copyright (C) 2016 Interactive Brokers LLC. All rights reserved. This code is
subject to the terms and conditions of the IB API Non-Commercial License or the
IB API Commercial License, as applicable.
"""
"""
SAME_POS = open/close leg value is same as combo
OPEN_POS = open
CLOSE_POS = close
UNKNOWN_POS = unknown
"""
from object_implem import Object
(SAME_POS, OPEN_POS, CLOSE_POS, UNKNOWN_POS) = range(4)
class ComboLeg(Object):
def __init__(self):
self.conId = 0 # type: int
self.ratio = 0 # type: int
self.action = "" # BUY/SELL/SSHORT
self.exchange = ""
self.openClose = 0 # type: int; LegOpenClose enum values
# for stock legs when doing short sale
self.shortSaleSlot = 0
self.designatedLocation = ""
self.exemptCode = -1
# //operator ==()
# return (conId == other.conId &&
# ratio == other.ratio &&
# openClose == other.openClose &&
# shortSaleSlot == other.shortSaleSlot &&
# exemptCode == other.exemptCode &&
# action == other.action &&
# exchange == other.exchange &&
# designatedLocation == other.designatedLocation);
def __str__(self):
return ",".join((
str(self.conId),
str(self.ratio),
str(self.action),
str(self.exchange),
str(self.openClose),
str(self.shortSaleSlot),
str(self.designatedLocation),
str(self.exemptCode)))
class UnderComp(Object):
def __init__(self):
self.conId = 0 # type: int
self.delta = 0. # type: float
self.price = 0. # type: float
def __str__(self):
return ",".join((
str(self.conId),
str(self.delta),
str(self.price)))
class Contract(Object):
def __init__(self):
self.conId = 0
self.symbol = ""
self.secType = ""
self.lastTradeDateOrContractMonth = ""
self.strike = 0. # float !!
self.right = ""
self.multiplier = ""
self.exchange = ""
self.primaryExchange = "" # pick an actual (ie non-aggregate) exchange that the contract trades on. DO NOT SET TO SMART.
self.currency = ""
self.localSymbol = ""
self.tradingClass = ""
self.includeExpired = False
self.secIdType = "" # CUSIP;SEDOL;ISIN;RIC
self.secId = ""
#combos
self.comboLegsDescrip = "" # type: str; received in open order 14 and up for all combos
self.comboLegs = None # type: vector<ComboLeg>
self.underComp = None
def __str__(self):
s = ",".join((
str(self.conId),
str(self.symbol),
str(self.secType),
str(self.lastTradeDateOrContractMonth),
str(self.strike),
str(self.right),
str(self.multiplier),
str(self.exchange),
str(self.primaryExchange),
str(self.currency),
str(self.localSymbol),
str(self.tradingClass),
str(self.includeExpired),
str(self.secIdType),
str(self.secId)))
s += "combo:" + self.comboLegsDescrip
if self.comboLegs:
for leg in self.comboLegs:
s += ";" + str(leg)
if self.underComp:
s += ";" + str(self.underComp)
return s
class ContractDetails(Object):
def __init__(self):
self.summary = Contract()
self.marketName = ""
self.minTick = 0.
self.orderTypes = ""
self.validExchanges = ""
self.priceMagnifier = 0
self.underConId = 0
self.longName = ""
self.contractMonth = ""
self.industry = ""
self.category = ""
self.subcategory = ""
self.timeZoneId = ""
self.tradingHours = ""
self.liquidHours = ""
self.evRule = ""
self.evMultiplier = 0
self.secIdList = None
# BOND values
self.cusip = ""
self.ratings = ""
self.descAppend = ""
self.bondType = ""
self.couponType = ""
self.callable = False
self.putable = False
self.coupon = 0
self.convertible = False
self.maturity = ""
self.issueDate = ""
self.nextOptionDate = ""
self.nextOptionType = ""
self.nextOptionPartial = False
self.notes = ""
def __str__(self):
s = ",".join((
str(self.summary),
str(self.marketName),
str(self.minTick),
str(self.orderTypes),
str(self.validExchanges),
str(self.priceMagnifier),
str(self.underConId),
str(self.longName),
str(self.contractMonth),
str(self.industry),
str(self.category),
str(self.subcategory),
str(self.timeZoneId),
str(self.tradingHours),
str(self.liquidHours),
str(self.evRule),
str(self.evMultiplier),
str(self.secIdList),
str(self.cusip),
str(self.ratings),
str(self.descAppend),
str(self.bondType),
str(self.couponType),
str(self.callable),
str(self.putable),
str(self.coupon),
str(self.convertible),
str(self.maturity),
str(self.issueDate),
str(self.nextOptionDate),
str(self.nextOptionType),
str(self.nextOptionPartial),
str(self.notes)))
return s
class ContractDescription(Object):
def __init__(self):
self.contract = Contract()
self.derivativeSecTypes = None # type: vector<std::string>
#inline void
#Contract::CloneComboLegs(ComboLegListSPtr& dst, const ComboLegListSPtr& src)
#{
# if (!src.get())
# return;
#
# dst->reserve(src->size());
#
# ComboLegList::const_iterator iter = src->begin();
# const ComboLegList::const_iterator iterEnd = src->end();
#
# for (; iter != iterEnd; ++iter) {
# const ComboLeg* leg = iter->get();
# if (!leg)
# continue;
# dst->push_back(ComboLegSPtr(new ComboLeg(*leg)));
# }
#}
#