Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ordermatch to fix 5.0 and fix error to cancel orders #40

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get Deps
run: go mod vendor
- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor
bin
.exe
dist/
.idea
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ build-linux:
GOOS=linux GOARCH=amd64 go build -v -o ./bin/qf .

build-docker: clean build-linux
docker build -t quickfixgo/qf:latest .
docker build -t quickfixgo/qf:latest .

run-client:
./bin/qf tradeclient ./config/tradeclient.cfg

run-server:
./bin/qf ordermatch ./config/ordermatch.cfg
2 changes: 1 addition & 1 deletion cmd/ordermatch/internal/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (m Market) Display() {
fmt.Printf("%+v\n", bid)
}

fmt.Println("OFFERS:")
fmt.Println("ASKS:")
fmt.Println("-----")
fmt.Println()

Expand Down
22 changes: 12 additions & 10 deletions cmd/ordermatch/ordermatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
"github.com/quickfixgo/examples/cmd/ordermatch/internal"
"github.com/quickfixgo/examples/cmd/utils"
"github.com/quickfixgo/field"
"github.com/quickfixgo/fix42/executionreport"
"github.com/quickfixgo/fix42/marketdatarequest"
"github.com/quickfixgo/fix42/newordersingle"
"github.com/quickfixgo/fix42/ordercancelrequest"
"github.com/quickfixgo/fix50/executionreport"
"github.com/quickfixgo/fix50/marketdatarequest"
"github.com/quickfixgo/fix50/newordersingle"
"github.com/quickfixgo/fix50/ordercancelrequest"
"github.com/spf13/cobra"

"github.com/quickfixgo/quickfix"
Expand Down Expand Up @@ -62,7 +62,9 @@ func newApplication() *Application {
func (a Application) OnCreate(sessionID quickfix.SessionID) {}

// OnLogon implemented as part of Application interface
func (a Application) OnLogon(sessionID quickfix.SessionID) {}
func (a Application) OnLogon(sessionID quickfix.SessionID) {

}

// OnLogout implemented as part of Application interface
func (a Application) OnLogout(sessionID quickfix.SessionID) {}
Expand Down Expand Up @@ -204,21 +206,21 @@ func (a *Application) updateOrder(order internal.Order, status enum.OrdStatus) {
execReport := executionreport.New(
field.NewOrderID(order.ClOrdID),
field.NewExecID(a.genExecID()),
field.NewExecTransType(enum.ExecTransType_NEW),
field.NewExecType(enum.ExecType(status)),
field.NewOrdStatus(status),
field.NewSymbol(order.Symbol),
field.NewSide(order.Side),
field.NewLeavesQty(order.OpenQuantity(), 2),
field.NewCumQty(order.ExecutedQuantity, 2),
field.NewAvgPx(order.AvgPx, 2),
)
execReport.SetOrderQty(order.Quantity, 2)

execReport.SetClOrdID(order.ClOrdID)
execReport.SetSymbol(order.Symbol)
execReport.SetOrderQty(order.Quantity, 2)
execReport.SetAvgPx(order.AvgPx, 2)

switch status {
case enum.OrdStatus_FILLED, enum.OrdStatus_PARTIALLY_FILLED:
execReport.SetLastShares(order.LastExecutedQuantity, 2)
execReport.SetLastQty(order.LastExecutedQuantity, 2)
execReport.SetLastPx(order.LastExecutedPrice, 2)
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/tradeclient/internal/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func queryClOrdID() field.ClOrdIDField {
}

func queryOrigClOrdID() field.OrigClOrdIDField {
return field.NewOrigClOrdID(("OrigClOrdID"))
return field.NewOrigClOrdID(queryString("OrigClOrdID"))
}

func querySymbol() field.SymbolField {
Expand Down Expand Up @@ -207,15 +207,17 @@ func queryTimeInForce() field.TimeInForceField {
}

func queryOrderQty() field.OrderQtyField {
return field.NewOrderQty(queryDecimal("OrderQty"), 2)
dec := queryDecimal("OrderQty").Truncate(8)
return field.NewOrderQty(dec, 8)
}

func queryPrice() field.PriceField {
return field.NewPrice(queryDecimal("Price"), 2)
dec := queryDecimal("Price").Truncate(8)
return field.NewPrice(dec, 8)
}

func queryStopPx() field.StopPxField {
return field.NewStopPx(queryDecimal("Stop Price"), 2)
return field.NewStopPx(queryDecimal("Stop Price"), 8)
}

func querySenderCompID() field.SenderCompIDField {
Expand Down Expand Up @@ -370,7 +372,6 @@ func queryNewOrderSingle50() (msg *quickfix.Message) {
order.SetHandlInst("1")
order.Set(querySymbol())
order.Set(queryOrderQty())
order.Set(queryTimeInForce())

switch ordType.Value() {
case enum.OrdType_LIMIT, enum.OrdType_STOP_LIMIT:
Expand All @@ -382,6 +383,8 @@ func queryNewOrderSingle50() (msg *quickfix.Message) {
order.Set(queryStopPx())
}

order.Set(queryTimeInForce())

msg = order.ToMessage()
queryHeader(&msg.Header)

Expand Down
48 changes: 46 additions & 2 deletions cmd/tradeclient/tradeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package tradeclient

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"path"
"strconv"

"github.com/quickfixgo/examples/cmd/tradeclient/internal"
"github.com/quickfixgo/examples/cmd/utils"
Expand All @@ -34,10 +36,12 @@ type TradeClient struct {
}

// OnCreate implemented as part of Application interface
func (e TradeClient) OnCreate(sessionID quickfix.SessionID) {}
func (e TradeClient) OnCreate(sessionID quickfix.SessionID) {
}

// OnLogon implemented as part of Application interface
func (e TradeClient) OnLogon(sessionID quickfix.SessionID) {}
func (e TradeClient) OnLogon(sessionID quickfix.SessionID) {
}

// OnLogout implemented as part of Application interface
func (e TradeClient) OnLogout(sessionID quickfix.SessionID) {}
Expand All @@ -58,7 +62,17 @@ func (e TradeClient) ToApp(msg *quickfix.Message, sessionID quickfix.SessionID)

// FromApp implemented as part of Application interface. This is the callback for all Application level messages from the counter party.
func (e TradeClient) FromApp(msg *quickfix.Message, sessionID quickfix.SessionID) (reject quickfix.MessageRejectError) {
fmt.Println()
fmt.Println()
utils.PrintInfo(fmt.Sprintf("FromApp: %s", msg.String()))
typeString, _ := msg.MsgType()
utils.PrintInfo(fmt.Sprintf("Response type: %s", typeString))
for _, tag := range msg.Body.Tags() {
value, _ := msg.Body.GetString(tag)
intVar, _ := strconv.Atoi(fmt.Sprintf("%v", tag))
utils.PrintInfo(fmt.Sprintf("%s: %v", Dic.TagField[intVar].Name, value))
}

return
}

Expand All @@ -80,7 +94,37 @@ var (
}
)

type FixDicField struct {
Tag int `json:"Tag"`
Name string `json:"Name"`
Type string `json:"Type"`
}

type FixDic struct {
FixVersion string `json:"FixVersion"`
Fields []FixDicField `json:"Fields"`
TagField map[int]FixDicField `json:"-"`
}

var Dic FixDic

func execute(cmd *cobra.Command, args []string) error {
file, err := os.ReadFile("./dictionary/fix5.json")
if err != nil {
fmt.Println(err)
}

err = json.Unmarshal(file, &Dic)
if err != nil {
fmt.Println(err)
}

Dic.TagField = make(map[int]FixDicField, 0)

for _, field := range Dic.Fields {
Dic.TagField[field.Tag] = field
}

var cfgFileName string
argLen := len(args)
switch argLen {
Expand Down
19 changes: 2 additions & 17 deletions config/ordermatch.cfg
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
[DEFAULT]
SocketAcceptPort=5001
SenderCompID=ISLD
TargetCompID=TW
ResetOnLogon=Y
FileLogPath=tmp

[SESSION]
BeginString=FIX.4.0

[SESSION]
BeginString=FIX.4.1

[SESSION]
BeginString=FIX.4.2

[SESSION]
BeginString=FIX.4.3

[SESSION]
BeginString=FIX.4.4

[SESSION]
BeginString=FIXT.1.1
SenderCompID=T
TargetCompID=S
DefaultApplVerID=7
21 changes: 3 additions & 18 deletions config/tradeclient.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@
SocketConnectHost=127.0.0.1
SocketConnectPort=5001
HeartBtInt=30
SenderCompID=TW
TargetCompID=ISLD
ResetOnLogon=Y
FileLogPath=tmp

[SESSION]
BeginString=FIX.4.0

[SESSION]
BeginString=FIX.4.1

[SESSION]
BeginString=FIX.4.2

[SESSION]
BeginString=FIX.4.3

[SESSION]
BeginString=FIX.4.4

[SESSION]
BeginString=FIXT.1.1
DefaultApplVerID=7
SenderCompID=S
TargetCompID=T
DefaultApplVerID=7
Loading