P
P
Pyth
Search…
Account Structure
The Pyth price oracle manages a number of on-chain accounts. There are three different types of accounts:
  1. 1.
    Product accounts store metadata about a product, such as its symbol (e.g., "BTC/USD") and asset type.
  2. 2.
    Price accounts store the current price information for a particular product. This account has fields such as the current price, a confidence interval, a time-weighted average price, and whether or not a price is currently available.
  3. 3.
    Mapping accounts serve as a listing of other accounts. The mapping accounts are organized into a linked list whose values are the set of product accounts. These accounts allow applications to enumerate the full list of products whose prices are available on Pyth.
The Pyth Rust Client Library contains a sample application that prints the current content of all Pyth accounts. We will use the output of this application to better understand the content of these accounts.
Product Accounts
Product accounts store metadata about a product. This metadata is represented as a set of reference attributes, stored as a list of text key/value pairs. For example, the product account for AAPL contains the following fields:
1
product_account .. 4SxmcsbJWVBWvuP2cRQDjFtAgdqzWWLbHESnUTH4CegT
2
symbol.......... AAPL/USD
3
asset_type...... Equity
4
country......... US
5
quote_currency.. USD
6
tenor........... Spot
7
description..... APPLE INC
8
cms_symbol...... AAPL
9
cqs_symbol...... AAPL
10
nasdaq_symbol... AAPL
11
price_account .. CeLD8TC7Ktv2o57EHP7rddh6TZBHXkAhTyfWgxsTYs21
Copied!
This snippet shows the reference attributes for AAPL. The set of available reference attributes depends on the asset_type. Every product has symbol, asset_type, quote_currency and tenor. US equity products additionally include additional reference symbology that is useful for mapping Pyth products to other industry-standard identifiers. The product account also contains a pointer to a price account that contains the product's current pricing information.
As another example, here is the product account for BTC/USD:
1
product_account .. 9BQ2WKSVbfzpSJYyLCJuxVuiUFxHmQvkhhez94AdffEZ
2
symbol.......... BTC/USD
3
asset_type...... Crypto
4
country......... US
5
quote_currency.. USD
6
tenor........... Spot
7
jlqd_symbol..... BTCUSD
8
price_account .. FCLf9N8xcN9HBA9Cw68FfEZoSBr4bYYJtyRxosNzswMH
Copied!
Price Accounts
Price accounts store the current price of a product along with additional useful information. For example, consider the following content of AAPL's price account:
1
price_account .. CeLD8TC7Ktv2o57EHP7rddh6TZBHXkAhTyfWgxsTYs21
2
price_type ... price
3
exponent ..... -5
4
status ....... trading
5
corp_act ..... nocorpact
6
price ........ 12276250
7
conf ......... 1500
8
valid_slot ... 55519683
9
publish_slot . 55519684
Copied!
This account stores the current price in a fixed-point format. The price is computed by taking the price field and multiplying by 10^exponent. The account also includes a confidence interval that represents Pyth's uncertainty about the current price. This confidence interval can be interpreted as the standard deviation of a normal distribution centered around the price. conf is also stored in the same fixed-point format. In the example above, the price is 12276250, the conf is 1500 and the exponent is -5. These values translate into a price of $122.76250 +- 0.15.
Price accounts include several other useful fields. First, each account has a status that indicates whether or not the price is valid. Pricing information for a product can be unavailable for various reasons, for example, US equity markets only trade during certain hours. The status field indicates whether or not Pyth currently has a price for the product. Only prices with a value of status=trading should be used. If the status is not trading, the Pyth price can be an arbitrary value.
Mapping Accounts
Mapping accounts serve as an index of the pricing information currently available on Pyth. These accounts are organized into a linked list whose values are product accounts. Applications can traverse this linked list to enumerate all products currently available on Pyth.
The on-chain relationship between different account types is as follows:
1
------------- ------------- -------------
2
| |1 m| | | |
3
| mapping |------->| product |------>| price |
4
| | | | | |
5
------------- ------------- -------------
6
|
7
V
8
-------------
9
| |
10
| mapping |
11
| |
12
-------------
13
|
14
V
15
...
Copied!
Each mapping account contains a list of product account ids, plus an optional pointer to the subsequent mapping account. Each product account in turn points to the price account that stores the current price information for that product.
Last modified 2mo ago
Copy link