-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathcommon.go
339 lines (292 loc) · 6.97 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
package ibapi
import (
"fmt"
)
// Account ...
type Account struct {
Name string
}
// TickAttrib describes additional information for price ticks
type TickAttrib struct {
CanAutoExecute bool
PastLimit bool
PreOpen bool
}
func (t TickAttrib) String() string {
return fmt.Sprintf("TickAttrib<CanAutoExecute: %t, PastLimit: %t, PreOpen: %t>",
t.CanAutoExecute,
t.PastLimit,
t.PreOpen)
}
// AlgoParams ...
type AlgoParams struct {
}
// TagValue ...
type TagValue struct {
Tag string
Value string
}
func (tv TagValue) String() string {
return fmt.Sprintf("TagValue<%s=%s>", tv.Tag, tv.Value)
}
// OrderComboLeg ...
type OrderComboLeg struct {
Price float64 `default:"UNSETFLOAT"`
}
func (o OrderComboLeg) String() string {
return fmt.Sprintf("OrderComboLeg<Price:%f>;", o.Price)
}
// ------------ComboLeg--------------------
// ComboLegOpenClose ...
type ComboLegOpenClose int64
// ComboLegShortSaleSlot ...
type ComboLegShortSaleSlot int64
const (
SAME_POS ComboLegOpenClose = 0
OPEN_POS = 1
CLOSE_POS = 2
UNKNOWN_POS = 3
ClearingBroker ComboLegShortSaleSlot = 1
ThirdParty = 2
)
// ComboLeg ...
type ComboLeg struct {
ContractID int64
Ratio int64
Action string
Exchange string
OpenClose int64
// for stock legs when doing short sale
ShortSaleSlot int64
DesignatedLocation string
ExemptCode int64 `default:"-1"`
}
func (c ComboLeg) String() string {
return fmt.Sprintf("ComboLeg<%d, %d, %s, %s, %d, %d, %s, %d>",
c.ContractID,
c.Ratio,
c.Action,
c.Exchange,
c.OpenClose,
c.ShortSaleSlot,
c.DesignatedLocation,
c.ExemptCode)
}
// -----------------------------------------------------
// ExecutionFilter ...
type ExecutionFilter struct {
ClientID int64
AccountCode string
Time string
Symbol string
SecurityType string
Exchange string
Side string
}
// BarData ...
type BarData struct {
Date string
Open float64
High float64
Low float64
Close float64
Volume float64
BarCount int64
Average float64
}
func (b BarData) String() string {
return fmt.Sprintf("BarData<Date: %s, Open: %f, High: %f, Low: %f, Close: %f, Volume: %f, Average: %f, BarCount: %d>",
b.Date,
b.Open,
b.High,
b.Low,
b.Close,
b.Volume,
b.Average,
b.BarCount)
}
// RealTimeBar ...
type RealTimeBar struct {
Time int64
endTime int64
Open float64
High float64
Low float64
Close float64
Volume int64
Wap float64
Count int64
}
func (rb RealTimeBar) String() string {
return fmt.Sprintf("RealTimeBar<Time: %d, Open: %f, High: %f, Low: %f, Close: %f, Volume: %d, Wap: %f, Count: %d>",
rb.Time,
rb.Open,
rb.High,
rb.Low,
rb.Close,
rb.Volume,
rb.Wap,
rb.Count)
}
// CommissionReport ...
type CommissionReport struct {
ExecID string
Commission float64
Currency string
RealizedPNL float64
Yield float64
YieldRedemptionDate int64 //YYYYMMDD
}
func (cr CommissionReport) String() string {
return fmt.Sprintf("CommissionReport<ExecId: %v, Commission: %v%s, RealizedPnL: %v, Yield: %v, YieldRedemptionDate: %v>",
cr.ExecID,
cr.Commission,
cr.Currency,
cr.RealizedPNL,
cr.Yield,
cr.YieldRedemptionDate)
}
// FamilyCode ...
type FamilyCode struct {
AccountID string
FamilyCode string
}
func (f FamilyCode) String() string {
return fmt.Sprintf("FamilyCode<AccountId: %s, FamilyCodeStr: %s>",
f.AccountID,
f.FamilyCode)
}
// SmartComponent ...
type SmartComponent struct {
BitNumber int64
Exchange string
ExchangeLetter string
}
func (s SmartComponent) String() string {
return fmt.Sprintf("SmartComponent<BitNumber: %d, Exchange: %s, ExchangeLetter: %s>",
s.BitNumber,
s.Exchange,
s.ExchangeLetter)
}
// DepthMktDataDescription ...
type DepthMktDataDescription struct {
Exchange string
SecurityType string
ListingExchange string
ServiceDataType string
AggGroup int64 `default:"UNSETINT"`
}
// DepthMktDataDescription ...
func (d DepthMktDataDescription) String() string {
aggGroup := ""
if d.AggGroup != UNSETINT {
aggGroup = fmt.Sprint(d.AggGroup)
}
return fmt.Sprintf("DepthMktDataDescription<Exchange: %s, SecType: %s, ListingExchange: %s, ServiceDataType: %s, AggGroup: %s>",
d.Exchange,
d.SecurityType,
d.ListingExchange,
d.ServiceDataType,
aggGroup)
}
// NewsProvider ...
type NewsProvider struct {
Code string
Name string
}
func (np NewsProvider) String() string {
return fmt.Sprintf("NewsProvider<Code: %s, Name: %s>",
np.Code,
np.Name)
}
// HistogramData ...
type HistogramData struct {
Price float64
Count int64
}
func (hgd HistogramData) String() string {
return fmt.Sprintf("HistogramData<Price: %f, Count: %d>",
hgd.Price,
hgd.Count)
}
// PriceIncrement ...
type PriceIncrement struct {
LowEdge float64
Increment float64
}
func (p PriceIncrement) String() string {
return fmt.Sprintf("PriceIncrement<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 int64
}
func (h HistoricalTick) String() string {
return fmt.Sprintf("Tick<Time: %d, Price: %f, Size: %d>",
h.Time,
h.Price,
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 int64
SizeAsk int64
}
func (h HistoricalTickBidAsk) String() string {
return fmt.Sprintf("TickBidAsk<Time: %d, TickAttriBidAsk: %s, PriceBid: %f, PriceAsk: %f, SizeBid: %d, SizeAsk: %d>",
h.Time,
h.TickAttirbBidAsk,
h.PriceBid,
h.PriceAsk,
h.SizeBid,
h.SizeAsk)
}
// TickAttribBidAsk ...
type TickAttribBidAsk struct {
BidPastLow bool
AskPastHigh bool
}
func (t TickAttribBidAsk) String() string {
return fmt.Sprintf("TickAttribBidAsk<BidPastLow: %t, AskPastHigh: %t>",
t.BidPastLow,
t.AskPastHigh)
}
// 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 int64
Exchange string
SpecialConditions string
}
func (h HistoricalTickLast) String() string {
return fmt.Sprintf("TickLast<Time: %d, TickAttribLast: %s, Price: %f, Size: %d, Exchange: %s, SpecialConditions: %s>",
h.Time,
h.TickAttribLast,
h.Price,
h.Size,
h.Exchange,
h.SpecialConditions)
}
// TickAttribLast ...
type TickAttribLast struct {
PastLimit bool
Unreported bool
}
func (t TickAttribLast) String() string {
return fmt.Sprintf("TickAttribLast<PastLimit: %t, Unreported: %t>",
t.PastLimit,
t.Unreported)
}