@@ -7,6 +7,53 @@ A Python library to retrieve data from Pyth account structures off the Solana bl
77
88** NOTE** : This library requires Python 3.7 or greater due to ` from __future__ import annotations ` .
99
10+ Usage
11+ --------------
12+
13+ Install the library:
14+
15+ pip install pythclient
16+
17+ You can then read the current Pyth price using the following:
18+
19+ ```
20+ from pythclient.pythclient import PythClient
21+ from pythclient.pythaccounts import PythPriceAccount
22+ from pythclient.utils import get_key
23+
24+ solana_network="devnet"
25+ async with PythClient(
26+ first_mapping_account_key=get_key(solana_network, "mapping"),
27+ program_key=get_key(solana_network, "program") if use_program else None,
28+ ) as c:
29+ await c.refresh_all_prices()
30+ products = await c.get_products()
31+ for p in products:
32+ print(p.attrs)
33+ prices = await p.get_prices()
34+ for _, pr in prices.items():
35+ print(
36+ pr.price_type,
37+ pr.aggregate_price,
38+ "p/m",
39+ pr.aggregate_price_confidence_interval,
40+ )
41+ ```
42+
43+ This code snippet lists the products on pyth and the price for each product. Sample output is:
44+
45+ ```
46+ {'symbol': 'Crypto.ETH/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'ETH/USD', 'generic_symbol': 'ETHUSD', 'base': 'ETH'}
47+ PythPriceType.PRICE 4390.286 p/m 2.4331
48+ {'symbol': 'Crypto.SOL/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SOL/USD', 'generic_symbol': 'SOLUSD', 'base': 'SOL'}
49+ PythPriceType.PRICE 192.27550000000002 p/m 0.0485
50+ {'symbol': 'Crypto.SRM/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SRM/USD', 'generic_symbol': 'SRMUSD', 'base': 'SRM'}
51+ PythPriceType.PRICE 4.23125 p/m 0.0019500000000000001
52+ ...
53+ ```
54+
55+ The library also includes an asynchronous API that updates the prices using a websocket subscription or account polling.
56+ See ` examples/dump.py ` for a more detailed usage example.
1057
1158Developer Setup
1259---------------
0 commit comments