OS Trading Engine
API Reference
Endpoints
Price Feeds

Price Feeds

Get real-time price data from Pyth Network.


Endpoints Overview

MethodEndpointDescription
GET/api/v1/price-feeds/sol-usdGet 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-usd

Response

Success (200)

{
  "price": "102.45678900",
  "lastUpdated": "2025-01-20T10:30:00.000Z",
  "isStale": false,
  "source": "pyth"
}

Response Fields

FieldTypeDescription
pricestringCurrent SOL price in USD (8 decimal precision)
lastUpdatedISO 8601When the price was last updated
isStalebooleanWhether the price is considered stale
sourcestringPrice 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
  1. Backend maintains persistent SSE connection to Pyth
  2. Prices are cached in-memory for instant access
  3. API returns cached price with freshness metadata

Related Endpoints