Skip to content

Commit 861aa1c

Browse files
author
Chris Busbey
committed
order match compliant with latest quickfix, moved to cmd
1 parent 3bd2502 commit 861aa1c

File tree

5 files changed

+88
-41
lines changed

5 files changed

+88
-41
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

ordermatch/ordermatch.go renamed to cmd/ordermatch/ordermatch.go

Lines changed: 88 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"bufio"
55
"flag"
66
"fmt"
7+
"os"
8+
"os/signal"
9+
"strconv"
10+
711
"github.com/quickfixgo/quickfix"
812
"github.com/quickfixgo/quickfix/enum"
13+
"github.com/quickfixgo/quickfix/field"
914
"github.com/quickfixgo/quickfix/fix42/executionreport"
1015
"github.com/quickfixgo/quickfix/fix42/marketdatarequest"
1116
"github.com/quickfixgo/quickfix/fix42/newordersingle"
1217
"github.com/quickfixgo/quickfix/fix42/ordercancelrequest"
13-
"github.com/quickfixgo/quickfix/tag"
14-
"os"
15-
"os/signal"
16-
"strconv"
1718
)
1819

1920
//Application implements the quickfix.Application interface
@@ -62,25 +63,56 @@ func (a *Application) FromApp(msg quickfix.Message, sessionID quickfix.SessionID
6263
return a.Route(msg, sessionID)
6364
}
6465

65-
func (a *Application) onNewOrderSingle(msg newordersingle.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
66-
if msg.Price == nil {
67-
err = quickfix.ConditionallyRequiredFieldMissing(tag.Price)
68-
return
66+
func (a *Application) onNewOrderSingle(msg newordersingle.NewOrderSingle, sessionID quickfix.SessionID) quickfix.MessageRejectError {
67+
clOrdID, err := msg.GetClOrdID()
68+
if err != nil {
69+
return err
6970
}
70-
if msg.OrderQty == nil {
71-
err = quickfix.ConditionallyRequiredFieldMissing(tag.OrderQty)
72-
return
71+
72+
symbol, err := msg.GetSymbol()
73+
if err != nil {
74+
return err
75+
}
76+
77+
senderCompID, err := msg.Header.GetSenderCompID()
78+
if err != nil {
79+
return err
80+
}
81+
82+
targetCompID, err := msg.Header.GetTargetCompID()
83+
if err != nil {
84+
return err
85+
}
86+
87+
side, err := msg.GetSide()
88+
if err != nil {
89+
return err
90+
}
91+
92+
ordType, err := msg.GetOrdType()
93+
if err != nil {
94+
return err
95+
}
96+
97+
price, err := msg.GetPrice()
98+
if err != nil {
99+
return err
100+
}
101+
102+
orderQty, err := msg.GetOrderQty()
103+
if err != nil {
104+
return err
73105
}
74106

75107
order := Order{
76-
ClOrdID: msg.ClOrdID,
77-
Symbol: msg.Symbol,
78-
SenderCompID: msg.Header.SenderCompID,
79-
TargetCompID: msg.Header.TargetCompID,
80-
Side: msg.Side,
81-
OrdType: msg.OrdType,
82-
Price: *msg.Price,
83-
Quantity: *msg.OrderQty,
108+
ClOrdID: clOrdID.String(),
109+
Symbol: symbol.String(),
110+
SenderCompID: senderCompID.String(),
111+
TargetCompID: targetCompID.String(),
112+
Side: side.String(),
113+
OrdType: ordType.String(),
114+
Price: price.Float64(),
115+
Quantity: orderQty.Float64(),
84116
}
85117

86118
a.Insert(order)
@@ -93,19 +125,34 @@ func (a *Application) onNewOrderSingle(msg newordersingle.Message, sessionID qui
93125
matches = matches[1:]
94126
}
95127

96-
return
128+
return nil
97129
}
98130

99-
func (a *Application) onOrderCancelRequest(msg ordercancelrequest.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
100-
order := a.Cancel(msg.OrigClOrdID, msg.Symbol, msg.Side)
131+
func (a *Application) onOrderCancelRequest(msg ordercancelrequest.OrderCancelRequest, sessionID quickfix.SessionID) quickfix.MessageRejectError {
132+
origClOrdID, err := msg.GetOrigClOrdID()
133+
if err != nil {
134+
return err
135+
}
136+
137+
symbol, err := msg.GetSymbol()
138+
if err != nil {
139+
return err
140+
}
141+
142+
side, err := msg.GetSide()
143+
if err != nil {
144+
return err
145+
}
146+
147+
order := a.Cancel(origClOrdID.String(), symbol.String(), side.String())
101148
if order != nil {
102149
a.cancelOrder(*order)
103150
}
104151

105-
return
152+
return nil
106153
}
107154

108-
func (a *Application) onMarketDataRequest(msg marketdatarequest.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
155+
func (a *Application) onMarketDataRequest(msg marketdatarequest.MarketDataRequest, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
109156
fmt.Printf("%+v\n", msg)
110157
return
111158
}
@@ -132,23 +179,23 @@ func (a *Application) genExecID() string {
132179
}
133180

134181
func (a *Application) updateOrder(order Order, status string) {
135-
execReport := executionreport.Message{
136-
OrderID: order.ClOrdID,
137-
ClOrdID: &order.ClOrdID,
138-
ExecID: a.genExecID(),
139-
ExecTransType: enum.ExecTransType_NEW,
140-
ExecType: status,
141-
OrdStatus: status,
142-
Symbol: order.Symbol,
143-
Side: order.Side,
144-
OrderQty: &order.Quantity,
145-
LeavesQty: order.OpenQuantity(),
146-
CumQty: order.ExecutedQuantity,
147-
AvgPx: order.AvgPx,
148-
}
149-
150-
execReport.Header.TargetCompID = order.SenderCompID
151-
execReport.Header.SenderCompID = order.TargetCompID
182+
execReport := executionreport.New(
183+
field.NewOrderID(order.ClOrdID),
184+
field.NewExecID(a.genExecID()),
185+
field.NewExecTransType(enum.ExecTransType_NEW),
186+
field.NewExecType(status),
187+
field.NewOrdStatus(status),
188+
field.NewSymbol(order.Symbol),
189+
field.NewSide(order.Side),
190+
field.NewLeavesQty(order.OpenQuantity()),
191+
field.NewCumQty(order.ExecutedQuantity),
192+
field.NewAvgPx(order.AvgPx),
193+
)
194+
195+
execReport.SetOrderQty(order.Quantity)
196+
execReport.SetClOrdID(order.ClOrdID)
197+
execReport.Header.SetTargetCompID(order.SenderCompID)
198+
execReport.Header.SetSenderCompID(order.TargetCompID)
152199

153200
quickfix.Send(execReport)
154201
}
File renamed without changes.

0 commit comments

Comments
 (0)