supra-oracle-sdk
v1.0.4
Published
SDK for accessing Supra Pull Oracle data
Readme
Supra Oracle SDK
A lightweight JavaScript SDK to fetch and decode price feed data from Supra's Pull Oracle REST API.
Features
- Fetches oracle proof data from Supra Pull Oracle
- Decodes the proof bytes into readable price feeds
- Supports easy customization of REST endpoint and chain type
Installation
npm install supra-oracle-sdkUsage
const SupraOracleClient = require('supra-oracle-sdk');
(async () => {
const client = new SupraOracleClient({
restAddress: 'https://rpc-testnet-dora-2.supra.com', // optional, defaults to this
chainType: 'evm' // optional, defaults to 'evm'
});
const pairIndexes = [0, 21, 49, 61];
const oracleData = await client.getOracleData(pairIndexes);
console.log('Oracle Feed Data:', oracleData);
})();API new SupraOracleClient(options) options.restAddress — REST API base URL (default: https://rpc-testnet-dora-2.supra.com)
options.chainType — Blockchain type (default: 'evm')
getOracleData(pairIndexes) Fetches and decodes oracle data for the specified array of pairIndexes.
pairIndexes — Array of integer indexes for requested price pairs.
Returns a Promise that resolves to an array of decoded price feed objects:
js Copy Edit [ { pairIndex: '0', price: '98544400000000000000000', decimals: '18', timestamp: '1750623025071' }, ... ]
📈 Historical Price Data (OHLC) The SDK provides support for fetching historical price data from the Supra REST API, returning OHLC (Open, High, Low, Close) candles for a specific trading pair.
🛠 Setup To enable historical price support, pass the history config with your API key when initializing the client:
const SupraOracleClient = require('supra-oracle-sdk');
const oracle = new SupraOracleClient({ history: { enabled: true, apiKey: 'YOUR_API_KEY_HERE', // 🔐 Replace with your actual key baseUrl: 'https://prod-kline-rest.supra.com' // Optional override } }); 📤 Fetch Historical Prices
const historical = await oracle.getHistoricalPrices({ tradingPair: 'btc_usdt', // Format: lowercase with underscore startDate: 1718000000000, // UNIX timestamp in milliseconds (UTC) endDate: 1718086400000, // UNIX timestamp in milliseconds (UTC) interval: 3600 // Interval in seconds (e.g. 60, 3600, 86400) });
console.log(historical.data); /* [ { timestamp: 1718000000000, open: 20000.5, high: 20100.0, low: 19950.0, close: 20050.0, volume: 15.2 }, ... ] */ 🔒 Notes You can request data up to 1 month back.
Time format: timestamps must be in Unix milliseconds.
Intervals are in seconds (e.g. 60 for 1 minute, 3600 for 1 hour, 86400 for 24 hours).
Historical Price Data (OHLC)
The SDK supports fetching historical OHLC (Open, High, Low, Close) candle data for a single trading pair, if you enable and configure the history API with your key.
const oracle = new SupraOracleClient({ history: { enabled: true, apiKey: 'YOUR_API_KEY_HERE', // 🔐 Replace with your key baseUrl: 'https://prod-kline-rest.supra.com' // Optional override } });
Fetch historical prices by specifying the trading pair, start and end timestamps (in Unix milliseconds UTC), and the candle interval (in seconds):
const historical = await oracle.getHistoricalPrices({ tradingPair: 'btc_usdt', // Lowercase with underscore format startDate: 1718000000000, // UNIX ms timestamp (UTC) endDate: 1718086400000, // UNIX ms timestamp (UTC) interval: 3600 // Interval in seconds (e.g., 60, 3600, 86400) });
The returned data is an array of candle objects:
[ { timestamp: 1718000000000, open: 20000.5, high: 20100.0, low: 19950.0, close: 20050.0, volume: 15.2 }, // ... ]
