github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/query/52_MarketVolatility/example.go (about) 1 package main 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 8 "github.com/InjectiveLabs/sdk-go/chain/exchange/types" 9 10 "os" 11 12 "github.com/InjectiveLabs/sdk-go/client" 13 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 14 "github.com/InjectiveLabs/sdk-go/client/common" 15 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 16 ) 17 18 func main() { 19 network := common.LoadNetwork("testnet", "lb") 20 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 21 if err != nil { 22 panic(err) 23 } 24 25 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 26 os.Getenv("HOME")+"/.injectived", 27 "injectived", 28 "file", 29 "inj-user", 30 "12345678", 31 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 32 false, 33 ) 34 35 if err != nil { 36 panic(err) 37 } 38 39 clientCtx, err := chainclient.NewClientContext( 40 network.ChainId, 41 senderAddress.String(), 42 cosmosKeyring, 43 ) 44 45 if err != nil { 46 panic(err) 47 } 48 49 clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) 50 51 chainClient, err := chainclient.NewChainClient( 52 clientCtx, 53 network, 54 common.OptionGasPrices(client.DefaultGasPriceWithDenom), 55 ) 56 57 if err != nil { 58 panic(err) 59 } 60 61 ctx := context.Background() 62 63 marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" 64 tradeHistoryOptions := types.TradeHistoryOptions{ 65 TradeGroupingSec: 10, 66 MaxAge: 0, 67 IncludeRawHistory: true, 68 IncludeMetadata: true, 69 } 70 71 res, err := chainClient.FetchMarketVolatility(ctx, marketId, &tradeHistoryOptions) 72 if err != nil { 73 fmt.Println(err) 74 } 75 76 str, _ := json.MarshalIndent(res, "", " ") 77 fmt.Print(string(str)) 78 79 }