Skip to main content

A basic framework for interacting with Solana's Pyth network

Project description

Pyth Network

A basic Python framework for reading and decoding data regarding the Pyth network oracles.

Install

pip3 install pythpy

Setup

import pythpy
from solana.rpc.api import Client

# use a Solana client to get Pyth oracle data
solana_client = Client(
    endpoint='https://api.mainnet-beta.solana.com',
    commitment='confirmed'
)
# public address for the Pyth SOL oracle
sol_oracle_address = 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'
oracle_account_info = pythpy.call_oracle_account(
    client=solana_client, 
    address=sol_oracle_address
)
# view the info
print(oracle_account_info)

Output:

{
    "magic": 2712847316,
    "version": 2,
    "oracle_type": 3,
    "size": 1872,
    "price_type": 1,
    "exponent": -8,
    "num_component_prices": 17,
    "num_quoters": 15,
    "last_slot": 109163611,
    "valid_slot": 109163610,
    "twap": {
        "value": 188.081046,
        "fraction": {
            "numerator": 4446404127,
            "denominator": 2364089437
        }
    },
    "twac": {
        "value": 0.10387786,
        "fraction": {
            "numerator": 2455765564,
            "denominator": 2364089437
        }
    },
    "drv1": 1e-08,
    "drv2": 3e-08,
    "product_account_key": "ALP8SdU9oARYVLgLR7LrqMNCYBnhtnQz1cj6bwgwQmgj",
    "next_price_account_key": "11111111111111111111111111111111",
    "previous_slot": 109163609,
    "previous_price": 189.912598,
    "previous_confidence": 0.142106,
    "drv3": 0.0,
    "aggregate": {
        "price": 189.914705,
        "confidence": 0.15314,
        "status": 1,
        "corporate_action": 0,
        "publish_slot": 109163611
    },
    "price_components": [
        {
            "price": 189.922,
            "confidence": 0.074,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.9655,
            "confidence": 0.0695,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.9125,
            "confidence": 0.03348694,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.9125,
            "confidence": 0.03348694,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.801,
            "confidence": 0.0075,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.801,
            "confidence": 0.0075,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.90375,
            "confidence": 0.0875,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.90375,
            "confidence": 0.0875,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.8,
            "confidence": 0.22,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.8,
            "confidence": 0.22,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.94324999,
            "confidence": 0.0945,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.94975,
            "confidence": 0.0945,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.9695,
            "confidence": 0.0915,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163592
        },
        {
            "price": 189.8795,
            "confidence": 0.0915,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163604
        },
        {
            "price": 189.945,
            "confidence": 0.224,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.945,
            "confidence": 0.224,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 190.00769337,
            "confidence": 0.09500384,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 190.00769337,
            "confidence": 0.09500384,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.9665,
            "confidence": 0.08199159,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.9665,
            "confidence": 0.08199159,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.9175,
            "confidence": 0.0328868,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.9175,
            "confidence": 0.0328868,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.94345807,
            "confidence": 0.09032811,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.94345807,
            "confidence": 0.09032811,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.94001131,
            "confidence": 0.12145504,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.94001131,
            "confidence": 0.12145504,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.90292767,
            "confidence": 0.08596382,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.90292767,
            "confidence": 0.08596382,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163603
        },
        {
            "price": 189.95925,
            "confidence": 0.32675,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        },
        {
            "price": 189.95925,
            "confidence": 0.32675,
            "status": 1,
            "corporate_action": 0,
            "publish_slot": 109163605
        }
    ]
}

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

pyth-py-0.0.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

pyth_py-0.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file pyth-py-0.0.2.tar.gz.

File metadata

  • Download URL: pyth-py-0.0.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pyth-py-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ee1a02a31916f5dd14702e6320a3daf42afb216c4544c38f343aa1ae50a06493
MD5 7ae5ee0adba49b7b77cb08d7c7163df6
BLAKE2b-256 2c310f199fd8ecbd6ee4a5b7dbb7d26091155de0f4ec8abf25acdd4a3542d087

See more details on using hashes here.

File details

Details for the file pyth_py-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyth_py-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pyth_py-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a7729f5afdb9afe9506b3fcb8f04490d3b4f73d4def3368d37738460f0aa55ee
MD5 f384a89b21b98cc7c7258e87e0fd9b3f
BLAKE2b-256 916d746fa8bf8583a3f7d2225617ee33750bbb903af76cf549e4bfccf885d462

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