Skip to main content

A library to retrieve Pyth account structures off the Solana blockchain.

Project description

Pyth Client in Python

pytest

A Python library to retrieve data from Pyth account structures off the Solana blockchain.

NOTE: This library requires Python 3.7 or greater due to from __future__ import annotations.

Usage

Install the library:

pip install pythclient

You can then read the current Pyth price using the following:

from pythclient.pythclient import PythClient
from pythclient.pythaccounts import PythPriceAccount
from pythclient.utils import get_key

solana_network="devnet"
async with PythClient(
    first_mapping_account_key=get_key(solana_network, "mapping"),
    program_key=get_key(solana_network, "program") if use_program else None,
) as c:
    await c.refresh_all_prices()
    products = await c.get_products()
    for p in products:
        print(p.attrs)
        prices = await p.get_prices()
        for _, pr in prices.items():
            print(
                pr.price_type,
                pr.aggregate_price_status,
                pr.aggregate_price,
                "p/m",
                pr.aggregate_price_confidence_interval,
            )

This code snippet lists the products on pyth and the price for each product. Sample output is:

{'symbol': 'Crypto.ETH/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'ETH/USD', 'generic_symbol': 'ETHUSD', 'base': 'ETH'}
PythPriceType.PRICE PythPriceStatus.TRADING 4390.286 p/m 2.4331
{'symbol': 'Crypto.SOL/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SOL/USD', 'generic_symbol': 'SOLUSD', 'base': 'SOL'}
PythPriceType.PRICE PythPriceStatus.TRADING 192.27550000000002 p/m 0.0485
{'symbol': 'Crypto.SRM/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SRM/USD', 'generic_symbol': 'SRMUSD', 'base': 'SRM'}
PythPriceType.PRICE PythPriceStatus.UNKNOWN None p/m None
...

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

Using python 3.7 or newer, create, and activate a virtual environment:

python3 -m venv ve
. ve/bin/activate

To install this library in editable mode with test dependencies:

pip install -e '.[testing]'

To run the unit tests:

pytest

If html based test coverage is more your jam:

pytest --cov-report=html

The coverage webpages will be in the htmlcov directory.

Distribution

To build the package for distribution to pypi, first install dependencies:

python3 -m pip install --upgrade twine build

Next, edit setup.py and bump the version field. Then build the package by running:

python3 -m build

This command will produce packages in the dist/ directory. Upload these packages to pypi by running:

python3 -m twine upload --repository pypi dist/*

This command will require you to log in to a pypi account.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythclient-0.1.3.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

pythclient-0.1.3-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file pythclient-0.1.3.tar.gz.

File metadata

  • Download URL: pythclient-0.1.3.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pythclient-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e3e26040bc21460de62437b2155cd16362d995a1b2b31f39b803f7f1c39684e4
MD5 e7b36c3c678433d6f6d455ca0951ccfe
BLAKE2b-256 81d93724df26add819c16c44fef10f6e4bcd5b7c94f93a1b61ffd41bff1168e6

See more details on using hashes here.

File details

Details for the file pythclient-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pythclient-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pythclient-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6dd94d22b6f5731bfc0e56789ac0409d2e4cff3bd7ef57ecdc8da3d2705ed600
MD5 2ce22a8911ada375a75b844adce975f9
BLAKE2b-256 e9465a046fe3210474c5b6154ea32c06b6fe0dc7a0e1fe0f4db7a4a17e88ebcc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page