Base-Quote OHLCV

SUBSCRIBE_BASE_QUOTE_PRICE

The "SUBSCRIBE_BASE_QUOTE_PRICE" event allows you to receive real-time updates about price changes for any token pairs without needing to input a specific pair address; you can simply pass the two token addresses you want to track. You can subscribe to price updates for these token pairs in the form of OHLCV (Open, High, Low, Close, Volume) data. This subscription is useful for tracking price movements and trends on the Birdeye platform.

Code Example

Check out this Github file for an example:

https://github.com/TheNang2710/bds-public/blob/main/ws-base-quote.js

1. WebSocket URL:

wss://public-api.birdeye.so/socket/solana?x-api-key=YOUR-API-KEY

Header

KeyValue
Originws://public-api.birdeye.so
Sec-WebSocket-Originws://public-api.birdeye.so
Sec-WebSocket-Protocolecho-protocol

2. Subscribe to Base-Quote Price (OHLCV)

To receive real-time updates about price changes for a specific token pair in the form of OHLCV data, use the following subscription message format:

Subscription message

{
  "type": "SUBSCRIBE_BASE_QUOTE_PRICE",
  "data": {
    "baseAddress": "XsDoVfqeBukxuZHWhdvWHBhgEHjGNst4MLodqsJHzoB",
    "quoteAddress": "So11111111111111111111111111111111111111112",
    "chartType": "1m",
    "mode": "both"
  }
}

Subscription fields

FieldTypeRequiredDescription
baseAddressstringYesBase token address.
quoteAddressstringYesQuote token address.
chartTypestringYesOHLCV interval. Example: 1m.
modestringNoControls which OHLCV values are returned. Supported values: raw, scaled, both.

Mode values

Use mode to control whether the WebSocket response includes raw OHLCV values, scaled OHLCV values, or both.

ModeDescription
rawReturns raw OHLCV fields: o, h, l, c, and v.
scaledReturns scaled OHLCV fields: scaledO, scaledH, scaledL, scaledC, and scaledV.
bothReturns both raw and scaled OHLCV fields.

Sample response

{
  "type": "BASE_QUOTE_PRICE_DATA",
  "data": {
    "eventType": "ohlcv",
    "type": "1m",
    "unixTime": 1779175980,
    "vUsd": 0,
    "baseAddress": "XsDoVfqeBukxuZHWhdvWHBhgEHjGNst4MLodqsJHzoB",
    "quoteAddress": "So11111111111111111111111111111111111111112",
    "isScaledBase": true,
    "isScaledQuote": false,
    "multiplierBase": 1,
    "multiplierQuote": null,
    "o": 4.792529252342796,
    "h": 4.795878266968378,
    "l": 4.79082399724625,
    "c": 4.791854954030759,
    "v": 0,
    "scaledO": 4.792529252342796,
    "scaledH": 4.795878266968378,
    "scaledL": 4.79082399724625,
    "scaledC": 4.791854954030759,
    "scaledV": 0
  }
}

Response fields

FieldTypeDescription
eventTypestringEvent type. For OHLCV updates, this is ohlcv.
typestringOHLCV interval. Example: 1m.
unixTimenumberCandle timestamp in Unix time.
vUsdnumberVolume in USD.
baseAddressstringBase token address.
quoteAddressstringQuote token address.
isScaledBasebooleanIndicates whether the base token uses scaled values.
isScaledQuotebooleanIndicates whether the quote token uses scaled values.
multiplierBasenumberMultiplier applied to the base token.
multiplierQuotenumber or nullMultiplier applied to the quote token. Returns null when no quote multiplier is applied.
onumberRaw open price. Returned when mode is raw or both.
hnumberRaw high price. Returned when mode is raw or both.
lnumberRaw low price. Returned when mode is raw or both.
cnumberRaw close price. Returned when mode is raw or both.
vnumberRaw volume. Returned when mode is raw or both.
scaledOnumberScaled open price. Returned when mode is scaled or both.
scaledHnumberScaled high price. Returned when mode is scaled or both.
scaledLnumberScaled low price. Returned when mode is scaled or both.
scaledCnumberScaled close price. Returned when mode is scaled or both.
scaledVnumberScaled volume. Returned when mode is scaled or both.

Implementation Example in JavaScript

Use the above github js code and run

node ws-base-quote.js solana So11111111111111111111111111111111111111112 EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v 1m

Explanation:

  • solana: The blockchain chain to subscribe to (e.g., Solana).
  • So11111111111111111111111111111111111111112: The base token address.
  • EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: The quote token address (e.g., USDC).
  • 1m: The chart type, which is the interval for OHLCV data (e.g., 1 minute).

Note:

  • This example subscribes to real-time price updates for a token pair and logs the Open, High, Low, Close, and Volume data to the console. The subscription is automatically closed after 1 hour.
  • This WebSocket only support 1 base-quote pair for 1 connection. You need to open another connection for new base-quote subscription.