forked from hadrianl/ibapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
354 lines (307 loc) · 11 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
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
354
package ibapi
import (
"fmt"
)
const (
CUSTOMER int64 = iota
FIRM
UNKNOWN
)
const (
AUCTION_UNSET int64 = iota
AUCTION_MATCH
AUCTION_IMPROVEMENT
AUCTION_TRANSPARENT
)
//Order is the origin type of order,do not try to new one unless you definitely know how to fill all the fields!Use NewDefaultOrder instead!
type Order struct {
OrderID int64
ClientID int64
PermID int64
Action string
TotalQuantity float64
OrderType string
LimitPrice float64 `default:"UNSETFLOAT"`
AuxPrice float64 `default:"UNSETFLOAT"`
TIF string
ActiveStartTime string
ActiveStopTime string
OCAGroup string
OCAType int64 // 1 = CANCEL_WITH_BLOCK, 2 = REDUCE_WITH_BLOCK, 3 = REDUCE_NON_BLOCK
OrderRef string
Transmit bool `default:"true"`
ParentID int64
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}
OverridePercentageConstraints bool
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:"UNSETINT"`
PercentOffset float64 `default:"UNSETFLOAT"` // REL orders only
TrailStopPrice float64 `default:"UNSETFLOAT"`
TrailingPercent float64 `default:"UNSETFLOAT"` // TRAILLIMIT orders only
//---- financial advisors only -----
FAGroup string
FAProfile string
FAMethod string
FAPercentage string
// ---------------------------------
// ---------institutional 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 // used only when shortSaleSlot=2
ExemptCode int64 `default:"-1"`
// ---------------------------------
// ------- SMART routing only ------
DiscretionaryAmount float64
ETradeOnly bool `default:"true"`
FirmQuoteOnly bool `default:"true"`
NBBOPriceCap float64 `default:"UNSETFLOAT"`
OptOutSmartRouting bool
// --------------------------------
// ---BOX exchange orders only ----
AuctionStrategy int64
StartingPrice float64 `default:"UNSETFLOAT"`
StockRefPrice float64 `default:"UNSETFLOAT"`
Delta float64 `default:"UNSETFLOAT"`
// --------------------------------
// --pegged to stock and VOL orders only--
StockRangeLower float64 `default:"UNSETFLOAT"`
StockRangeUpper float64 `default:"UNSETFLOAT"`
RandomizePrice bool
RandomizeSize bool
// ---VOLATILITY ORDERS ONLY--------
Volatility float64 `default:"UNSETFLOAT"`
VolatilityType int64 `default:"UNSETINT"`
DeltaNeutralOrderType string
DeltaNeutralAuxPrice float64 `default:"UNSETFLOAT"`
DeltaNeutralContractID int64
DeltaNeutralSettlingFirm string
DeltaNeutralClearingAccount string
DeltaNeutralClearingIntent string
DeltaNeutralOpenClose string
DeltaNeutralShortSale bool
DeltaNeutralShortSaleSlot int64
DeltaNeutralDesignatedLocation string
ContinuousUpdate bool
ReferencePriceType int64 `default:"UNSETINT"` // 1=Average, 2 = BidOrAsk
// DeltaNeutral DeltaNeutralData `when:"DeltaNeutralOrderType" cond:"is" value:""`
// -------------------------------------
// ------COMBO ORDERS ONLY-----------
BasisPoints float64 `default:"UNSETFLOAT"` // EFP orders only
BasisPointsType int64 `default:"UNSETINT"` // EFP orders only
// -----------------------------------
//-----------SCALE ORDERS ONLY------------
ScaleInitLevelSize int64 `default:"UNSETINT"`
ScaleSubsLevelSize int64 `default:"UNSETINT"`
ScalePriceIncrement float64 `default:"UNSETFLOAT"`
ScalePriceAdjustValue float64 `default:"UNSETFLOAT"`
ScalePriceAdjustInterval int64 `default:"UNSETINT"`
ScaleProfitOffset float64 `default:"UNSETFLOAT"`
ScaleAutoReset bool
ScaleInitPosition int64 `default:"UNSETINT"`
ScaleInitFillQty int64 `default:"UNSETINT"`
ScaleRandomPercent bool
ScaleTable string
NotSuppScaleNumComponents int64
//--------------------------------------
// ---------HEDGE ORDERS--------------
HedgeType string
HedgeParam string
//--------------------------------------
//-----------Clearing info ----------------
Account string
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 order -------------------
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:"UNSETFLOAT"`
AdjustedStopPrice float64 `default:"UNSETFLOAT"`
AdjustedStopLimitPrice float64 `default:"UNSETFLOAT"`
AdjustedTrailingAmount float64 `default:"UNSETFLOAT"`
AdjustableTrailingUnit int64
LimitPriceOffset float64 `default:"UNSETFLOAT"`
Conditions []OrderConditioner
ConditionsCancelOrder bool
ConditionsIgnoreRth bool
//------ext operator--------------
ExtOperator string
//-----native cash quantity --------
CashQty float64 `default:"UNSETFLOAT"`
//--------------------------------
Mifid2DecisionMaker string
Mifid2DecisionAlgo string
Mifid2ExecutionTrader string
Mifid2ExecutionAlgo string
//-------------
DontUseAutoPriceForHedge bool
IsOmsContainer bool
DiscretionaryUpToLimitPrice bool
AutoCancelDate string
FilledQuantity float64 `default:"UNSETFLOAT"`
RefFuturesConID int64
AutoCancelParent bool
Shareholder string
ImbalanceOnly bool
RouteMarketableToBbo bool
ParentPermID int64
UsePriceMgmtAlgo bool
Duration int64 `default:"UNSETINT"`
PostToAts int64 `default:"UNSETINT"`
SoftDollarTier SoftDollarTier
}
func (o Order) String() string {
s := fmt.Sprintf("Order<OrderID: %d, ClientID: %d, PermID: %d> -- <%s %s %.2f@%f %s> --",
o.OrderID,
o.ClientID,
o.PermID,
o.OrderType,
o.Action,
o.TotalQuantity,
o.LimitPrice,
o.TIF)
for i, leg := range o.OrderComboLegs {
s += fmt.Sprintf(" CMB<%d>-%s", i, leg)
}
for i, cond := range o.Conditions {
s += fmt.Sprintf(" COND<%d>-%s", i, cond)
}
return s
}
// OrderState is the state of Order
type OrderState struct {
Status string
InitialMarginBefore string
InitialMarginChange string
InitialMarginAfter string
MaintenanceMarginBefore string
MaintenanceMarginChange string
MaintenanceMarginAfter string
EquityWithLoanBefore string
EquityWithLoanChange string
EquityWithLoanAfter string
Commission float64 `default:"UNSETFLOAT"`
MinCommission float64 `default:"UNSETFLOAT"`
MaxCommission float64 `default:"UNSETFLOAT"`
CommissionCurrency string
WarningText string
CompletedTime string
CompletedStatus string
}
func (state OrderState) String() string {
return fmt.Sprintf(
"OrderState<Status: %s, Commission: %v%s, CompletedTime: %s, CompletedStatus: %s>",
state.Status,
state.Commission,
state.CommissionCurrency,
state.CompletedTime,
state.CompletedStatus,
)
}
// SoftDollarTier is a container for storing Soft Dollar Tier information
type SoftDollarTier struct {
Name string
Value string
DisplayName string
}
func (s SoftDollarTier) String() string {
return fmt.Sprintf("SoftDollarTier<Name: %s, Value: %s, DisplayName: %s>",
s.Name,
s.Value,
s.DisplayName)
}
// NewOrder create a default order
func NewOrder() *Order {
order := &Order{}
order.LimitPrice = UNSETFLOAT
order.AuxPrice = UNSETFLOAT
order.Transmit = true
order.MinQty = UNSETINT
order.PercentOffset = UNSETFLOAT
order.TrailStopPrice = UNSETFLOAT
order.TrailingPercent = UNSETFLOAT
order.OpenClose = "O"
order.ExemptCode = -1
order.ETradeOnly = true
order.FirmQuoteOnly = true
order.NBBOPriceCap = UNSETFLOAT
order.AuctionStrategy = AUCTION_UNSET
order.StartingPrice = UNSETFLOAT
order.StockRefPrice = UNSETFLOAT
order.Delta = UNSETFLOAT
order.StockRangeLower = UNSETFLOAT
order.StockRangeUpper = UNSETFLOAT
order.Volatility = UNSETFLOAT
order.VolatilityType = UNSETINT
order.DeltaNeutralAuxPrice = UNSETFLOAT
order.ReferencePriceType = UNSETINT
order.BasisPoints = UNSETFLOAT
order.BasisPointsType = UNSETINT
order.ScaleInitLevelSize = UNSETINT
order.ScaleSubsLevelSize = UNSETINT
order.ScalePriceIncrement = UNSETFLOAT
order.ScalePriceAdjustValue = UNSETFLOAT
order.ScalePriceAdjustInterval = UNSETINT
order.ScaleProfitOffset = UNSETFLOAT
order.ScaleInitPosition = UNSETINT
order.ScaleInitFillQty = UNSETINT
order.TriggerPrice = UNSETFLOAT
order.AdjustedStopPrice = UNSETFLOAT
order.AdjustedStopLimitPrice = UNSETFLOAT
order.AdjustedTrailingAmount = UNSETFLOAT
order.LimitPriceOffset = UNSETFLOAT
order.CashQty = UNSETFLOAT
order.FilledQuantity = UNSETFLOAT
order.Duration = UNSETINT
order.PostToAts = UNSETINT
return order
}
// NewLimitOrder create a limit order with action, limit price and quantity
func NewLimitOrder(action string, lmtPrice float64, quantity float64) *Order {
o := NewOrder()
o.OrderType = "LMT"
o.Action = action
o.LimitPrice = lmtPrice
o.TotalQuantity = quantity
return o
}
// NewMarketOrder create a market order with action and quantity
func NewMarketOrder(action string, quantity float64) *Order {
o := NewOrder()
o.OrderType = "MKT"
o.Action = action
o.TotalQuantity = quantity
return o
}