🚀 A robust, real-time price oracle system for fetching cryptocurrency and stock prices from multiple data sources.
- Multi-Source Price Fetching: CoinGecko, Binance, Alpha Vantage, Finnhub, Yahoo Finance
- Real-time Updates: Configurable update intervals
- Fallback System: Automatic fallback to alternative APIs when primary sources fail
- Comprehensive Data: Prices, 24h changes, volume, market cap
- Error Handling: Robust retry mechanisms and error recovery
- CLI Interface: Easy-to-use command line interface
- Configurable: JSON-based configuration system
- Bitcoin (BTC)
- Ethereum (ETH)
- Binance Coin (BNB)
- Cardano (ADA)
- Solana (SOL)
- Polkadot (DOT)
- Chainlink (LINK)
- Litecoin (LTC)
- Avalanche (AVAX)
- Polygon (MATIC)
- Apple (AAPL)
- Google (GOOGL)
- Microsoft (MSFT)
- Amazon (AMZN)
- Tesla (TSLA)
- Meta (META)
- NVIDIA (NVDA)
- Netflix (NFLX)
- AMD (AMD)
- Intel (INTC)
- Clone the repository:
git clone <repository-url>
cd kanari-oracle- Build the project:
cargo build --release- Run the oracle:
cargo run -- --helpStart the continuous price monitoring service:
# Start with default settings (30-second intervals)
cargo run -- start
# Start with custom interval (60 seconds)
cargo run -- start --interval 60
# Start with custom config file
cargo run -- start --config my-config.jsonFetch current price for a specific asset:
# Get Bitcoin price
cargo run -- price BTC --asset-type crypto
# Get Apple stock price
cargo run -- price AAPL --asset-type stockView all supported assets:
# List all assets
cargo run -- list
# List only cryptocurrencies
cargo run -- list --asset-type crypto
# List only stocks
cargo run -- list --asset-type stockOn first run, a config.json file will be created with default settings. You can edit this file to add API keys and customize behavior:
{
"crypto": {
"coingecko_api_key": null,
"binance_api_key": null,
"binance_secret_key": null,
"default_vs_currency": "usd",
"symbols": [
"bitcoin",
"ethereum",
"binancecoin",
"cardano",
"solana"
]
},
"stocks": {
"alpha_vantage_api_key": null,
"finnhub_api_key": null,
"symbols": [
"AAPL",
"GOOGL",
"MSFT",
"AMZN",
"TSLA"
]
},
"general": {
"request_timeout": 30,
"max_retries": 3,
"retry_delay": 1000,
"enable_logging": true
}
}While the oracle works without API keys using free endpoints, adding API keys provides:
- Higher rate limits
- More reliable service
- Additional data points
- CoinGecko: Get API Key
- Alpha Vantage: Get Free API Key
- Finnhub: Get Free API Key
- Binance: Get API Key
=== Current Prices (Last updated: 2025-10-01 10:30:45 UTC) ===
--- Cryptocurrencies ---
Symbol Price ($) 24h Change Change % Source
----------------------------------------------------------------------
BTC 43250.50 1250.30 2.98% coingecko
ETH 3420.75 -45.20 -1.30% coingecko
BNB 425.80 8.95 2.15% coingecko
ADA 0.45 0.02 4.65% coingecko
SOL 95.30 -2.10 -2.15% coingecko
--- Stocks ---
Symbol Price ($) Change Change % Source
----------------------------------------------------------------------
AAPL 175.25 2.35 1.36% yahoo_finance
GOOGL 142.80 -1.20 -0.83% yahoo_finance
MSFT 420.15 5.80 1.40% yahoo_finance
AMZN 145.90 -0.95 -0.65% yahoo_finance
TSLA 245.60 8.25 3.48% yahoo_finance
The oracle system consists of several key components:
-
Oracle Engine (
src/oracle.rs)- Central coordination system
- Price feed management
- Cache management
-
Price Fetchers (
src/fetchers/)crypto.rs: CoinGecko, Binance integrationstock.rs: Alpha Vantage, Finnhub, Yahoo Finance integration
-
Data Models (
src/models.rs)- Price data structures
- API response models
-
Configuration (
src/config.rs)- JSON-based configuration
- API key management
-
Error Handling (
src/errors.rs)- Comprehensive error types
- Retry mechanisms
- Configuration Loading: Load settings and API keys
- Fetcher Initialization: Initialize price fetchers for each source
- Price Fetching: Retrieve prices from multiple APIs
- Data Processing: Parse and normalize price data
- Cache Update: Update internal price cache
- Output: Display formatted price information
The oracle includes robust error handling:
- Network Failures: Automatic retries with exponential backoff
- API Failures: Fallback to alternative data sources
- Rate Limiting: Respect API rate limits
- Data Validation: Validate price data before processing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and informational purposes only. Price data is provided by third-party APIs and may not be suitable for trading or investment decisions. Always verify prices through official sources before making financial decisions.
For issues, questions, or contributions, please open an issue on the GitHub repository.