Skip to content

Add documentation for reading a single price account #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ PythPriceType.PRICE 4.23125 p/m 0.0019500000000000001
...
```

The library also includes an asynchronous API that updates the prices using a websocket subscription or account polling.
See `examples/dump.py` for a more detailed usage example.
The `examples` directory includes some example applications that demonstrate how to use this library:
* `examples/dump.py` is a detailed usage example that demonstrates the asynchronous API to update prices using a websocket subscription or account polling.
* `examples/read_one_price_feed.py` shows how to read the price of a single price feed using its account key.

Developer Setup
---------------
Expand Down
18 changes: 18 additions & 0 deletions examples/read_one_price_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import asyncio

from pythclient.pythaccounts import PythPriceAccount
from pythclient.solana import SolanaClient, SolanaPublicKey, SOLANA_DEVNET_HTTP_ENDPOINT, SOLANA_DEVNET_WS_ENDPOINT

async def get_price():
# devnet DOGE/USD price account key (available on pyth.network website)
account_key = SolanaPublicKey("4L6YhY8VvUgmqG5MvJkUJATtzB2rFqdrJwQCmFLv4Jzy")
solana_client = SolanaClient(endpoint=SOLANA_DEVNET_HTTP_ENDPOINT, ws_endpoint=SOLANA_DEVNET_WS_ENDPOINT)
price: PythPriceAccount = PythPriceAccount(account_key, solana_client)

await price.update()
# Sample output: "DOGE/USD is 0.141455 ± 7.4e-05"
print("DOGE/USD is", price.aggregate_price, "±", price.aggregate_price_confidence_interval)

asyncio.run(get_price())