github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/13_MsgInstantBinaryOptionsMarketLaunch/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  	oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
    13  	exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange"
    14  
    15  	"github.com/InjectiveLabs/sdk-go/client"
    16  	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
    17  	"github.com/InjectiveLabs/sdk-go/client/common"
    18  	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
    19  )
    20  
    21  func main() {
    22  	network := common.LoadNetwork("testnet", "lb")
    23  	tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
    24  	if err != nil {
    25  		panic(err)
    26  	}
    27  
    28  	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
    29  		os.Getenv("HOME")+"/.injectived",
    30  		"injectived",
    31  		"file",
    32  		"inj-user",
    33  		"12345678",
    34  		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
    35  		false,
    36  	)
    37  
    38  	if err != nil {
    39  		panic(err)
    40  	}
    41  
    42  	clientCtx, err := chainclient.NewClientContext(
    43  		network.ChainId,
    44  		senderAddress.String(),
    45  		cosmosKeyring,
    46  	)
    47  
    48  	if err != nil {
    49  		panic(err)
    50  	}
    51  
    52  	clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
    53  
    54  	chainClient, err := chainclient.NewChainClient(
    55  		clientCtx,
    56  		network,
    57  		common.OptionGasPrices(client.DefaultGasPriceWithDenom),
    58  	)
    59  	if err != nil {
    60  		panic(err)
    61  	}
    62  
    63  	exchangeClient, err := exchangeclient.NewExchangeClient(network)
    64  	if err != nil {
    65  		panic(err)
    66  	}
    67  
    68  	ctx := context.Background()
    69  	marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient)
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  	quoteToken := marketsAssistant.AllTokens()["USDC"]
    75  	minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
    76  	minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
    77  
    78  	chainMinPriceTickSize := minPriceTickSize.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals)))
    79  	chainMinQuantityTickSize := minQuantityTickSize
    80  
    81  	msg := &exchangetypes.MsgInstantBinaryOptionsMarketLaunch{
    82  		Sender:              senderAddress.String(),
    83  		Ticker:              "UFC-KHABIB-TKO-05/30/2023",
    84  		OracleSymbol:        "UFC-KHABIB-TKO-05/30/2023",
    85  		OracleProvider:      "UFC",
    86  		OracleType:          oracletypes.OracleType_Provider,
    87  		OracleScaleFactor:   6,
    88  		MakerFeeRate:        math.LegacyMustNewDecFromStr("0.0005"),
    89  		TakerFeeRate:        math.LegacyMustNewDecFromStr("0.0010"),
    90  		ExpirationTimestamp: 1680730982,
    91  		SettlementTimestamp: 1690730982,
    92  		Admin:               senderAddress.String(),
    93  		QuoteDenom:          quoteToken.Denom,
    94  		MinPriceTickSize:    chainMinPriceTickSize,
    95  		MinQuantityTickSize: chainMinQuantityTickSize,
    96  	}
    97  
    98  	// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
    99  	response, err := chainClient.AsyncBroadcastMsg(msg)
   100  
   101  	if err != nil {
   102  		panic(err)
   103  	}
   104  
   105  	str, _ := json.MarshalIndent(response, "", " ")
   106  	fmt.Print(string(str))
   107  }