github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/25_MsgUpdateDerivativeMarket/example.go (about) 1 package main 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 "os" 8 9 "cosmossdk.io/math" 10 11 exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" 12 exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange" 13 14 "github.com/InjectiveLabs/sdk-go/client" 15 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 16 "github.com/InjectiveLabs/sdk-go/client/common" 17 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 18 ) 19 20 func main() { 21 network := common.LoadNetwork("testnet", "lb") 22 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 23 if err != nil { 24 panic(err) 25 } 26 27 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 28 os.Getenv("HOME")+"/.injectived", 29 "injectived", 30 "file", 31 "inj-user", 32 "12345678", 33 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 34 false, 35 ) 36 37 if err != nil { 38 panic(err) 39 } 40 41 clientCtx, err := chainclient.NewClientContext( 42 network.ChainId, 43 senderAddress.String(), 44 cosmosKeyring, 45 ) 46 47 if err != nil { 48 panic(err) 49 } 50 51 clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) 52 53 chainClient, err := chainclient.NewChainClient( 54 clientCtx, 55 network, 56 common.OptionGasPrices(client.DefaultGasPriceWithDenom), 57 ) 58 if err != nil { 59 panic(err) 60 } 61 62 exchangeClient, err := exchangeclient.NewExchangeClient(network) 63 if err != nil { 64 panic(err) 65 } 66 67 ctx := context.Background() 68 marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient) 69 if err != nil { 70 panic(err) 71 } 72 73 quoteToken := marketsAssistant.AllTokens()["USDT"] 74 minPriceTickSize := math.LegacyMustNewDecFromStr("0.1") 75 minQuantityTickSize := math.LegacyMustNewDecFromStr("0.1") 76 minNotional := math.LegacyMustNewDecFromStr("2") 77 78 chainMinPriceTickSize := minPriceTickSize.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals))) 79 chainMinQuantityTickSize := minQuantityTickSize 80 chainMinNotional := minNotional.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals))) 81 82 msg := &exchangetypes.MsgUpdateDerivativeMarket{ 83 Admin: senderAddress.String(), 84 MarketId: "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", 85 NewTicker: "INJ/USDT PERP 2", 86 NewMinPriceTickSize: chainMinPriceTickSize, 87 NewMinQuantityTickSize: chainMinQuantityTickSize, 88 NewMinNotional: chainMinNotional, 89 NewInitialMarginRatio: math.LegacyMustNewDecFromStr("0.4"), 90 NewMaintenanceMarginRatio: math.LegacyMustNewDecFromStr("0.085"), 91 } 92 93 // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg 94 response, err := chainClient.AsyncBroadcastMsg(msg) 95 96 if err != nil { 97 panic(err) 98 } 99 100 str, _ := json.MarshalIndent(response, "", " ") 101 fmt.Print(string(str)) 102 }