Skip to content

Commit 3d5e97e

Browse files
committed
Improves logging and docs/info
1 parent 3d4cd55 commit 3d5e97e

File tree

9 files changed

+185
-83
lines changed

9 files changed

+185
-83
lines changed

Diff for: cmd/executor/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Executor
2-
Executor is a FIX acceptor service that fills every limit order it receives.
2+
Executor is a FIX acceptor service that fills every limit order it receives.
3+
4+
(Note: it will reject any non-limit order type)
35

46
## Features
57
* Accept any canonical `NewOrderSingle` message for an instrument, with the instrument symbol consisting of an arbitrary string

Diff for: cmd/executor/executor.go

+25-31
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
package executor
1717

1818
import (
19-
"bufio"
2019
"bytes"
2120
"fmt"
2221
"io"
2322
"path"
2423
"syscall"
2524

26-
"github.com/fatih/color"
2725
"github.com/quickfixgo/enum"
26+
"github.com/quickfixgo/examples/cmd/utils"
2827
"github.com/quickfixgo/field"
2928
"github.com/quickfixgo/tag"
3029
"github.com/shopspring/decimal"
@@ -101,6 +100,7 @@ func (e *executor) OnFIX40NewOrderSingle(msg fix40nos.NewOrderSingle, sessionID
101100
}
102101

103102
if ordType != enum.OrdType_LIMIT {
103+
utils.PrintBad("incoming order was not a limit order and was rejected")
104104
return quickfix.ValueIsIncorrect(tag.OrdType)
105105
}
106106

@@ -146,7 +146,7 @@ func (e *executor) OnFIX40NewOrderSingle(msg fix40nos.NewOrderSingle, sessionID
146146

147147
sendErr := quickfix.SendToTarget(execReport, sessionID)
148148
if sendErr != nil {
149-
fmt.Println(sendErr)
149+
utils.PrintBad(sendErr.Error())
150150
}
151151

152152
return nil
@@ -158,6 +158,7 @@ func (e *executor) OnFIX41NewOrderSingle(msg fix41nos.NewOrderSingle, sessionID
158158
return
159159
}
160160
if ordType != enum.OrdType_LIMIT {
161+
utils.PrintBad("incoming order was not a limit order and was rejected")
161162
return quickfix.ValueIsIncorrect(tag.OrdType)
162163
}
163164

@@ -205,7 +206,7 @@ func (e *executor) OnFIX41NewOrderSingle(msg fix41nos.NewOrderSingle, sessionID
205206

206207
sendErr := quickfix.SendToTarget(execReport, sessionID)
207208
if sendErr != nil {
208-
fmt.Println(sendErr)
209+
utils.PrintBad(sendErr.Error())
209210
}
210211
return
211212
}
@@ -217,6 +218,7 @@ func (e *executor) OnFIX42NewOrderSingle(msg fix42nos.NewOrderSingle, sessionID
217218
}
218219

219220
if ordType != enum.OrdType_LIMIT {
221+
utils.PrintBad("incoming order was not a limit order and was rejected")
220222
return quickfix.ValueIsIncorrect(tag.OrdType)
221223
}
222224

@@ -273,7 +275,7 @@ func (e *executor) OnFIX42NewOrderSingle(msg fix42nos.NewOrderSingle, sessionID
273275

274276
sendErr := quickfix.SendToTarget(execReport, sessionID)
275277
if sendErr != nil {
276-
fmt.Println(sendErr)
278+
utils.PrintBad(sendErr.Error())
277279
}
278280

279281
return
@@ -285,6 +287,7 @@ func (e *executor) OnFIX43NewOrderSingle(msg fix43nos.NewOrderSingle, sessionID
285287
return err
286288
}
287289
if ordType != enum.OrdType_LIMIT {
290+
utils.PrintBad("incoming order was not a limit order and was rejected")
288291
return quickfix.ValueIsIncorrect(tag.OrdType)
289292
}
290293

@@ -340,7 +343,7 @@ func (e *executor) OnFIX43NewOrderSingle(msg fix43nos.NewOrderSingle, sessionID
340343

341344
sendErr := quickfix.SendToTarget(execReport, sessionID)
342345
if sendErr != nil {
343-
fmt.Println(sendErr)
346+
utils.PrintBad(sendErr.Error())
344347
}
345348

346349
return
@@ -353,6 +356,7 @@ func (e *executor) OnFIX44NewOrderSingle(msg fix44nos.NewOrderSingle, sessionID
353356
}
354357

355358
if ordType != enum.OrdType_LIMIT {
359+
utils.PrintBad("incoming order was not a limit order and was rejected")
356360
return quickfix.ValueIsIncorrect(tag.OrdType)
357361
}
358362

@@ -408,7 +412,7 @@ func (e *executor) OnFIX44NewOrderSingle(msg fix44nos.NewOrderSingle, sessionID
408412

409413
sendErr := quickfix.SendToTarget(execReport, sessionID)
410414
if sendErr != nil {
411-
fmt.Println(sendErr)
415+
utils.PrintBad(sendErr.Error())
412416
}
413417

414418
return
@@ -421,6 +425,7 @@ func (e *executor) OnFIX50NewOrderSingle(msg fix50nos.NewOrderSingle, sessionID
421425
}
422426

423427
if ordType != enum.OrdType_LIMIT {
428+
utils.PrintBad("incoming order was not a limit order and was rejected")
424429
return quickfix.ValueIsIncorrect(tag.OrdType)
425430
}
426431

@@ -476,26 +481,26 @@ func (e *executor) OnFIX50NewOrderSingle(msg fix50nos.NewOrderSingle, sessionID
476481

477482
sendErr := quickfix.SendToTarget(execReport, sessionID)
478483
if sendErr != nil {
479-
fmt.Println(sendErr)
484+
utils.PrintBad(sendErr.Error())
480485
}
481486

482487
return
483488
}
484489

485490
const (
486491
usage = "executor"
487-
short = "Start an executor"
488-
long = "Start an executor."
492+
short = "Start an order execution (FIX acceptor) service"
493+
long = "Start an order execution (FIX acceptor) service."
489494
)
490495

491496
var (
492-
// Cmd is the quote command.
497+
// Cmd is the executor command.
493498
Cmd = &cobra.Command{
494499
Use: usage,
495500
Short: short,
496501
Long: long,
497502
Aliases: []string{"x"},
498-
Example: "qf ordermatch config/executor.cfg",
503+
Example: "qf executor [YOUR_FIX_CONFIG_FILE_HERE.cfg] (default is ./config/executor.cfg)",
499504
RunE: execute,
500505
}
501506
)
@@ -506,6 +511,8 @@ func execute(cmd *cobra.Command, args []string) error {
506511
switch argLen {
507512
case 0:
508513
{
514+
utils.PrintInfo("FIX config file not provided...")
515+
utils.PrintInfo("attempting to use default location './config/executor.cfg' ...")
509516
cfgFileName = path.Join("config", "executor.cfg")
510517
}
511518
case 1:
@@ -532,40 +539,27 @@ func execute(cmd *cobra.Command, args []string) error {
532539
return fmt.Errorf("error reading cfg: %s,", err)
533540
}
534541

535-
logFactory := quickfix.NewScreenLogFactory()
542+
logger := utils.NewFancyLog()
536543
app := newExecutor()
537544

538-
printConfig(bytes.NewReader(stringData))
539-
acceptor, err := quickfix.NewAcceptor(app, quickfix.NewMemoryStoreFactory(), appSettings, logFactory)
545+
utils.PrintConfig("acceptor", bytes.NewReader(stringData))
546+
acceptor, err := quickfix.NewAcceptor(app, quickfix.NewMemoryStoreFactory(), appSettings, logger)
540547
if err != nil {
541548
return fmt.Errorf("unable to create acceptor: %s", err)
542549
}
543550

544551
err = acceptor.Start()
545552
if err != nil {
546-
return fmt.Errorf("unable to start acceptor: %s", err)
553+
return fmt.Errorf("unable to start FIX acceptor: %s", err)
547554
}
548555

549556
interrupt := make(chan os.Signal, 1)
550557
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
551558
<-interrupt
552559

560+
utils.PrintInfo("stopping FIX acceptor service..")
553561
acceptor.Stop()
562+
utils.PrintInfo("stopped")
554563

555564
return nil
556565
}
557-
558-
func printConfig(reader io.Reader) {
559-
scanner := bufio.NewScanner(reader)
560-
color.Set(color.Bold)
561-
fmt.Println("Starting FIX acceptor with config:")
562-
color.Unset()
563-
564-
color.Set(color.FgHiMagenta)
565-
for scanner.Scan() {
566-
line := scanner.Text()
567-
fmt.Println(line)
568-
}
569-
570-
color.Unset()
571-
}

Diff for: cmd/ordermatch/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Ordermatch
2-
Ordermatch is a simple matching engine (A set of orderbooks) with a FIX acceptor serving as the point of ingress.
2+
Ordermatch is a simple matching engine (A set of orderbooks) with a FIX acceptor service as the point of ingress.
33

44
## Features
55
* Accept any canonical `NewOrderSingle` message for an instrument, with the instrument symbol consisting of an arbitrary string

Diff for: cmd/ordermatch/ordermatch.go

+10-23
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626
"strconv"
2727
"syscall"
2828

29-
"github.com/fatih/color"
3029
"github.com/quickfixgo/enum"
3130
"github.com/quickfixgo/examples/cmd/ordermatch/internal"
31+
"github.com/quickfixgo/examples/cmd/utils"
3232
"github.com/quickfixgo/field"
3333
"github.com/quickfixgo/fix42/executionreport"
3434
"github.com/quickfixgo/fix42/marketdatarequest"
@@ -234,8 +234,8 @@ func (a *Application) updateOrder(order internal.Order, status enum.OrdStatus) {
234234

235235
const (
236236
usage = "ordermatch"
237-
short = "Start an ordermatcher"
238-
long = "Start an ordermatcher."
237+
short = "Start an order matching (FIX acceptor) service"
238+
long = "Start an order matching (FIX acceptor) service."
239239
)
240240

241241
var (
@@ -245,7 +245,7 @@ var (
245245
Short: short,
246246
Long: long,
247247
Aliases: []string{"oms"},
248-
Example: "qf ordermatch config/ordermatch.cfg",
248+
Example: "qf ordermatch [YOUR_FIX_CONFIG_FILE_HERE.cfg] (default is ./config/ordermatch.cfg)",
249249
RunE: execute,
250250
}
251251
)
@@ -256,6 +256,8 @@ func execute(cmd *cobra.Command, args []string) error {
256256
switch argLen {
257257
case 0:
258258
{
259+
utils.PrintInfo("FIX config file not provided...")
260+
utils.PrintInfo("attempting to use default location './config/ordermatch.cfg' ...")
259261
cfgFileName = path.Join("config", "ordermatch.cfg")
260262
}
261263
case 1:
@@ -283,18 +285,18 @@ func execute(cmd *cobra.Command, args []string) error {
283285
return fmt.Errorf("error reading cfg: %s,", err)
284286
}
285287

286-
logFactory := quickfix.NewScreenLogFactory()
288+
logger := utils.NewFancyLog()
287289
app := newApplication()
288290

289-
printConfig(bytes.NewReader(stringData))
290-
acceptor, err := quickfix.NewAcceptor(app, quickfix.NewMemoryStoreFactory(), appSettings, logFactory)
291+
utils.PrintConfig("acceptor", bytes.NewReader(stringData))
292+
acceptor, err := quickfix.NewAcceptor(app, quickfix.NewMemoryStoreFactory(), appSettings, logger)
291293
if err != nil {
292294
return fmt.Errorf("unable to create acceptor: %s", err)
293295
}
294296

295297
err = acceptor.Start()
296298
if err != nil {
297-
return fmt.Errorf("unable to start acceptor: %s", err)
299+
return fmt.Errorf("unable to start FIX acceptor: %s", err)
298300
}
299301

300302
interrupt := make(chan os.Signal, 1)
@@ -317,18 +319,3 @@ func execute(cmd *cobra.Command, args []string) error {
317319
}
318320
}
319321
}
320-
321-
func printConfig(reader io.Reader) {
322-
scanner := bufio.NewScanner(reader)
323-
color.Set(color.Bold)
324-
fmt.Println("Starting FIX acceptor with config:")
325-
color.Unset()
326-
327-
color.Set(color.FgHiMagenta)
328-
for scanner.Scan() {
329-
line := scanner.Text()
330-
fmt.Println(line)
331-
}
332-
333-
color.Unset()
334-
}

Diff for: cmd/tradeclient/tradeclient.go

+12-24
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
package tradeclient
1717

1818
import (
19-
"bufio"
2019
"bytes"
2120
"fmt"
2221
"io"
2322
"os"
2423
"path"
2524

26-
"github.com/fatih/color"
2725
"github.com/quickfixgo/examples/cmd/tradeclient/internal"
26+
"github.com/quickfixgo/examples/cmd/utils"
2827
"github.com/spf13/cobra"
2928

3029
"github.com/quickfixgo/quickfix"
@@ -53,20 +52,20 @@ func (e TradeClient) ToAdmin(msg *quickfix.Message, sessionID quickfix.SessionID
5352

5453
// ToApp implemented as part of Application interface
5554
func (e TradeClient) ToApp(msg *quickfix.Message, sessionID quickfix.SessionID) (err error) {
56-
fmt.Printf("Sending %s\n", msg)
55+
utils.PrintInfo(fmt.Sprintf("Sending: %s", msg.String()))
5756
return
5857
}
5958

6059
// FromApp implemented as part of Application interface. This is the callback for all Application level messages from the counter party.
6160
func (e TradeClient) FromApp(msg *quickfix.Message, sessionID quickfix.SessionID) (reject quickfix.MessageRejectError) {
62-
fmt.Printf("FromApp: %s\n", msg.String())
61+
utils.PrintInfo(fmt.Sprintf("FromApp: %s", msg.String()))
6362
return
6463
}
6564

6665
const (
6766
usage = "tradeclient"
68-
short = "Start a tradeclient"
69-
long = "Start a tradeclient."
67+
short = "Start a tradeclient (FIX initiator) cli trading agent"
68+
long = "Start a tradeclient (FIX initiator) cli trading agent."
7069
)
7170

7271
var (
@@ -76,7 +75,7 @@ var (
7675
Short: short,
7776
Long: long,
7877
Aliases: []string{"tc"},
79-
Example: "qf tradeclient config/tradeclient.cfg",
78+
Example: "qf tradeclient [YOUR_FIX_CONFIG_FILE_HERE.cfg] (default is ./config/tradeclient.cfg)",
8079
RunE: execute,
8180
}
8281
)
@@ -87,6 +86,8 @@ func execute(cmd *cobra.Command, args []string) error {
8786
switch argLen {
8887
case 0:
8988
{
89+
utils.PrintInfo("FIX config file not provided...")
90+
utils.PrintInfo("attempting to use default location './config/tradeclient.cfg' ...")
9091
cfgFileName = path.Join("config", "tradeclient.cfg")
9192
}
9293
case 1:
@@ -132,7 +133,7 @@ func execute(cmd *cobra.Command, args []string) error {
132133
return fmt.Errorf("unable to start initiator: %s", err)
133134
}
134135

135-
printConfig(bytes.NewReader(stringData))
136+
utils.PrintConfig("initiator", bytes.NewReader(stringData))
136137

137138
Loop:
138139
for {
@@ -160,25 +161,12 @@ Loop:
160161
}
161162

162163
if err != nil {
163-
fmt.Printf("%v\n", err)
164+
utils.PrintBad(err.Error())
164165
}
165166
}
166167

168+
utils.PrintInfo("stopping FIX initiator ..")
167169
initiator.Stop()
170+
utils.PrintInfo("stopped")
168171
return nil
169172
}
170-
171-
func printConfig(reader io.Reader) {
172-
scanner := bufio.NewScanner(reader)
173-
color.Set(color.Bold)
174-
fmt.Println("Started FIX initiator with config:")
175-
color.Unset()
176-
177-
color.Set(color.FgHiMagenta)
178-
for scanner.Scan() {
179-
line := scanner.Text()
180-
fmt.Println(line)
181-
}
182-
183-
color.Unset()
184-
}

0 commit comments

Comments
 (0)