Pyth Benchmark Rust Client
A Rust client for streaming and processing price data from the Pyth Network oracle. This crate provides a robust interface for accessing real-time price data and converting it into OHLC (Open, High, Low, Close) bar data.
🚀 Features
- Historical Data: Automatically fetch historical OHLC price data
- Real-time Price Streaming: Connect to Pyth Network's streaming API for live price updates
- OHLC Bar Generation: Automatically convert price feeds into candlestick bar data
- Daily Bar Aggregation: Aggregate price data into daily time periods
- Subscription Management: Thread-safe subscription system for multiple symbols
- Automatic Reconnection: Resilient connection handling with exponential backoff
- Multiple Data Formats: Support for JSON and Server-Sent Events (SSE)
📦 Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
= { = "1", = ["full"] }
🏃 Quick Start
use ;
use HashMap;
use ;
use mpsc;
async
📊 Real-time Subscriptions
Subscribe to real-time price updates:
use mpsc;
// Create a channel for receiving updates
let = unbounded_channel;
// Subscribe to BTC/USD daily bars
let symbol = new;
datafeed.subscribe_bars.await;
// Listen for updates
spawn;
🏗️ API Overview
Core Types
DataFeed
: Main client for interacting with Pyth NetworkBar
: OHLC price data structureSymbolInfo
: Symbol information (ticker)PeriodParams
: Time period parameters for historical data
Key Methods
on_ready()
: Initialize the data feedget_bars()
: Fetch historical OHLC datasubscribe_bars()
: Subscribe to real-time updatessearch_symbols()
: Search for available symbolsresolve_symbol()
: Get detailed symbol information
Streaming Functions
start_streaming()
: Start the main streaming connectionsubscribe_on_stream()
: Add a symbol subscriptionunsubscribe_from_stream()
: Remove a subscription
🎯 What This Crate is Built For
This repository is specifically designed to read OHLC (Open, High, Low, Close) data from the Pyth Network oracle. Pyth Network is a decentralized oracle that provides real-time market data for various financial instruments, particularly in the cryptocurrency space.
Use Cases
- Trading Applications: Build real-time trading bots and algorithms
- Market Analysis: Analyze price movements and trends
- Data Collection: Store historical price data for research
- Charting Applications: Create price charts and technical indicators
- Portfolio Management: Track asset prices for portfolio valuation
🔧 Configuration
The crate uses these default endpoints:
- Streaming:
https://benchmarks.pyth.network/v1/shims/tradingview/streaming
- API:
https://benchmarks.pyth.network/v1/shims/tradingview
🛠️ Building and Running
Build the library:
Run the example:
Run tests:
📖 Examples
The src/main.rs
file contains a comprehensive example showing:
- Fetching historical data
- Starting real-time streaming
- Subscribing to symbol updates
- Handling bar data updates
- Graceful shutdown
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
📄 License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.