Skip to content

Commit 686cf99

Browse files
authored
Merge pull request #8 from cbusbey/qfix_bump
Qfix bump
2 parents cc35172 + 368cfae commit 686cf99

File tree

52 files changed

+3756
-2791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3756
-2791
lines changed

cmd/executor/executor.go

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/quickfixgo/quickfix/enum"
1010
"github.com/quickfixgo/quickfix/field"
1111
"github.com/quickfixgo/quickfix/tag"
12+
"github.com/shopspring/decimal"
1213

1314
fix40nos "github.com/quickfixgo/quickfix/fix40/newordersingle"
1415
fix41nos "github.com/quickfixgo/quickfix/fix41/newordersingle"
@@ -109,12 +110,18 @@ func (e *executor) OnFIX40NewOrderSingle(msg fix40nos.NewOrderSingle, sessionID
109110
symbol,
110111
side,
111112
orderQty,
112-
field.NewLastShares(orderQty.Float64()),
113-
field.NewLastPx(price.Float64()),
114-
field.NewCumQty(orderQty.Float64()),
115-
field.NewAvgPx(price.Float64()),
113+
field.NewLastShares(orderQty.Decimal, 2),
114+
field.NewLastPx(price.Decimal, 2),
115+
field.NewCumQty(orderQty.Decimal, 2),
116+
field.NewAvgPx(price.Decimal, 2),
116117
)
117118

119+
var clOrdID field.ClOrdIDField
120+
if clOrdID, err = msg.GetClOrdID(); err != nil {
121+
return
122+
}
123+
execReport.Set(clOrdID)
124+
118125
quickfix.SendToTarget(execReport, sessionID)
119126

120127
return
@@ -158,13 +165,19 @@ func (e *executor) OnFIX41NewOrderSingle(msg fix41nos.NewOrderSingle, sessionID
158165
symbol,
159166
side,
160167
orderQty,
161-
field.NewLastShares(orderQty.Float64()),
162-
field.NewLastPx(price.Float64()),
163-
field.NewLeavesQty(0),
164-
field.NewCumQty(orderQty.Float64()),
165-
field.NewAvgPx(price.Float64()),
168+
field.NewLastShares(orderQty.Decimal, 2),
169+
field.NewLastPx(price.Decimal, 2),
170+
field.NewLeavesQty(decimal.Zero, 2),
171+
field.NewCumQty(orderQty.Decimal, 2),
172+
field.NewAvgPx(price.Decimal, 2),
166173
)
167174

175+
var clOrdID field.ClOrdIDField
176+
if clOrdID, err = msg.GetClOrdID(); err != nil {
177+
return
178+
}
179+
execReport.Set(clOrdID)
180+
168181
quickfix.SendToTarget(execReport, sessionID)
169182

170183
return
@@ -212,15 +225,15 @@ func (e *executor) OnFIX42NewOrderSingle(msg fix42nos.NewOrderSingle, sessionID
212225
field.NewOrdStatus(enum.OrdStatus_FILLED),
213226
symbol,
214227
side,
215-
field.NewLeavesQty(0),
216-
field.NewCumQty(orderQty.Float64()),
217-
field.NewAvgPx(price.Float64()),
228+
field.NewLeavesQty(decimal.Zero, 2),
229+
field.NewCumQty(orderQty.Decimal, 2),
230+
field.NewAvgPx(price.Decimal, 2),
218231
)
219232

220233
execReport.Set(clOrdID)
221234
execReport.Set(orderQty)
222-
execReport.SetLastShares(orderQty.Float64())
223-
execReport.SetLastPx(price.Float64())
235+
execReport.SetLastShares(orderQty.Decimal, 2)
236+
execReport.SetLastPx(price.Decimal, 2)
224237

225238
if msg.HasAccount() {
226239
var acct field.AccountField
@@ -275,16 +288,16 @@ func (e *executor) OnFIX43NewOrderSingle(msg fix43nos.NewOrderSingle, sessionID
275288
field.NewExecType(enum.ExecType_FILL),
276289
field.NewOrdStatus(enum.OrdStatus_FILLED),
277290
side,
278-
field.NewLeavesQty(0),
279-
field.NewCumQty(orderQty.Float64()),
280-
field.NewAvgPx(price.Float64()),
291+
field.NewLeavesQty(decimal.Zero, 2),
292+
field.NewCumQty(orderQty.Decimal, 2),
293+
field.NewAvgPx(price.Decimal, 2),
281294
)
282295

283296
execReport.Set(clOrdID)
284297
execReport.Set(symbol)
285298
execReport.Set(orderQty)
286-
execReport.SetLastQty(orderQty.Float64())
287-
execReport.SetLastPx(price.Float64())
299+
execReport.SetLastQty(orderQty.Decimal, 2)
300+
execReport.SetLastPx(price.Decimal, 2)
288301

289302
if msg.HasAccount() {
290303
var acct field.AccountField
@@ -340,16 +353,16 @@ func (e *executor) OnFIX44NewOrderSingle(msg fix44nos.NewOrderSingle, sessionID
340353
field.NewExecType(enum.ExecType_FILL),
341354
field.NewOrdStatus(enum.OrdStatus_FILLED),
342355
side,
343-
field.NewLeavesQty(0),
344-
field.NewCumQty(orderQty.Float64()),
345-
field.NewAvgPx(price.Float64()),
356+
field.NewLeavesQty(decimal.Zero, 2),
357+
field.NewCumQty(orderQty.Decimal, 2),
358+
field.NewAvgPx(price.Decimal, 2),
346359
)
347360

348361
execReport.Set(clOrdID)
349362
execReport.Set(symbol)
350363
execReport.Set(orderQty)
351-
execReport.SetLastQty(orderQty.Float64())
352-
execReport.SetLastPx(price.Float64())
364+
execReport.SetLastQty(orderQty.Decimal, 2)
365+
execReport.SetLastPx(price.Decimal, 2)
353366

354367
if msg.HasAccount() {
355368
var acct field.AccountField
@@ -405,16 +418,16 @@ func (e *executor) OnFIX50NewOrderSingle(msg fix50nos.NewOrderSingle, sessionID
405418
field.NewExecType(enum.ExecType_FILL),
406419
field.NewOrdStatus(enum.OrdStatus_FILLED),
407420
side,
408-
field.NewLeavesQty(0),
409-
field.NewCumQty(orderQty.Float64()),
421+
field.NewLeavesQty(decimal.Zero, 2),
422+
field.NewCumQty(orderQty.Decimal, 2),
410423
)
411424

412425
execReport.Set(clOrdID)
413426
execReport.Set(symbol)
414427
execReport.Set(orderQty)
415-
execReport.SetLastQty(orderQty.Float64())
416-
execReport.SetLastPx(price.Float64())
417-
execReport.SetAvgPx(price.Float64())
428+
execReport.SetLastQty(orderQty.Decimal, 2)
429+
execReport.SetLastPx(price.Decimal, 2)
430+
execReport.SetAvgPx(price.Decimal, 2)
418431

419432
if msg.HasAccount() {
420433
var acct field.AccountField

cmd/ordermatch/internal/market.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ func (l *orderList) Remove(clordID string) (order *Order) {
3838

3939
func bids() (b orderList) {
4040
b.sortBy = func(i, j *Order) bool {
41-
if i.Price > j.Price {
41+
switch i.Price.Cmp(j.Price) {
42+
case 1:
4243
return true
43-
} else if i.Price < j.Price {
44+
case -1:
4445
return false
4546
}
4647

@@ -52,10 +53,11 @@ func bids() (b orderList) {
5253

5354
func offers() (o orderList) {
5455
o.sortBy = func(i, j *Order) bool {
55-
if i.Price < j.Price {
56-
return true
57-
} else if i.Price < j.Price {
56+
switch i.Price.Cmp(j.Price) {
57+
case 1:
5858
return false
59+
case -1:
60+
return true
5961
}
6062

6163
return i.insertTime.Before(j.insertTime)
@@ -121,7 +123,7 @@ func (m *Market) Match() (matched []Order) {
121123

122124
price := bestOffer.Price
123125
quantity := bestBid.OpenQuantity()
124-
if offerQuant := bestOffer.OpenQuantity(); offerQuant < quantity {
126+
if offerQuant := bestOffer.OpenQuantity(); offerQuant.Cmp(quantity) == -1 {
125127
quantity = offerQuant
126128
}
127129

cmd/ordermatch/internal/order.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,46 @@ package internal
22

33
import (
44
"time"
5+
6+
"github.com/shopspring/decimal"
57
)
68

79
type Order struct {
8-
ClOrdID string
9-
Symbol string
10-
SenderCompID string
11-
TargetCompID string
12-
Side string
13-
OrdType string
14-
Price float64
15-
Quantity float64
16-
ExecutedQuantity float64
17-
openQuantity *float64
18-
AvgPx float64
19-
insertTime time.Time
10+
ClOrdID string
11+
Symbol string
12+
SenderCompID string
13+
TargetCompID string
14+
Side string
15+
OrdType string
16+
Price decimal.Decimal
17+
Quantity decimal.Decimal
18+
ExecutedQuantity decimal.Decimal
19+
openQuantity *decimal.Decimal
20+
AvgPx decimal.Decimal
21+
insertTime time.Time
22+
LastExecutedQuantity decimal.Decimal
23+
LastExecutedPrice decimal.Decimal
2024
}
2125

2226
func (o Order) IsClosed() bool {
23-
return o.OpenQuantity() == 0
27+
return o.OpenQuantity().Equals(decimal.Zero)
2428
}
2529

26-
func (o Order) OpenQuantity() float64 {
30+
func (o Order) OpenQuantity() decimal.Decimal {
2731
if o.openQuantity == nil {
28-
return o.Quantity - o.ExecutedQuantity
32+
return o.Quantity.Sub(o.ExecutedQuantity)
2933
}
3034

3135
return *o.openQuantity
3236
}
3337

34-
func (o *Order) Execute(price, quantity float64) {
35-
o.ExecutedQuantity += quantity
38+
func (o *Order) Execute(price, quantity decimal.Decimal) {
39+
o.ExecutedQuantity = o.ExecutedQuantity.Add(quantity)
40+
o.LastExecutedPrice = price
41+
o.LastExecutedQuantity = quantity
3642
}
3743

3844
func (o *Order) Cancel() {
39-
openQuantity := float64(0)
45+
openQuantity := decimal.Zero
4046
o.openQuantity = &openQuantity
4147
}

cmd/ordermatch/ordermatch.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func (a *Application) onNewOrderSingle(msg newordersingle.NewOrderSingle, sessio
113113
TargetCompID: targetCompID.String(),
114114
Side: side.String(),
115115
OrdType: ordType.String(),
116-
Price: price.Float64(),
117-
Quantity: orderQty.Float64(),
116+
Price: price.Decimal,
117+
Quantity: orderQty.Decimal,
118118
}
119119

120120
a.Insert(order)
@@ -189,13 +189,19 @@ func (a *Application) updateOrder(order internal.Order, status string) {
189189
field.NewOrdStatus(status),
190190
field.NewSymbol(order.Symbol),
191191
field.NewSide(order.Side),
192-
field.NewLeavesQty(order.OpenQuantity()),
193-
field.NewCumQty(order.ExecutedQuantity),
194-
field.NewAvgPx(order.AvgPx),
192+
field.NewLeavesQty(order.OpenQuantity(), 2),
193+
field.NewCumQty(order.ExecutedQuantity, 2),
194+
field.NewAvgPx(order.AvgPx, 2),
195195
)
196-
197-
execReport.SetOrderQty(order.Quantity)
196+
execReport.SetOrderQty(order.Quantity, 2)
198197
execReport.SetClOrdID(order.ClOrdID)
198+
199+
switch status {
200+
case enum.OrdStatus_FILLED, enum.OrdStatus_PARTIALLY_FILLED:
201+
execReport.SetLastShares(order.LastExecutedQuantity, 2)
202+
execReport.SetLastPx(order.LastExecutedPrice, 2)
203+
}
204+
199205
execReport.Header.SetTargetCompID(order.SenderCompID)
200206
execReport.Header.SetSenderCompID(order.TargetCompID)
201207

cmd/tradeclient/internal/console.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/quickfixgo/quickfix"
99
"github.com/quickfixgo/quickfix/enum"
1010
"github.com/quickfixgo/quickfix/field"
11+
"github.com/shopspring/decimal"
1112

1213
"os"
1314
"strconv"
@@ -43,8 +44,8 @@ func queryString(fieldName string) string {
4344
return scanner.Text()
4445
}
4546

46-
func queryFloat(fieldName string) float64 {
47-
val, err := strconv.ParseFloat(queryString(fieldName), 64)
47+
func queryDecimal(fieldName string) decimal.Decimal {
48+
val, err := decimal.NewFromString(queryString(fieldName))
4849
if err != nil {
4950
panic(err)
5051
}
@@ -190,15 +191,15 @@ func queryTimeInForce() field.TimeInForceField {
190191
}
191192

192193
func queryOrderQty() field.OrderQtyField {
193-
return field.NewOrderQty(queryFloat("OrderQty"))
194+
return field.NewOrderQty(queryDecimal("OrderQty"), 2)
194195
}
195196

196197
func queryPrice() field.PriceField {
197-
return field.NewPrice(queryFloat("Price"))
198+
return field.NewPrice(queryDecimal("Price"), 2)
198199
}
199200

200201
func queryStopPx() field.StopPxField {
201-
return field.NewStopPx(queryFloat("Stop Price"))
202+
return field.NewStopPx(queryDecimal("Stop Price"), 2)
202203
}
203204

204205
func querySenderCompID() field.SenderCompIDField {

vendor/github.com/quickfixgo/quickfix/CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/quickfixgo/quickfix/Makefile

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)