Skip to content

Commit

Permalink
Merge pull request #305 from vegaprotocol/304-add-stop-orders
Browse files Browse the repository at this point in the history
feat: Adding stop order support in perftool
  • Loading branch information
peterbarrow authored Oct 3, 2023
2 parents 7166988 + be71de2 commit 9b3e91b
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: '1.20'
id: go

- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
go: ['1.19']
go: ['1.20']
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
- [281](https://github.com/vegaprotocol/vegatools/issues/281) - add a toggle to perftest to enable/disable lp users from creating initial orders
- [288](https://github.com/vegaprotocol/vegatools/issues/288) - stop processing per testing if the number of price levels is greater than the mid price
- [297](https://github.com/vegaprotocol/vegatools/issues/297) - update perftool to use the new SLA liquidity system
- [304](https://github.com/vegaprotocol/vegatools/issues/304) - update perftool to support stop orders


### 🐛 Fixes
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS builder
FROM golang:1.20-alpine AS builder
# Install git: required for fetching the Go dependencies.
RUN apk update && apk add --no-cache git
ENV GOPROXY=direct GOSUMDB=off
Expand Down
1 change: 1 addition & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func init() {
perfTestCmd.Flags().IntVarP(&opts.PriceLevels, "pricelevels", "L", 100, "number of price levels per side")
perfTestCmd.Flags().IntVarP(&opts.SLAUpdateSeconds, "slaupdate", "S", 10, "number of seconds between SLA updates")
perfTestCmd.Flags().IntVarP(&opts.SLAPriceLevels, "slapricelevels", "l", 3, "number of price levels for SLA orders")
perfTestCmd.Flags().IntVarP(&opts.StopOrders, "stoporders", "d", 0, "number of stop orders per user")
perfTestCmd.Flags().Int64VarP(&opts.StartingMidPrice, "startingmidprice", "s", 10000, "mid price to use at the start")
perfTestCmd.Flags().BoolVarP(&opts.MoveMid, "movemidprice", "M", false, "allow the mid price we place orders around to move randomly")
perfTestCmd.Flags().BoolVarP(&opts.FillPriceLevels, "fillpricelevel", "F", false, "place an order at every available price level")
Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module code.vegaprotocol.io/vegatools

go 1.19
go 1.20

require (
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f
code.vegaprotocol.io/vega v0.72.8
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a
code.vegaprotocol.io/vega v0.73.0-preview.8
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/iavl v0.20.0
github.com/ethereum/go-ethereum v1.11.6
github.com/gdamore/tcell/v2 v2.5.2
Expand All @@ -21,12 +22,9 @@ require (

require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cometbft/cometbft-db v0.7.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
Expand Down
18 changes: 4 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f h1:ivaWSXN7XKESShqYw/QFuT6b2mvThWPQLO7lW5sadHs=
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f/go.mod h1:XzX67GsyOHzvytMr0QOHX4CCTdCZDYKUUi88rx40Nt0=
code.vegaprotocol.io/vega v0.72.8 h1:WLIrubFNF/rpDHqmdS2HGWv/jUphjuBk7pS5AWgm6Eo=
code.vegaprotocol.io/vega v0.72.8/go.mod h1:4jz+8jy99maf7bop6JkxeyQplI+d+mmdf8Zgk+REyBg=
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a h1:sgniM6sgxPKAStJo2rNoYJR3NMlS/t55H12lvynkw5c=
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a/go.mod h1:XzX67GsyOHzvytMr0QOHX4CCTdCZDYKUUi88rx40Nt0=
code.vegaprotocol.io/vega v0.73.0-preview.8 h1:JhV92aCVUwBu+byA9Jy7Cxdf9j4IIJyj8Oiy8seE1OU=
code.vegaprotocol.io/vega v0.73.0-preview.8/go.mod h1:GVK9Ex2zdERQGOMsre49eVrlAPprkHe8M2l8O2MnBRM=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
Expand All @@ -13,8 +13,6 @@ github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y=
github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E=
github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand All @@ -36,8 +34,6 @@ github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38=
github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
Expand Down Expand Up @@ -169,7 +165,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220317090546-adb2f9614b17 h1:pxR+aWfo+famermIZvD+SiDQ3qmF7Iy2VPZuEsKTMtA=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
Expand All @@ -183,7 +178,6 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -203,7 +197,6 @@ github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNue
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
Expand Down Expand Up @@ -238,9 +231,6 @@ github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5f
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok=
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8=
github.com/tendermint/tendermint v0.35.9 h1:yUEgfkcNHWSidsU8wHjRDbYPVijV4cHxCclKVITGRAQ=
github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8=
github.com/tendermint/tm-db v0.6.7/go.mod h1:byQDzFkZV1syXr/ReXS808NxA2xvyuuVgXOJ/088L6I=
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
Expand Down
2 changes: 1 addition & 1 deletion networkhistorydivergencetool/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module networkhistorydivergencetool

go 1.19
go 1.20

require (
github.com/benbjohnson/clock v1.3.0 // indirect
Expand Down
75 changes: 75 additions & 0 deletions perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Opts struct {
PriceLevels int
SLAUpdateSeconds int
SLAPriceLevels int
StopOrders int
StartingMidPrice int64
FillPriceLevels bool
InitialiseOnly bool
Expand Down Expand Up @@ -216,6 +217,18 @@ func (p *perfLoadTesting) checkNetworkLimits(opts Opts) error {
return fmt.Errorf("supplied order batch size is greater than network param (%d>%d)", opts.BatchSize, maxBatchSize)
}

// Check the maximum number of stop orders per market per user
networkParam, err = p.dataNode.getNetworkParam("spam.protection.max.stopOrdersPerMarket")
if err != nil {
fmt.Println("Failed to get maximum order batch size")
return err
}
maxStopOrders, _ := strconv.ParseInt(networkParam, 0, 32)

if opts.StopOrders > int(maxStopOrders) {
return fmt.Errorf("supplied stop orders size is greater than network param (%d>%d)", opts.StopOrders, maxStopOrders)
}

// Make sure if we are adding price levels that we have enough space to put them all in given the mid price
if opts.FillPriceLevels {
if opts.PriceLevels > int(opts.StartingMidPrice) {
Expand Down Expand Up @@ -396,6 +409,57 @@ func (p *perfLoadTesting) seedPriceLevels(marketIDs []string, opts Opts) error {
return nil
}

func (p *perfLoadTesting) seedStopOrders(marketIDs []string, opts Opts) error {
// We need to go through all markets and all users
for _, marketID := range marketIDs {
order := &commandspb.OrderSubmission{
MarketId: marketID,
Size: 1,
Side: proto.Side_SIDE_SELL,
Type: proto.Order_TYPE_MARKET,
Reference: "StopLossOrder",
ReduceOnly: true,
TimeInForce: proto.Order_TIME_IN_FORCE_IOC}
for userOffset := opts.LpUserCount; userOffset < (opts.LpUserCount + opts.NormalUserCount); userOffset++ {
user := p.users[userOffset]

// We need a position before we can place a stop order
err := p.wallet.SendOrder(user, &commandspb.OrderSubmission{
MarketId: marketID,
Size: 1,
Side: proto.Side_SIDE_BUY,
Type: proto.Order_TYPE_MARKET,
TimeInForce: proto.Order_TIME_IN_FORCE_IOC,
})
if err != nil {
return err
}

time.Sleep(1 * time.Second)

sos := &commandspb.StopOrdersSubmission{
RisesAbove: &commandspb.StopOrderSetup{
OrderSubmission: order,
Trigger: &commandspb.StopOrderSetup_Price{
Price: fmt.Sprint(opts.StartingMidPrice + 1000),
},
},
FallsBelow: &commandspb.StopOrderSetup{
OrderSubmission: order,
Trigger: &commandspb.StopOrderSetup_Price{
Price: fmt.Sprint(opts.StartingMidPrice - 1000),
},
},
}
err = p.wallet.SendStopOrder(user, sos)
if err != nil {
return err
}
}
}
return nil
}

func (p *perfLoadTesting) sendSLAOrders(marketID string, deleteFirst bool, opts Opts) error {
for l := 0; l < opts.LpUserCount; l++ {
batch := &BatchOrders{}
Expand Down Expand Up @@ -780,6 +844,17 @@ func Run(opts Opts) error {
fmt.Println("Complete")
}

// Do we need to place stop orders for all users
if opts.StopOrders > 0 {
fmt.Print("Adding stop orders for every user and market...")
err = plt.seedStopOrders(marketIDs, opts)
if err != nil {
fmt.Println("FAILED")
return err
}
fmt.Println("Complete")
}

// If we are only initialising, stop now and return
if opts.InitialiseOnly {
// Make one more check that assets are topped up
Expand Down
31 changes: 31 additions & 0 deletions perftest/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

proto "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
"google.golang.org/protobuf/encoding/protojson"
)

// WalletWrapper holds details about the wallet
Expand Down Expand Up @@ -42,6 +43,22 @@ type listKeysResult struct {
ID string
}

func (w walletWrapper) sendTransactionString(user UserDetails, subType string, subData string) ([]byte, error) {
transactionStr := `{
"jsonrpc": "2.0",
"method": "client.send_transaction",
"id": "1",
"params": {
"publicKey":"` + user.pubKey + `",
"sendingMode": "TYPE_SYNC",
"transaction":{"` + subType + `":` + subData + `
}
}
}`

return w.sendRequest([]byte(transactionStr), user.token)
}

func (w walletWrapper) sendTransaction(user UserDetails, subType string, subData interface{}) ([]byte, error) {
transaction, _ := json.Marshal(map[string]interface{}{
"jsonrpc": "2.0",
Expand Down Expand Up @@ -183,6 +200,14 @@ func (w walletWrapper) NewMarket(offset int, user UserDetails) error {
"performanceHysteresisEpochs": 60,
"slaCompetitionFactor": "1.0",
},
"liquidityMonitoringParameters": map[string]interface{}{
"targetStakeParameters": map[string]interface{}{
"timeWindow": "100",
"scalingFactor": "1.0",
},
"triggeringRatio": "1.0",
"auctionExtension": "10",
},
},
},
},
Expand Down Expand Up @@ -213,6 +238,12 @@ func (w walletWrapper) GetFirstKey(longLivedToken string) (string, error) {
return "", nil
}

func (w *walletWrapper) SendStopOrder(user UserDetails, sos *commandspb.StopOrdersSubmission) error {
sosString, _ := protojson.Marshal(sos)
_, err := w.sendTransactionString(user, "stopOrdersSubmission", string(sosString))
return err
}

// SendBatchOrders sends a set of new order commands to the wallet
func (w *walletWrapper) SendBatchOrders(user UserDetails,
cancels []*commandspb.OrderCancellation,
Expand Down

0 comments on commit 9b3e91b

Please sign in to comment.