-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.go
353 lines (293 loc) · 7.75 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
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
package ibapi
import (
"fmt"
"math"
"time"
)
const (
UNSET_INT int64 = math.MaxInt32
UNSET_LONG int64 = math.MaxInt64
UNSET_FLOAT float64 = math.MaxFloat64
INFINITY_STRING string = "Infinity"
)
var INFINITY_FLOAT float64 = math.Inf(1)
type TickerID = int64
type OrderID = int64
type FaDataType int64
const (
GROUPS FaDataType = 1
ALIASES FaDataType = 3
)
func (fa FaDataType) String() string {
switch fa {
case GROUPS:
return "GROUPS"
case ALIASES:
return "ALIASES"
default:
return ""
}
}
type MarketDataType int64
const (
REALTIME MarketDataType = 1
FROZEN MarketDataType = 2
DELAYED MarketDataType = 3
DELAYED_FROZEN MarketDataType = 4
)
func (mdt MarketDataType) String() string {
switch mdt {
case REALTIME:
return "REALTIME"
case FROZEN:
return "FROZEN"
case DELAYED:
return "DELAYED"
case DELAYED_FROZEN:
return "DELAYED_FROZEN"
}
return ""
}
// Bar .
type Bar struct {
Date string
Open float64
High float64
Low float64
Close float64
Volume Decimal
Wap Decimal
BarCount int64
}
func NewBar() Bar {
b := Bar{}
b.Volume = UNSET_DECIMAL
b.Wap = UNSET_DECIMAL
return b
}
func (b Bar) String() string {
return fmt.Sprintf("Date: %s, Open: %f, High: %f, Low: %f, Close: %f, Volume: %s, WAP: %s, BarCount: %d",
b.Date, b.Open, b.High, b.Low, b.Close, DecimalMaxString(b.Volume), DecimalMaxString(b.Wap), b.BarCount)
}
// RealTimeBar .
type RealTimeBar struct {
Time int64
EndTime int64
Open float64
High float64
Low float64
Close float64
Volume Decimal
Wap Decimal
Count int64
}
func NewRealTimeBar() RealTimeBar {
rtb := RealTimeBar{}
rtb.Volume = UNSET_DECIMAL
rtb.Wap = UNSET_DECIMAL
return rtb
}
func (rb RealTimeBar) String() string {
return fmt.Sprintf("Time: %d, Open: %f, High: %f, Low: %f, Close: %f, Volume: %s, Wap: %s, Count: %d",
rb.Time, rb.Open, rb.High, rb.Low, rb.Close, DecimalMaxString(rb.Volume), DecimalMaxString(rb.Wap), rb.Count)
}
// HistogramData .
type HistogramData struct {
Price float64
Size Decimal
}
func NewHistogramData() HistogramData {
hd := HistogramData{}
hd.Size = UNSET_DECIMAL
return hd
}
func (hd HistogramData) String() string {
return fmt.Sprintf("Price: %v, Size: %v", hd.Price, hd.Size)
}
// NewsProvider .
type NewsProvider struct {
Code string
Name string
}
func NewNewsProvider() NewsProvider {
return NewsProvider{}
}
func (np NewsProvider) String() string {
return fmt.Sprintf("Code: %s, Name: %s", np.Code, np.Name)
}
// DepthMktDataDescription .
type DepthMktDataDescription struct {
Exchange string
SecType string
ListingExch string
ServiceDataType string
AggGroup int64
}
func NewDepthMktDataDescription() DepthMktDataDescription {
dmdd := DepthMktDataDescription{}
dmdd.AggGroup = UNSET_INT
return dmdd
}
// DepthMktDataDescription .
func (d DepthMktDataDescription) String() string {
return fmt.Sprintf("Exchange: %s, SecType: %s, ListingExchange: %s, ServiceDataType: %s, AggGroup: %s",
d.Exchange, d.SecType, d.ListingExch, d.ServiceDataType, IntMaxString(d.AggGroup))
}
// SmartComponent .
type SmartComponent struct {
BitNumber int64
Exchange string
ExchangeLetter string
}
func NewSmartComponent() SmartComponent {
return SmartComponent{}
}
func (s SmartComponent) String() string {
return fmt.Sprintf("BitNumber: %d, Exchange: %s, ExchangeLetter: %s", s.BitNumber, s.Exchange, s.ExchangeLetter)
}
// TickAttrib .
type TickAttrib struct {
CanAutoExecute bool
PastLimit bool
PreOpen bool
}
func NewTickAttrib() TickAttrib {
return TickAttrib{}
}
func (t TickAttrib) String() string {
return fmt.Sprintf("CanAutoExecute: %t, PastLimit: %t, PreOpen: %t", t.CanAutoExecute, t.PastLimit, t.PreOpen)
}
// TickAttribBidAsk .
type TickAttribBidAsk struct {
BidPastLow bool
AskPastHigh bool
}
func NewTickAttribBidAsk() TickAttribBidAsk {
return TickAttribBidAsk{}
}
func (t TickAttribBidAsk) String() string {
return fmt.Sprintf("BidPastLow: %t, AskPastHigh: %t", t.BidPastLow, t.AskPastHigh)
}
// TickAttribLast .
type TickAttribLast struct {
PastLimit bool
Unreported bool
}
func NewTickAttribLast() TickAttribLast {
return TickAttribLast{}
}
func (t TickAttribLast) String() string {
return fmt.Sprintf("PastLimit: %t, Unreported: %t", t.PastLimit, t.Unreported)
}
// FamilyCode .
type FamilyCode struct {
AccountID string
FamilyCodeStr string
}
func NewFamilyCode() FamilyCode {
return FamilyCode{}
}
func (f FamilyCode) String() string {
return fmt.Sprintf("AccountId: %s, FamilyCodeStr: %s", f.AccountID, f.FamilyCodeStr)
}
// PriceIncrement .
type PriceIncrement struct {
LowEdge float64
Increment float64
}
func NewPriceIncrement() PriceIncrement {
return PriceIncrement{}
}
func (p PriceIncrement) String() string {
return fmt.Sprintf("LowEdge: %f, Increment: %f", p.LowEdge, p.Increment)
}
// HistoricalTick is the historical tick's description.
// Used when requesting historical tick data with whatToShow = MIDPOINT.
type HistoricalTick struct {
Time int64
Price float64
Size Decimal
}
func NewHistoricalTick() HistoricalTick {
ht := HistoricalTick{}
ht.Size = UNSET_DECIMAL
return ht
}
func (h HistoricalTick) String() string {
return fmt.Sprintf("Time: %d, Price: %f, Size: %s", h.Time, h.Price, DecimalMaxString(h.Size))
}
// HistoricalTickBidAsk is the historical tick's description.
// Used when requesting historical tick data with whatToShow = BID_ASK.
type HistoricalTickBidAsk struct {
Time int64
TickAttirbBidAsk TickAttribBidAsk
PriceBid float64
PriceAsk float64
SizeBid Decimal
SizeAsk Decimal
}
func NewHistoricalTickBidAsk() HistoricalTickBidAsk {
htba := HistoricalTickBidAsk{}
htba.SizeBid = UNSET_DECIMAL
htba.SizeAsk = UNSET_DECIMAL
return htba
}
func (h HistoricalTickBidAsk) String() string {
return fmt.Sprintf("Time: %d, TickAttriBidAsk: %s, PriceBid: %f, PriceAsk: %f, SizeBid: %s, SizeAsk: %s",
h.Time, h.TickAttirbBidAsk, h.PriceBid, h.PriceAsk, DecimalMaxString(h.SizeBid), DecimalMaxString(h.SizeAsk))
}
// HistoricalTickLast is the historical last tick's description.
// Used when requesting historical tick data with whatToShow = TRADES.
type HistoricalTickLast struct {
Time int64
TickAttribLast TickAttribLast
Price float64
Size Decimal
Exchange string
SpecialConditions string
}
func NewHistoricalTickLast() HistoricalTickLast {
htl := HistoricalTickLast{}
htl.Size = UNSET_DECIMAL
return htl
}
func (h HistoricalTickLast) String() string {
return fmt.Sprintf("Time: %d, TickAttribLast: %s, Price: %f, Size: %s, Exchange: %s, SpecialConditions: %s",
h.Time, h.TickAttribLast, h.Price, DecimalMaxString(h.Size), h.Exchange, h.SpecialConditions)
}
func (h HistoricalTickLast) Timestamp() time.Time {
return time.Unix(h.Time, 0)
}
// HistoricalSession .
type HistoricalSession struct {
StartDateTime string
EndDateTime string
RefDate string
}
func NewHistoricalSession() HistoricalSession {
return HistoricalSession{}
}
func (h HistoricalSession) String() string {
return fmt.Sprintf("Start: %s, End: %s, Ref Date: %s", h.StartDateTime, h.EndDateTime, h.RefDate)
}
// WshEventData .
type WshEventData struct {
ConID int64
Filter string
FillWatchList bool
FillPortfolio bool
FillCompetitors bool
StartDate string
EndDate string
TotalLimit int64
}
func NewWshEventData() WshEventData {
wed := WshEventData{}
wed.ConID = UNSET_INT
wed.TotalLimit = UNSET_INT
return wed
}
func (w WshEventData) String() string {
return fmt.Sprintf("WshEventData. ConId: %s, Filter: %s, Fill Watchlist: %t, Fill Portfolio: %t, Fill Competitors: %t",
IntMaxString(w.ConID), w.Filter, w.FillWatchList, w.FillPortfolio, w.FillCompetitors)
}