-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
317 lines (265 loc) · 6.68 KB
/
common.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
package ibsync
import (
"fmt"
"strings"
"time"
)
type AccountValue struct {
Account string
Tag string
Value string
Currency string
}
type AccountValues []AccountValue
func (avs AccountValues) String() string {
ss := make(map[string]string)
var dots string
for _, av := range avs {
dots = strings.Repeat(".", 40-len(av.Tag)-len(av.Value))
ss[av.Account] = ss[av.Account] + fmt.Sprintf("\t%v%v%v %v\n", av.Tag, dots, av.Value, av.Currency)
}
s := "\n"
for k, v := range ss {
s = s + fmt.Sprintf("Account: %v\n", k)
s = s + v
}
return s
}
type AccountSummary []AccountValue
func (as AccountSummary) String() string {
return fmt.Sprint(AccountValues(as))
}
type ReceiveFA struct {
FaDataType FaDataType
Cxml string
}
type TickData struct {
Time time.Time
TickType TickType
Price float64
Size Decimal
}
type Tick interface {
Type() TickType
String() string
}
type TickPrice struct {
TickType TickType
Price float64
Attrib TickAttrib
}
func (t TickPrice) Type() TickType {
return t.TickType
}
func (t TickPrice) String() string {
return fmt.Sprintf("<%v> price:%v, attrib:%v", TickName(t.TickType), t.Price, t.Attrib)
}
type TickSize struct {
TickType TickType
Size Decimal
}
func (t TickSize) Type() TickType {
return t.TickType
}
func (t TickSize) String() string {
return fmt.Sprintf("<%v> size:%v", TickName(t.TickType), t.Size)
}
type TickOptionComputation struct {
TickType TickType
TickAttrib int64
ImpliedVol float64
Delta float64
OptPrice float64
PvDividend float64
Gamma float64
Vega float64
Theta float64
UndPrice float64
}
func (t TickOptionComputation) Type() TickType {
return t.TickType
}
func (t TickOptionComputation) String() string {
return fmt.Sprintf("<%v> tickAttrib:%v, impliedVol:%v, delta:%v, optPrice:%v, pvDividend: %v, gamma:%v, vega:%v, theta:%v, undPrice:%v",
TickName(t.TickType), t.TickAttrib, t.ImpliedVol, t.Delta, t.OptPrice, t.PvDividend, t.Gamma, t.Vega, t.Theta, t.UndPrice)
}
type TickGeneric struct {
TickType TickType
Value float64
}
func (t TickGeneric) Type() TickType {
return t.TickType
}
func (t TickGeneric) String() string {
return fmt.Sprintf("<%v> value:%v", TickName(t.TickType), t.Value)
}
type TickString struct {
TickType TickType
Value string
}
func (t TickString) Type() TickType {
return t.TickType
}
func (t TickString) String() string {
return fmt.Sprintf("<%v> value:%v", TickName(t.TickType), t.Value)
}
type TickEFP struct {
TickType TickType
BasisPoints float64
FormattedBasisPoints string
TotalDividends float64
HoldDays int64
FutureLastTradeDate string
DividendImpact float64
DividendsToLastTradeDate float64
}
func (t TickEFP) Type() TickType {
return t.TickType
}
func (t TickEFP) String() string {
return fmt.Sprintf("<%v> basisPoints:%v, formattedBasisPoints:%v, totalDividends:%v, holdDays:%v, futureLastTradeDate:%v, dividendImpact:%v, dividendsToLastTradeDate:%v",
TickName(t.TickType), t.BasisPoints, t.FormattedBasisPoints, t.TotalDividends, t.HoldDays, t.FutureLastTradeDate, t.DividendImpact, t.DividendsToLastTradeDate)
}
// TickByTick
type TickByTick interface {
Timestamp() time.Time
String() string
}
type TickByTickAllLast struct {
Time int64
TickType int64
Price float64
Size Decimal
TickAttribLast TickAttribLast
Exchange string
SpecialConditions string
}
func (t TickByTickAllLast) Timestamp() time.Time {
return time.Unix(t.Time, 0)
}
func (t TickByTickAllLast) String() string {
return fmt.Sprintf("<TickByTickAllLast> timestamp:%v, tickType:%v, price:%v, size:%v, tickAttribLast:%v, exchange:%v, specialConditions:%v",
t.Timestamp(), t.TickType, t.Price, t.Size, t.TickAttribLast, t.Exchange, t.SpecialConditions)
}
type TickByTickBidAsk struct {
Time int64
BidPrice float64
AskPrice float64
BidSize Decimal
AskSize Decimal
TickAttribBidAsk TickAttribBidAsk
}
func (t TickByTickBidAsk) Timestamp() time.Time {
return time.Unix(t.Time, 0)
}
func (t TickByTickBidAsk) String() string {
return fmt.Sprintf("<TickByTickBidAsk> timestamp:%v, bidPrice:%v, askPrice:%v, bidSize:%v, askSize:%v, tickAttribBidAsk:%v",
t.Timestamp(), t.BidPrice, t.AskPrice, t.BidSize, t.AskSize, t.TickAttribBidAsk)
}
type TickByTickMidPoint struct {
Time int64
MidPoint float64
}
func (t TickByTickMidPoint) Timestamp() time.Time {
return time.Unix(t.Time, 0)
}
func (t TickByTickMidPoint) String() string {
return fmt.Sprintf("<TickByTickMidPoint> timestamp:%v, midPoint:%v", t.Timestamp(), t.MidPoint)
}
type MktDepthData struct {
Time time.Time
Position int64
MarketMaker string
Operation int64
Side int64
Price float64
Size Decimal
IsSmartDepth bool
}
// DOMLevel represents a single level in the order book
type DOMLevel struct {
Price float64
Size Decimal
MarketMaker string
}
// String provides a readable representation of a DOM level
func (dl DOMLevel) String() string {
return fmt.Sprintf("Price: %v, Size: %v, Market Maker: %s", dl.Price, dl.Size, dl.MarketMaker)
}
type Dividends struct {
Past12Months float64
Next12Months float64
NextDate time.Time
NextAmount float64
}
type NewsArticle struct {
ArticleType int64
ArticleText string
}
type HistoricalNews struct {
Time time.Time
ProviderCode string
ArticleID string
Headline string
}
type NewsTick struct {
TimeStamp int64
ProviderCode string
ArticleId string
Headline string
ExtraData string
}
type NewsBulletin struct {
MsgID int64
MsgType int64
NewsMessage string
OriginExch string
}
type PortfolioItem struct {
Contract *Contract
Position Decimal
MarketPrice float64
MarketValue float64
AverageCost float64
UnrealizedPNL float64
RealizedPNL float64
Account string
}
type Position struct {
Account string
Contract *Contract
Position Decimal
AvgCost float64
}
type Pnl struct {
Account string
ModelCode string
DailyPNL float64
UnrealizedPnl float64
RealizedPNL float64
}
type PnlSingle struct {
Account string
ModelCode string
ConID int64
Position Decimal
DailyPNL float64
UnrealizedPnl float64
RealizedPNL float64
Value float64
}
type HistoricalSchedule struct {
StartDateTime string
EndDateTime string
TimeZone string
Sessions []HistoricalSession
}
type OptionChain struct {
Exchange string
UnderlyingConId int64
TradingClass string
Multiplier string
Expirations []string
Strikes []float64
}
type FundamentalRatios map[string]float64