Skip to content

Commit

Permalink
Merge pull request #203 from InjectiveLabs/fix/update_oracle_price_ex…
Browse files Browse the repository at this point in the history
…amples

(fix) Updated examples for oracle price requests
  • Loading branch information
aarmoa committed Jan 17, 2024
2 parents 02cb6ed + c469534 commit 1abe3e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 9 additions & 4 deletions examples/exchange/oracle/1_StreamPrices/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ import (
"encoding/json"
"fmt"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"

"github.com/InjectiveLabs/sdk-go/client/common"
exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange"
)

func main() {
network := common.LoadNetwork("mainnet", "lb")
network := common.LoadNetwork("testnet", "lb")
exchangeClient, err := exchangeclient.NewExchangeClient(network)
if err != nil {
panic(err)
}

ctx := context.Background()
baseSymbol := "BTC"
quoteSymbol := "USDT"
oracleType := "bandibc"
marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient)
market := marketsAssistant.AllDerivativeMarkets()["0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"]

baseSymbol := market.OracleBase
quoteSymbol := market.OracleQuote
oracleType := market.OracleType
stream, err := exchangeClient.StreamPrices(ctx, baseSymbol, quoteSymbol, oracleType)
if err != nil {
panic(err)
Expand Down
15 changes: 10 additions & 5 deletions examples/exchange/oracle/2_Price/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import (
"encoding/json"
"fmt"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"

"github.com/InjectiveLabs/sdk-go/client/common"
exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange"
)

func main() {
network := common.LoadNetwork("mainnet", "lb")
network := common.LoadNetwork("testnet", "lb")
exchangeClient, err := exchangeclient.NewExchangeClient(network)
if err != nil {
panic(err)
}

ctx := context.Background()
baseSymbol := "BTC"
quoteSymbol := "USDT"
oracleType := "BandIBC"
oracleScaleFactor := uint32(6)
marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient)
market := marketsAssistant.AllDerivativeMarkets()["0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"]

baseSymbol := market.OracleBase
quoteSymbol := market.OracleQuote
oracleType := market.OracleType
oracleScaleFactor := uint32(0)
res, err := exchangeClient.GetPrice(ctx, baseSymbol, quoteSymbol, oracleType, oracleScaleFactor)
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 1abe3e3

Please sign in to comment.