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

Load test exemple wip #43

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"github.com/quickfixgo/examples/cmd/executor"
"github.com/quickfixgo/examples/cmd/loadtest"
"github.com/quickfixgo/examples/cmd/ordermatch"
"github.com/quickfixgo/examples/cmd/tradeclient"
"github.com/quickfixgo/examples/version"
Expand Down Expand Up @@ -45,6 +46,7 @@ func Execute() error {
c.AddCommand(executor.Cmd)
c.AddCommand(ordermatch.Cmd)
c.AddCommand(tradeclient.Cmd)
c.AddCommand(loadtest.Cmd)
c.Flags().BoolVarP(&versionF, "version", "v", false, "show the version and exit")
return c.Execute()
}
43 changes: 43 additions & 0 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package loadtest

import (
"fmt"
"time"

"github.com/spf13/cobra"
)

var (
// Cmd is the load test command.
Cmd = &cobra.Command{
Use: "loadtest",
Short: "Perform load testing by sending FIX orders",
Long: "Load testing tool for sending multiple FIX orders at a configurable rate.",
Example: "qf loadtest --orders 100 --rate 10",
RunE: execute,
}

orderCount int
rate int
)

func init() {
Cmd.Flags().IntVarP(&orderCount, "orders", "o", 100, "Number of orders to send")
Cmd.Flags().IntVarP(&rate, "rate", "r", 10, "Orders per second")
}

func execute(cmd *cobra.Command, args []string) error {
fmt.Printf("Starting load test: %d orders at %d orders/second\n", orderCount, rate)

for i := 0; i < orderCount; i++ {
sendOrder(i) // Replace this with actual order sending logic
time.Sleep(time.Second / time.Duration(rate)) // Control the rate
}

return nil
}

// sendOrder is a stub for sending an order. Replace with actual implementation.
func sendOrder(orderID int) {
fmt.Printf("Order %d sent\n", orderID)
}
115 changes: 107 additions & 8 deletions cmd/ordermatch/ordermatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ import (
"path"
"strconv"
"syscall"
"time"

"github.com/quickfixgo/enum"
"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/fix44/executionreport"
"github.com/quickfixgo/fix44/marketdatarequest"
"github.com/quickfixgo/fix44/marketdatasnapshotfullrefresh"

"github.com/quickfixgo/fix44/newordersingle"
"github.com/quickfixgo/fix44/ordercancelrequest"
"github.com/shopspring/decimal"
"github.com/spf13/cobra"

"github.com/quickfixgo/quickfix"
Expand Down Expand Up @@ -77,11 +81,13 @@ func (a Application) ToApp(msg *quickfix.Message, sessionID quickfix.SessionID)

// FromAdmin implemented as part of Application interface
func (a Application) FromAdmin(msg *quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
fmt.Printf("FromAdmin ###########>%+v\n", msg)
return nil
}

// FromApp implemented as part of Application interface, uses Router on incoming application messages
func (a *Application) FromApp(msg *quickfix.Message, sessionID quickfix.SessionID) (reject quickfix.MessageRejectError) {
fmt.Printf("FromApp ###########>\n")
return a.Route(msg, sessionID)
}

Expand Down Expand Up @@ -176,7 +182,49 @@ func (a *Application) onOrderCancelRequest(msg ordercancelrequest.OrderCancelReq

func (a *Application) onMarketDataRequest(msg marketdatarequest.MarketDataRequest, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
fmt.Printf("%+v\n", msg)
return
marketdatafullrefresh := marketdatasnapshotfullrefresh.New()

marketdatafullrefresh.SetSymbol("BTC/USD")
marketdatafullrefresh.SetMDReqID("MDReq1")
marketdatafullrefresh.SetProduct(enum.Product_CURRENCY)

noMDEntriesRptGrp := marketdatasnapshotfullrefresh.NewNoMDEntriesRepeatingGroup()

median_px := 68000.0
for i := 0; i < 5; i++ {
sz := decimal.NewFromInt(int64(i + 1))
noMDEntries0 := noMDEntriesRptGrp.Add()
noMDEntries0.SetMDEntryType(enum.MDEntryType_BID)
var bid_px = median_px - (float64(i+1) * 5.0)
p0 := decimal.NewFromFloat(bid_px)
noMDEntries0.SetMDEntryPx(p0, 5)
noMDEntries0.SetMDEntrySize(sz, 2)

noMDEntries1 := noMDEntriesRptGrp.Add()
noMDEntries1.SetMDEntryType(enum.MDEntryType_OFFER)
var off_px = median_px + (float64(i+1) * 5.0)
p1 := decimal.NewFromFloat(off_px)
noMDEntries1.SetMDEntryPx(p1, 5)
noMDEntries1.SetMDEntrySize(sz, 2)
}

marketdatafullrefresh.SetNoMDEntries(noMDEntriesRptGrp)

marketdatafullrefresh.Header.SetTargetCompID("TW")
marketdatafullrefresh.Header.SetSenderCompID("ISLD")

sendErr := quickfix.Send(marketdatafullrefresh)

if sendErr != nil {
fmt.Println(sendErr)
}

errUpdate := StartUpdateRefresh()
if errUpdate != nil {
fmt.Printf("failed to start update refresher!!")
}

return nil
}

func (a *Application) acceptOrder(order internal.Order) {
Expand Down Expand Up @@ -204,21 +252,22 @@ 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.NewExecTransType(enum.ExecTransType_NEW),
field.NewExecType(enum.ExecType(status)),
field.NewOrdStatus(status),
field.NewSymbol(order.Symbol),
//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)

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 All @@ -232,6 +281,56 @@ func (a *Application) updateOrder(order internal.Order, status enum.OrdStatus) {

}

func StartUpdateRefresh() (err error) {
fmt.Printf("StartUpdateRefresh==>")
go func() {
for j := 0; ; j++ {

time.Sleep(20 * time.Second)

marketdatafullrefresh := marketdatasnapshotfullrefresh.New()

marketdatafullrefresh.SetSymbol("BTC/USD")
marketdatafullrefresh.SetMDReqID("MDReq" + fmt.Sprint(j))
marketdatafullrefresh.SetProduct(enum.Product_CURRENCY)

noMDEntriesRptGrp := marketdatasnapshotfullrefresh.NewNoMDEntriesRepeatingGroup()

median_px := 68000.0 + float64(j*2)
for i := 0; i < 5; i++ {
sz := decimal.NewFromInt(int64(i + 1))
sprd := float64(i+1) * 5.0

noMDEntries0 := noMDEntriesRptGrp.Add()
noMDEntries0.SetMDEntryType(enum.MDEntryType_BID)
var bid_px = median_px - sprd
p0 := decimal.NewFromFloat(bid_px)
noMDEntries0.SetMDEntryPx(p0, 5)
noMDEntries0.SetMDEntrySize(sz, 2)

noMDEntries1 := noMDEntriesRptGrp.Add()
noMDEntries1.SetMDEntryType(enum.MDEntryType_OFFER)
var off_px = median_px + sprd
p1 := decimal.NewFromFloat(off_px)
noMDEntries1.SetMDEntryPx(p1, 5)
noMDEntries1.SetMDEntrySize(sz, 2)
}

marketdatafullrefresh.SetNoMDEntries(noMDEntriesRptGrp)

marketdatafullrefresh.Header.SetTargetCompID("TW")
marketdatafullrefresh.Header.SetSenderCompID("ISLD")

sendErr := quickfix.Send(marketdatafullrefresh)

if sendErr != nil {
fmt.Println(sendErr)
}
}
}()
return nil
}

const (
usage = "ordermatch"
short = "Start an order matching (FIX acceptor) service"
Expand Down
Loading
Loading