Consuming Data
Full scope of what you can do with Pragma
You can find the list of supported assets here.
The current Pragma addresses are:
Network | Address | Explorer |
---|---|---|
Starknet Mainnet | 0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b | Starkscan Voyager |
Starknet Sepolia | 0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a | Starkscan Voyager |
Sample Code
If you are just trying to get started with our price feeds, see the self-contained code snippets below. If you’d like to use more advanced oracle functions please see the further information below. You can find a full sample data feed consumer contract here and the full Oracle interface specification is available here.
Add Pragma as a dependency to your scarb/snforge project
BTC/USD Spot Median Price
SOL/USD Spot Average Price, filtered by sources
BTC/USD Future Price
Conversion Rate
For some assets such as liquid staking tokens, it’s actually more relevant to use the conversion rate rather than the market price given the liquidity is often poor for these assets. To use this special aggregation method, the base token first needs to be associated to a vault address which follows the ERC4626 standard.
Sample code
Alternatively, we implemented a specialized conversion rate feed that automatically calculates the conversion rate for specific feeds. Calling these feeds follows a process similar to retrieving spot BTC/USD prices.
Supported feeds:
Pair | Pair Id | Decimals |
---|---|---|
CONVERSION_XSTRK/USD | 384270964630611589151504336040175440891848512324 | 8 |
CONVERSION_SSTRK/USD | 384270964630611589151504335947941720523300754244 | 8 |
It will only work with the Median
aggregation mode.
Technical Specification
get_data_median
get_data_median
Function: get_data_median
The simplest function that aggregates all data into a median for a given data type.
Inputs
data_type
: enum of the data type you are requesting (See DataType structure). By providing the enum data type, you also provide the pair id (for spot entries), or the pair id and the expiration timestamp (for futures).
Returns
A PragmaPricesResponse
struct containing:
price
: aggregation result using robust median algorithm (multiplied by10**decimals
)decimals
: number of places value has been shiftedlast_updated_timestamp
: timestamp of most recent entrynum_sources_aggregated
: number of sources in final answerexpiration_timestamp
: expiration timestamp (futures only)
get_data_median_for_sources
get_data_median_for_sources
Function: get_data_median_for_sources
Aggregates data from specified sources into a median for a given data type.
Inputs
data_type
: enum of data type requested (provides pair id or pair id + expiration timestamp)sources
: array of sources to aggregate (Span of felt252)
Returns
A PragmaPricesResponse
struct containing:
price
: median aggregation result (multiplied by10**decimals
)decimals
: decimal places shiftedlast_updated_timestamp
: most recent entry timestampnum_sources_aggregated
: source count in final resultexpiration_timestamp
: expiration time (futures only)
get_data
get_data
Function: get_data
Like get_data_median but with custom aggregation logic options.
Inputs
data_type
: enum of requested data typeaggregation_mode
: mode for combining data sources (MEDIAN, MEAN, or CONVERSIONRATE)
Returns
price
: aggregated result using specified mode (multiplied by10**decimals
)decimals
: decimal places shiftedlast_updated_timestamp
: most recent entry timestampnum_sources_aggregated
: sources in final answerexpiration_timestamp
: expiration time (futures only)
get_data_with_USD_hop
get_data_with_USD_hop
Function: get_data_with_USD_hop
Enables price rebasing with different base currency (e.g., BTC/ETH from BTC/USD and ETH/USD).
Inputs
base_currency_id
: base currency felt252 (e.g., BTC)quote_currency_id
: quote currency felt252 (e.g., ETH)aggregation_mode
: combining mode (MEDIAN, MEAN, CONVERSIONRATE)typeof
: SimpleDataType enumexpiration_timestamp
: expiration time (futures only)
Returns
price
: aggregated result (multiplied by10**decimals
)decimals
: decimal shiftlast_updated_timestamp
: latest entry timenum_sources_aggregated
: source countexpiration_timestamp
: expiration (futures only)
get_data_for_sources
get_data_for_sources
Function: get_data_for_sources
Gets price with specified currency path and sources.
Inputs
data_type
: data type enumaggregation_mode
: combining mode (MEDIAN, MEAN, CONVERSIONRATE)sources
: source array (Span of felt252)
Returns
price
: aggregated result (multiplied by10**decimals
)decimals
: decimal placeslast_updated_timestamp
: latest update timenum_sources_aggregated
: source countexpiration_timestamp
: expiration (futures only)
get_data_entry
get_data_entry
Function: get_data_entry
Retrieves most recent raw data point for specific asset, source, and publisher.
Inputs
data_type
: data type enumsource
: uppercased UTF8-encoded source (e.g.,str_to_felt("GEMINI")
)publisher
: publisher to consider (e.g.,str_to_felt("PRAGMA")
)
Returns
possible_entry
: PossibleEntry enum containing base entry (timestamp, source, publisher) and additional data (type, price, volume)
get_data_entries
get_data_entries
get_data_entries_for_sources
get_data_entries_for_sources
get_last_checkpoint_before
get_last_checkpoint_before
get_latest_checkpoint_index
get_latest_checkpoint_index