Skip to content

A comprehensive Python toolkit for fetching real-time and historical price data from PYTH Network oracles

License

Notifications You must be signed in to change notification settings

giraphant/pyth-oracle-toolkit

Repository files navigation

PYTH Oracle Data Toolkit

A comprehensive Python toolkit for fetching real-time and historical price data from PYTH Network oracles.

Python Version License

Features

  • Real-time Price Data - Fetch latest prices with confidence intervals
  • Historical Data - Get price history with customizable time ranges
  • Minute-level Precision - Up to 1440 data points per 24 hours
  • Multiple Time Granularities - Hour, 5-min, or minute intervals
  • 100% Success Rate - Robust error handling and retry logic
  • Easy to Use - Simple command-line interface
  • 📊 Data Export - Save results to JSON for further analysis

Quick Start

# Clone the repository
git clone https://github.com/YOUR_USERNAME/pyth-oracle-toolkit.git
cd pyth-oracle-toolkit

# Install dependencies
pip install -r requirements.txt

# Get real-time price
python get_realtime_price.py

# Get 24-hour lowest price
python get_24h_lowest.py <your_feed_id>

# Get minute-level data
python get_minute_data.py 24

Scripts Overview

Script Description Usage
get_realtime_price.py Fetch latest price data python get_realtime_price.py
get_24h_lowest.py Find 24h lowest price python get_24h_lowest.py [feed_id]
get_historical_price.py Query historical data python get_historical_price.py --days 7
get_minute_data.py Minute-level data (1440 points/24h) python get_minute_data.py 24
fetch_price_feed_info.py Query price feed information python fetch_price_feed_info.py

Example Output

JLP/USD 24小时最低价: $5.1570
发生时间: 2025-10-10 22:28:31

📊 数据点数: 1440/1440 (100.0% 成功率)
🔴 最高价: $5.8222
🟢 最低价: $5.1570
📈 平均价: $5.4889
📊 价格波动: $0.6652 (12.90%)

PYTH Network APIs

1. Hermes API - Real-time Data

Hermes continuously monitors Pyth Network for price updates and serves them via REST API.

Endpoint: https://hermes.pyth.network

2. Benchmarks API - Historical Data

Benchmarks provides historical price data queries for any time point.

Endpoint: https://benchmarks.pyth.network

Price Feed ID vs Solana Address

  • Solana Account Address: Used on Solana blockchain (Base58 format)
    • Example: 2TTGSRSezqFzeLUH8JwRUbtN66XLLaymfYsWRTMjfiMw
  • Price Feed ID: Used in Hermes/Benchmarks API (64-char hex string)
    • Example: 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace

Find your Price Feed ID at: https://www.pyth.network/price-feeds

Common Price Feeds

Asset Price Feed ID
BTC/USD e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
ETH/USD ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
SOL/USD ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
JLP/USD c811abc82b4bad1f9bd711a2773ccaa935b03ecef974236942cec5e0eb845a3a

Documentation

Price Calculation

PYTH returns prices with an exponent field:

price: 383538126869
expo: -8
Actual Price = 383538126869 × 10^(-8) = 3835.38 USD

Requirements

  • Python 3.7+
  • requests
  • python-dateutil
  • base58

API Rate Limits

  • Hermes and Benchmarks APIs are free to use
  • Implement appropriate rate limiting to avoid throttling
  • Use larger time granularities (e.g., 5-min instead of 1-min) for long historical queries

Resources

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This tool is for educational and research purposes. Always verify data accuracy and implement proper error handling for production use.

About

A comprehensive Python toolkit for fetching real-time and historical price data from PYTH Network oracles

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages