github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/3_MsgInstantSpotMarketLaunch/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 baseToken := marketsAssistant.AllTokens()["INJ"] 74 quoteToken := marketsAssistant.AllTokens()["USDC"] 75 minPriceTickSize := math.LegacyMustNewDecFromStr("0.01") 76 minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001") 77 minNotional := math.LegacyMustNewDecFromStr("1") 78 79 chainMinPriceTickSize := minPriceTickSize.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals))) 80 chainMinPriceTickSize = chainMinPriceTickSize.Quo(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(baseToken.Decimals))) 81 82 chainMinQuantityTickSize := minQuantityTickSize.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(baseToken.Decimals))) 83 chainMinNotional := minNotional.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals))) 84 85 msg := &exchangetypes.MsgInstantSpotMarketLaunch{ 86 Sender: senderAddress.String(), 87 Ticker: "INJ/USDC", 88 BaseDenom: baseToken.Denom, 89 QuoteDenom: quoteToken.Denom, 90 MinPriceTickSize: chainMinPriceTickSize, 91 MinQuantityTickSize: chainMinQuantityTickSize, 92 MinNotional: chainMinNotional, 93 } 94 95 // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg 96 response, err := chainClient.AsyncBroadcastMsg(msg) 97 98 if err != nil { 99 panic(err) 100 } 101 102 str, _ := json.MarshalIndent(response, "", " ") 103 fmt.Print(string(str)) 104 }