Getting Prices
Getting prices from the Connect oracle
Building with Connect? Join our Discord!
Summary
Connect prices are stored within the x/oracle module.
On very specific chains - right now only dYdX - they live in a different storage module (in dYdX’s case, x/prices
).
These prices are updated on a per-block basis when there is a sufficient delta from the last block’s price. They can be accessed natively by CosmWasm smart contracts, other modules, or those with access to chain state.
Connect’s market configuration is stored in the x/marketmap. This module, unlike x/oracle
, does not store price data. Instead, it stores which currency pairs are supported and how they are configured.
Getting Supported Assets
Every chain will have a different set of supported assets. You can find out which assets are supported on your chain by either running:
- (REST):
curl http://localhost:1317/connect/marketmap/v2/marketmap
- (application cli):
appd q marketmap marketmap
- (gRPC):
grpcurl -plaintext localhost:9090 connect.marketmap.v2.Query/MarketMap
This will return a JSON list of supported assets with associated metadata.
Accessing Connect Prices over node APIs and RPC
To access all Connect prices (as of the last committed block):
- (REST):
curl http://localhost:1317/connect/oracle/v2/get_prices
- (gRPC):
grpcurl -plaintext localhost:9090 connect.oracle.v2.Query/GetPrices
To get a specific currency pair:
- (Get all currency pairs request)
appd q oracle currency-pairs
- (Get price request)
appd q oracle price [base] [quote]
Price Metadata within Connect
When calling getPrices
via the above methods, you are returned an array of GetPriceResponse
, each of which contains the following metadata about individual prices:
QuotePrice
- nonce
- decimals
- ID
GetPriceResponse
looks like this:
Inside QuotePrice
, you can fetch for the currency-pair:
- price
- timestamp of last update
- blockheight of last update
QuotePrice
looks like this: