Price Feeds
Get real-time price data from Pyth Network.
Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/price-feeds/sol-usd | Get current SOL/USD price |
All price feed endpoints require JWT authentication.
Get SOL/USD Price
Get the current SOL/USD price from Pyth Network.
GET /api/v1/price-feeds/sol-usdResponse
Success (200)
{
"price": "102.45678900",
"lastUpdated": "2025-01-20T10:30:00.000Z",
"isStale": false,
"source": "pyth"
}Response Fields
| Field | Type | Description |
|---|---|---|
price | string | Current SOL price in USD (8 decimal precision) |
lastUpdated | ISO 8601 | When the price was last updated |
isStale | boolean | Whether the price is considered stale |
source | string | Price data source (pyth) |
Staleness
A price is considered stale if:
- No update received for more than 60 seconds
- The Pyth SSE connection is down
⚠️
If isStale is true, the price may not reflect current market conditions. Trading decisions should account for this.
Example
curl -X GET "https://your-instance.com/api/v1/price-feeds/sol-usd" \
-H "Authorization: Bearer <access_token>"JavaScript Usage
async function getSolPrice() {
const response = await fetch('/api/v1/price-feeds/sol-usd', {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await response.json();
if (data.isStale) {
console.warn('Price data is stale');
}
return parseFloat(data.price);
}
// Convert SOL to USD
const solPrice = await getSolPrice();
const usdValue = solAmount * solPrice;Price Source
Nexgent uses Pyth Network for SOL/USD pricing:
- Connection: Server-Sent Events (SSE) for real-time updates
- Update Frequency: Sub-second price updates
- Reliability: Decentralized oracle network
How It Works
Pyth Network ──SSE──► Price Service ──► In-Memory Cache
│
▼
/api/v1/price-feeds/sol-usd- Backend maintains persistent SSE connection to Pyth
- Prices are cached in-memory for instant access
- API returns cached price with freshness metadata
Related Endpoints
- Data Sources - Check configuration
- Agent Positions - Uses prices for P/L
- Agent Balances - Uses prices for values