Skip to content

Commit 1fd7cb1

Browse files
jayantkJayant Krishnamurthy
and
Jayant Krishnamurthy
authored
Add documentation for reading a single price account (#18)
* Add documentation for reading a single price account * PR comments Co-authored-by: Jayant Krishnamurthy <[email protected]>
1 parent 45f29b8 commit 1fd7cb1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ PythPriceType.PRICE 4.23125 p/m 0.0019500000000000001
5252
...
5353
```
5454

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.
55+
The `examples` directory includes some example applications that demonstrate how to use this library:
56+
* `examples/dump.py` is a detailed usage example that demonstrates the asynchronous API to update prices using a websocket subscription or account polling.
57+
* `examples/read_one_price_feed.py` shows how to read the price of a single price feed using its account key.
5758

5859
Developer Setup
5960
---------------

examples/read_one_price_feed.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
5+
from pythclient.pythaccounts import PythPriceAccount
6+
from pythclient.solana import SolanaClient, SolanaPublicKey, SOLANA_DEVNET_HTTP_ENDPOINT, SOLANA_DEVNET_WS_ENDPOINT
7+
8+
async def get_price():
9+
# devnet DOGE/USD price account key (available on pyth.network website)
10+
account_key = SolanaPublicKey("4L6YhY8VvUgmqG5MvJkUJATtzB2rFqdrJwQCmFLv4Jzy")
11+
solana_client = SolanaClient(endpoint=SOLANA_DEVNET_HTTP_ENDPOINT, ws_endpoint=SOLANA_DEVNET_WS_ENDPOINT)
12+
price: PythPriceAccount = PythPriceAccount(account_key, solana_client)
13+
14+
await price.update()
15+
# Sample output: "DOGE/USD is 0.141455 ± 7.4e-05"
16+
print("DOGE/USD is", price.aggregate_price, "±", price.aggregate_price_confidence_interval)
17+
18+
asyncio.run(get_price())

0 commit comments

Comments
 (0)