Skip to content

Commit

Permalink
Merge pull request #228 from vegaprotocol/227-allow-lp-shape-configur…
Browse files Browse the repository at this point in the history
…ation

Configure number of LP orders per side
  • Loading branch information
peterbarrow authored Oct 20, 2022
2 parents 90ca38d + 8ace24c commit 59e4320
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- [218](https://github.com/vegaprotocol/vegatools/issue/218) - perftest allows multiple LPs and moving of mid price for random orders
- [222](https://github.com/vegaprotocol/vegatools/issue/222) - Updated market proposal text with renamed fields
- [225](https://github.com/vegaprotocol/vegatools/issue/225) - Add option to dump total event counts
- [227](https://github.com/vegaprotocol/vegatools/issue/227) - Allow configuration of the LP shape

### 🐛 Fixes
- [78](https://github.com/vegaprotocol/vegatools/pull/78) - Fix build with missing dependency
Expand Down
1 change: 1 addition & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
perfTestCmd.Flags().IntVarP(&opts.UserCount, "users", "u", 10, "number of users to send commands with")
perfTestCmd.Flags().IntVarP(&opts.MarketCount, "markets", "m", 1, "number of markets to create and use")
perfTestCmd.Flags().IntVarP(&opts.Voters, "voters", "v", 3, "number of accounts to assign voting power")
perfTestCmd.Flags().IntVarP(&opts.LPOrdersPerSide, "lporders", "l", 3, "number of orders per side in the LP shape")
perfTestCmd.Flags().BoolVarP(&opts.MoveMid, "movemidprice", "p", false, "allow the mid price we place orders around to move randomly")
perfTestCmd.MarkFlagRequired("address")
perfTestCmd.MarkFlagRequired("wallet")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72
code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d
code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1
github.com/cosmos/iavl v0.19.1
github.com/ethereum/go-ethereum v1.10.21
github.com/gdamore/tcell/v2 v2.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72 h1:BJwmbEbC+ujqLSA1dSyUwDOc4+aRoZcndj/RM210CtE=
code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72/go.mod h1:P9MfU2GyzI4Vc7OrKx9+qN9JV0bNGFB/aYe0++e7158=
code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d h1:9CJJLpF/oldVly33eZi1lQKTGwkVEgNnMx3XxV+yipU=
code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d/go.mod h1:FQ3Q23aHsBNIzNL4YyTab2w/cleZQlr/vPfhQym04v4=
code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1 h1:zqPMCOusWpPDPsm8f25fLIxv9cU95nFsIfdvYWTv0KQ=
code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1/go.mod h1:G9A0haG9Qf0GNd6oza8UeDxF9hDVHRwM+1OkUcZnfac=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
Expand Down
72 changes: 45 additions & 27 deletions perftest/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

datanode "code.vegaprotocol.io/vega/protos/data-node/api/v1"
datanode "code.vegaprotocol.io/vega/protos/data-node/api/v2"
proto "code.vegaprotocol.io/vega/protos/vega"
v1 "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)
Expand All @@ -17,82 +17,100 @@ type dnWrapper struct {
wallet walletWrapper
}

func (d *dnWrapper) getNetworkParam(param string) (string, error) {
request := &datanode.GetNetworkParameterRequest{
Key: param,
}

response, err := d.dataNode.GetNetworkParameter(context.Background(), request)
if err != nil {
return "", err
}

return response.NetworkParameter.Value, nil
}

func (d *dnWrapper) getAssets() (map[string]string, error) {
request := &datanode.AssetsRequest{}
request := &datanode.ListAssetsRequest{}

response, err := d.dataNode.Assets(context.Background(), request)
response, err := d.dataNode.ListAssets(context.Background(), request)
if err != nil {
return nil, err
}
assets := map[string]string{}
for _, asset := range response.Assets {
assets[asset.Details.Symbol] = asset.Id
for _, asset := range response.GetAssets().GetEdges() {
assets[asset.Node.Details.Symbol] = asset.Node.Id
}
return assets, nil
}

func (d *dnWrapper) getAssetsPerUser(pubKey, asset string) (int64, error) {
request := &datanode.PartyAccountsRequest{
PartyId: pubKey,
Asset: asset,
request := &datanode.ListAccountsRequest{
Filter: &datanode.AccountFilter{
AssetId: asset,
PartyIds: []string{pubKey},
AccountTypes: []proto.AccountType{
proto.AccountType_ACCOUNT_TYPE_GENERAL,
},
},
}

response, err := d.dataNode.PartyAccounts(context.Background(), request)
response, err := d.dataNode.ListAccounts(context.Background(), request)
if err != nil {
return 0, err
}
for _, account := range response.Accounts {
if account.Type == proto.AccountType_ACCOUNT_TYPE_GENERAL {
return strconv.ParseInt(account.Balance, 10, 64)
}
for _, account := range response.Accounts.Edges {
return strconv.ParseInt(account.Account.Balance, 10, 64)
}
return 0, nil
}

func (d *dnWrapper) getMarkets() []string {
marketsReq := &datanode.MarketsRequest{}
marketsReq := &datanode.ListMarketsRequest{}

response, err := d.dataNode.Markets(context.Background(), marketsReq)
response, err := d.dataNode.ListMarkets(context.Background(), marketsReq)
if err != nil {
log.Println(err)
return nil
}
marketIDs := []string{}
for _, market := range response.Markets {
if market.State != proto.Market_STATE_REJECTED {
marketIDs = append(marketIDs, market.Id)
for _, market := range response.Markets.Edges {
if market.Node.State != proto.Market_STATE_REJECTED {
marketIDs = append(marketIDs, market.Node.Id)
}
}
return marketIDs
}

func (d *dnWrapper) getPendingProposalID() (string, error) {
request := &datanode.GetProposalsRequest{}
request := &datanode.ListGovernanceDataRequest{}

response, err := d.dataNode.GetProposals(context.Background(), request)
response, err := d.dataNode.ListGovernanceData(context.Background(), request)
if err != nil {
log.Println(err)
}

for _, proposal := range response.GetData() {
if proposal.Proposal.State == proto.Proposal_STATE_OPEN {
return proposal.Proposal.Id, nil
for _, proposal := range response.Connection.Edges {
if proposal.Node.Proposal.State == proto.Proposal_STATE_OPEN {
return proposal.Node.Proposal.Id, nil
}
}
return "", fmt.Errorf("no pending proposals found")
}

func (d *dnWrapper) waitForMarketEnactment(marketID string, maxWaitSeconds int) error {
request := &datanode.GetProposalsRequest{}
request := &datanode.ListGovernanceDataRequest{
ProposalReference: &marketID,
}

for i := 0; i < maxWaitSeconds; i++ {
response, err := d.dataNode.GetProposals(context.Background(), request)
response, err := d.dataNode.ListGovernanceData(context.Background(), request)
if err != nil {
return err
}

for _, proposal := range response.GetData() {
if proposal.Proposal.State == proto.Proposal_STATE_ENACTED {
for _, proposal := range response.Connection.Edges {
if proposal.Node.Proposal.State == proto.Proposal_STATE_ENACTED {
return nil
}
}
Expand Down
21 changes: 17 additions & 4 deletions perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"log"
"math/rand"
"strconv"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

datanode "code.vegaprotocol.io/vega/protos/data-node/api/v1"
datanode "code.vegaprotocol.io/vega/protos/data-node/api/v2"
proto "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)
Expand All @@ -27,6 +28,7 @@ type Opts struct {
MarketCount int
Voters int
MoveMid bool
LPOrdersPerSide int
}

type perfLoadTesting struct {
Expand Down Expand Up @@ -103,7 +105,7 @@ func (p *perfLoadTesting) depositTokens(assets map[string]string, faucetURL, gan
return nil
}

func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters int) ([]string, error) {
func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters, maxLPShape int) ([]string, error) {
markets := p.dataNode.getMarkets()
if len(markets) == 0 {
for i := 0; i < numberOfMarkets; i++ {
Expand Down Expand Up @@ -132,7 +134,7 @@ func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters int) ([]
for i := 0; i < len(markets); i++ {
// Send in a liquidity provision so we can get the market out of auction
for j := 0; j < voters; j++ {
p.wallet.SendLiquidityProvision(p.users[j], markets[i])
p.wallet.SendLiquidityProvision(p.users[j], markets[i], maxLPShape)
}

p.wallet.SendOrder(p.users[0], &commandspb.OrderSubmission{MarketId: markets[i],
Expand Down Expand Up @@ -317,9 +319,20 @@ func Run(opts Opts) error {
}
fmt.Println("Complete")

networkParam, err := plt.dataNode.getNetworkParam("market.liquidityProvision.shapes.maxSize")
if err != nil {
fmt.Println("Failed to get LP maximum shape size")
return err
}
maxLPShape, _ := strconv.ParseInt(networkParam, 0, 32)

if opts.LPOrdersPerSide > int(maxLPShape) {
return fmt.Errorf("supplied lp size greater than network param (%d>%d)", opts.LPOrdersPerSide, maxLPShape)
}

// Send in a proposal to create a new market and vote to get it through
fmt.Print("Proposing and voting in new market...")
marketIDs, err := plt.proposeAndEnactMarket(opts.MarketCount, opts.Voters)
marketIDs, err := plt.proposeAndEnactMarket(opts.MarketCount, opts.Voters, opts.LPOrdersPerSide)
if err != nil {
fmt.Println("FAILED")
return err
Expand Down
56 changes: 21 additions & 35 deletions perftest/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log"
"net/http"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -360,48 +361,33 @@ func (w *walletWrapper) SendNewMarketProposal(marketIndex int, user UserDetails)
return w.SignSubmitTx(user.token, cmd)
}

func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string) error {
func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string, orderCount int) error {
lp := commandspb.LiquidityProvisionSubmission{
MarketId: marketID,
Reference: "MarketLiquidity",
Fee: "0.01",
CommitmentAmount: "50000000",
Buys: []*proto.LiquidityOrder{
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID,
Proportion: 10,
Offset: "1000",
},
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID,
Proportion: 10,
Offset: "1500",
},
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_MID,
Proportion: 10,
Offset: "2000",
},
},
Sells: []*proto.LiquidityOrder{
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK,
Proportion: 10,
Offset: "2000",
},
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK,
Proportion: 10,
Offset: "1500",
},
{
Reference: proto.PeggedReference_PEGGED_REFERENCE_MID,
Proportion: 10,
Offset: "1000",
},
},
}

// Generate the buy and sell side LP orders
buys := make([]*proto.LiquidityOrder, orderCount)
sells := make([]*proto.LiquidityOrder, orderCount)
for i := 0; i < orderCount; i++ {
buys[i] = &proto.LiquidityOrder{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID,
Proportion: 10,
Offset: strconv.FormatInt(int64(1000+(i*10)), 10),
}
sells[i] = &proto.LiquidityOrder{
Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK,
Proportion: 10,
Offset: strconv.FormatInt(int64(1000+(i*10)), 10),
}
}

lp.Buys = buys
lp.Sells = sells

m := jsonpb.Marshaler{}

submitTxReq := &walletpb.SubmitTransactionRequest{
Expand Down

0 comments on commit 59e4320

Please sign in to comment.