-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathorder.go
327 lines (271 loc) · 10 KB
/
order.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
package ibapi
import "fmt"
type AuctionStrategy = int64
const (
AUCTION_UNSET AuctionStrategy = 0
AUCTION_MATCH AuctionStrategy = 1
AUCTION_IMPROVEMENT AuctionStrategy = 2
AUCTION_TRANSPARENT AuctionStrategy = 3
)
var COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID = INFINITY_FLOAT
// OrderComboLeg .
type OrderComboLeg struct {
Price float64 `default:"UNSET_FLOAT"`
}
// NewOrder creates a default OrderComboLeg.
func NewOrderComboLeg() OrderComboLeg {
ocl := OrderComboLeg{}
ocl.Price = UNSET_FLOAT
return ocl
}
func (o OrderComboLeg) String() string {
return fmt.Sprintf("%s ", FloatMaxString(o.Price))
}
// Order .
type Order struct {
// order identifier
OrderID int64
ClientID int64
PermID int64
// main order fields
Action string
TotalQuantity Decimal `default:"UNSET_DECIMAL"`
OrderType string
LmtPrice float64 `default:"UNSET_FLOAT"`
AuxPrice float64 `default:"UNSET_FLOAT"`
// extended order fields
TIF string // "Time in Force" - DAY, GTC, etc.
ActiveStartTime string // for GTC orders
ActiveStopTime string // for GTC orders
OCAGroup string // one cancels all group name
OCAType int64 // 1 = CANCEL_WITH_BLOCK, 2 = REDUCE_WITH_BLOCK, 3 = REDUCE_NON_BLOCK
OrderRef string // order reference
Transmit bool `default:"true"` // if false, order will be created but not transmitted
ParentID int64 // Parent order Id, to associate Auto STP or TRAIL orders with the original order.
BlockOrder bool
SweepToFill bool
DisplaySize int64
TriggerMethod int64 // 0=Default, 1=Double_Bid_Ask, 2=Last, 3=Double_Last, 4=Bid_Ask, 7=Last_or_Bid_Ask, 8=Mid-point
OutsideRTH bool
Hidden bool
GoodAfterTime string // Format: 20060505 08:00:00 {time zone}
GoodTillDate string // Format: 20060505 08:00:00 {time zone}
Rule80A string // Individual = 'I', Agency = 'A', AgentOtherMember = 'W', IndividualPTIA = 'J', AgencyPTIA = 'U', AgentOtherMemberPTIA = 'M', IndividualPT = 'K', AgencyPT = 'Y', AgentOtherMemberPT = 'N'
AllOrNone bool
MinQty int64 `default:"UNSET_INT"`
PercentOffset float64 `default:"UNSET_FLOAT"` // REL orders only
OverridePercentageConstraints bool
TrailStopPrice float64 `default:"UNSET_FLOAT"` // TRAILLIMIT orders only
TrailingPercent float64 `default:"UNSET_FLOAT"`
// financial advisors only
FAGroup string
FAMethod string
FAPercentage string
// institutional (ie non-cleared) only
OpenClose string // O=Open, C=Close
Origin int64 // 0=Customer, 1=Firm
ShortSaleSlot int64 // 1 if you hold the shares, 2 if they will be delivered from elsewhere. Only for Action=SSHORT
DesignatedLocation string // set when slot=2 only.
ExemptCode int64 `default:"-1"`
// SMART routing only
DiscretionaryAmt float64
OptOutSmartRouting bool
// BOX exchange orders only
AuctionStrategy AuctionStrategy // AUCTION_UNSET, AUCTION_MATCH, AUCTION_IMPROVEMENT, AUCTION_TRANSPARENT
StartingPrice float64 `default:"UNSET_FLOAT"`
StockRefPrice float64 `default:"UNSET_FLOAT"`
Delta float64 `default:"UNSET_FLOAT"`
// pegged to stock and VOL orders only
StockRangeLower float64 `default:"UNSET_FLOAT"`
StockRangeUpper float64 `default:"UNSET_FLOAT"`
RandomizeSize bool
RandomizePrice bool
// VOLATILITY ORDERS ONLY
Volatility float64 `default:"UNSET_FLOAT"`
VolatilityType int64 `default:"UNSET_INT"`
DeltaNeutralOrderType string
DeltaNeutralAuxPrice float64 `default:"UNSET_FLOAT"`
DeltaNeutralConID int64
DeltaNeutralSettlingFirm string
DeltaNeutralClearingAccount string
DeltaNeutralClearingIntent string
DeltaNeutralOpenClose string
DeltaNeutralShortSale bool
DeltaNeutralShortSaleSlot int64
DeltaNeutralDesignatedLocation string
ContinuousUpdate bool
ReferencePriceType int64 `default:"UNSET_INT"` // 1=Average, 2 = BidOrAsk
// COMBO ORDERS ONLY
BasisPoints float64 `default:"UNSET_FLOAT"` // EFP orders only
BasisPointsType int64 `default:"UNSET_INT"` // EFP orders only
// SCALE ORDERS ONLY
ScaleInitLevelSize int64 `default:"UNSET_INT"`
ScaleSubsLevelSize int64 `default:"UNSET_INT"`
ScalePriceIncrement float64 `default:"UNSET_FLOAT"`
ScalePriceAdjustValue float64 `default:"UNSET_FLOAT"`
ScalePriceAdjustInterval int64 `default:"UNSET_INT"`
ScaleProfitOffset float64 `default:"UNSET_FLOAT"`
ScaleAutoReset bool
ScaleInitPosition int64 `default:"UNSET_INT"`
ScaleInitFillQty int64 `default:"UNSET_INT"`
ScaleRandomPercent bool
ScaleTable string
// HEDGE ORDERS
HedgeType string // 'D' - delta, 'B' - beta, 'F' - FX, 'P' - pair
HedgeParam string // 'beta=X' value for beta hedge, 'ratio=Y' for pair hedge
// Clearing info
Account string // IB account
SettlingFirm string
ClearingAccount string // True beneficiary of the order
ClearingIntent string // "" (Default), "IB", "Away", "PTA" (PostTrade)
// ALGO ORDERS ONLY
AlgoStrategy string
AlgoParams []TagValue
SmartComboRoutingParams []TagValue
AlgoID string
// What-if
WhatIf bool
// Not Held
NotHeld bool
Solictied bool
// models
ModelCode string
// order combo legs
OrderComboLegs []OrderComboLeg
OrderMiscOptions []TagValue
//VER PEG2BENCH fields:
ReferenceContractID int64
PeggedChangeAmount float64
IsPeggedChangeAmountDecrease bool
ReferenceChangeAmount float64
ReferenceExchangeID string
AdjustedOrderType string
TriggerPrice float64 `default:"UNSET_FLOAT"`
AdjustedStopPrice float64 `default:"UNSET_FLOAT"`
AdjustedStopLimitPrice float64 `default:"UNSET_FLOAT"`
AdjustedTrailingAmount float64 `default:"UNSET_FLOAT"`
AdjustableTrailingUnit int64
LmtPriceOffset float64 `default:"UNSET_FLOAT"`
Conditions []OrderCondition
ConditionsCancelOrder bool
ConditionsIgnoreRth bool
// ext operator
ExtOperator string
SoftDollarTier SoftDollarTier
// native cash quantity
CashQty float64 `default:"UNSET_FLOAT"`
Mifid2DecisionMaker string
Mifid2DecisionAlgo string
Mifid2ExecutionTrader string
Mifid2ExecutionAlgo string
// don't use auto price for hedge
DontUseAutoPriceForHedge bool
IsOmsContainer bool
DiscretionaryUpToLimitPrice bool
AutoCancelDate string
FilledQuantity Decimal `default:"UNSET_DECIMAL"`
RefFuturesConID int64
AutoCancelParent bool
Shareholder string
ImbalanceOnly bool
RouteMarketableToBbo bool
ParentPermID int64
UsePriceMgmtAlgo bool
Duration int64 `default:"UNSET_INT"`
PostToAts int64 `default:"UNSET_INT"`
AdvancedErrorOverride string
ManualOrderTime string
MinTradeQty int64 `default:"UNSET_INT"`
MinCompeteSize int64 `default:"UNSET_INT"`
CompeteAgainstBestOffset float64 `default:"UNSET_FLOAT"`
MidOffsetAtWhole float64 `default:"UNSET_FLOAT"`
MidOffsetAtHalf float64 `default:"UNSET_FLOAT"`
CustomerAccount string
ProfessionalCustomer bool
BondAccruedInterest string
IncludeOvernight bool
ManualOrderIndicator int64 `default:"UNSET_INT"`
Submitter string
}
// NewOrder creates a default Order.
func NewOrder() *Order {
order := &Order{}
order.TotalQuantity = UNSET_DECIMAL
order.LmtPrice = UNSET_FLOAT
order.AuxPrice = UNSET_FLOAT
order.Transmit = true
order.MinQty = UNSET_INT
order.PercentOffset = UNSET_FLOAT
order.TrailStopPrice = UNSET_FLOAT
order.TrailingPercent = UNSET_FLOAT
order.ExemptCode = -1
order.AuctionStrategy = AUCTION_UNSET
order.StartingPrice = UNSET_FLOAT
order.StockRefPrice = UNSET_FLOAT
order.Delta = UNSET_FLOAT
order.StockRangeLower = UNSET_FLOAT
order.StockRangeUpper = UNSET_FLOAT
order.Volatility = UNSET_FLOAT
order.VolatilityType = UNSET_INT
order.DeltaNeutralAuxPrice = UNSET_FLOAT
order.ReferencePriceType = UNSET_INT
order.BasisPoints = UNSET_FLOAT
order.BasisPointsType = UNSET_INT
order.ScaleInitLevelSize = UNSET_INT
order.ScaleSubsLevelSize = UNSET_INT
order.ScalePriceIncrement = UNSET_FLOAT
order.ScalePriceAdjustValue = UNSET_FLOAT
order.ScalePriceAdjustInterval = UNSET_INT
order.ScaleProfitOffset = UNSET_FLOAT
order.ScaleInitPosition = UNSET_INT
order.ScaleInitFillQty = UNSET_INT
order.TriggerPrice = UNSET_FLOAT
order.AdjustedStopPrice = UNSET_FLOAT
order.AdjustedStopLimitPrice = UNSET_FLOAT
order.AdjustedTrailingAmount = UNSET_FLOAT
order.LmtPriceOffset = UNSET_FLOAT
order.CashQty = UNSET_FLOAT
order.FilledQuantity = UNSET_DECIMAL
order.Duration = UNSET_INT
order.PostToAts = UNSET_INT
order.MinTradeQty = UNSET_INT
order.MinCompeteSize = UNSET_INT
order.CompeteAgainstBestOffset = UNSET_FLOAT
order.MidOffsetAtWhole = UNSET_FLOAT
order.MidOffsetAtHalf = UNSET_FLOAT
order.ManualOrderIndicator = UNSET_INT
return order
}
func (o *Order) HasSameID(other *Order) bool {
if o.PermID != 0 && other.PermID != 0 {
return o.PermID == other.PermID
}
return o.OrderID == other.OrderID && o.ClientID == other.ClientID
}
func (o Order) String() string {
s := fmt.Sprintf("%s, %s, %s: %s %s %s@%s %s",
IntMaxString(o.OrderID),
IntMaxString(o.ClientID),
LongMaxString(o.PermID),
o.OrderType,
o.Action,
DecimalMaxString(o.TotalQuantity),
FloatMaxString(o.LmtPrice),
o.TIF,
)
if len(o.OrderComboLegs) > 0 {
s += " CMB("
for _, leg := range o.OrderComboLegs {
s += fmt.Sprintf("%s,", leg)
}
s += ")"
}
if len(o.Conditions) > 0 {
s += " COND("
for _, cond := range o.Conditions {
s += fmt.Sprintf("%s,", cond)
}
s += ")"
}
return s
}