Skip to main content

OpenBook DEX API

Need real-time OpenBook data or anything from the last ~30 days?

For real-time + last ~30 days, use the Trading cube. Trading.Trades gives you clean, MEV-filtered OpenBook swaps with USD price, market cap, and supply on every row across 10 chains in one API. Use this page when you need historical OpenBook data older than ~30 days, raw per-swap detail, or call / event context.

OpenBook markets are covered by the Solana DEX API alongside Raydium, Orca and Jupiter.

note

Trade Side Account field will not be available for aggregate queries in Archive and Combined Datasets

ProductUsing this in production? See the Solana DEX API page for plans, free trial and enterprise delivery options.

OpenBook Trades in Real-Time​

This streams a message for every new trade on the order book, carrying both sides of the fill, the venue that matched it and the block time. Open it in the Bitquery IDE: realtime order-book trades.

subscription {
Solana {
DEXTrades(
where: { Trade: { Dex: { ProtocolFamily: { is: "OpenBook" } } } }
) {
Trade {
Dex {
ProgramAddress
ProtocolFamily
ProtocolName
}
Buy {
Currency {
Name
Symbol
MintAddress
}
Amount
Account {
Address
}
PriceAgainstSellCurrency: Price
}
Sell {
Account {
Address
}
Amount
Currency {
Name
Symbol
MintAddress
}
PriceAgainstBuyCurrency: Price
}
}
Block {
Time
}
}
}
}

Price Average of Pair on OpenBook​

Open the Bitquery IDE: average price over 24 hours to read the average price of a pair on a chosen day.

query PriceAverage {
Solana {
DEXTrades(
limit: { count: 1 }
orderBy: { descending: Block_Time }
where: {
Trade: {
Dex: { ProtocolFamily: { is: "OpenBook" } }
Sell: { Currency: { Symbol: { is: "USDC" } } }
Buy: { Currency: { Symbol: { is: "WSOL" } } }
}
Block: {
Time: {
after: "2024-06-03T00:00:00Z"
before: "2024-06-04T00:00:00Z"
}
}
}
) {
tokenPrice: average(of: Trade_Buy_Price)
}
}
}

Get All Instructions of OpenBook v2​

The Solana instructions API returns every instruction the v2 program executed. Open it in the Bitquery IDE: OpenBook v2 instructions.

query MyQuery {
Solana {
Instructions(
where: {
Instruction: {
Program: {
Address: { is: "opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb" }
}
}
Transaction: { Result: { Success: true } }
}
) {
Instruction {
Program {
Method
}
}
count
}
}
}

Listen to placeOrder, placeTakeOrder Instructions of OpenBook v2​

This subscription follows transactions that place orders on v2, through the Solana instructions API. There is also a video walkthrough on YouTube. Open it in the Bitquery IDE: placeOrder and placeTakeOrder instructions.

subscription {
Solana {
Instructions(
where: {
Instruction: {
Program: {
Address: { is: "opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb" }
Method: { in: ["placeOrder", "placeTakeOrder"] }
}
}
Transaction: { Result: { Success: true } }
}
) {
Transaction {
Signature
}
Instruction {
Accounts {
Address
IsWritable
Token {
Mint
Owner
ProgramId
}
}
Program {
AccountNames
Address
Method
Name
Parsed
Arguments {
Name
Type
Value {
... on Solana_ABI_Json_Value_Arg {
json
}
... on Solana_ABI_Float_Value_Arg {
float
}
... on Solana_ABI_Boolean_Value_Arg {
bool
}
... on Solana_ABI_Bytes_Value_Arg {
hex
}
... on Solana_ABI_BigInt_Value_Arg {
bigInteger
}
... on Solana_ABI_Address_Value_Arg {
address
}
... on Solana_ABI_String_Value_Arg {
string
}
... on Solana_ABI_Integer_Value_Arg {
integer
}
}
}
}
}
}
}
}

Listen to consumeEvents Instructions of OpenBook v2​

This subscription follows consumeEvents transactions on v2. That instruction settles trade events and cancellations, updating the book so every filled order is accounted for. The same video walkthrough covers it. Open it in the Bitquery IDE: consumeEvents instruction.

subscription {
Solana {
Instructions(
where: {
Instruction: {
Program: {
Address: { is: "opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb" }
Method: { is: "consumeEvents" }
}
}
Transaction: { Result: { Success: true } }
}
) {
Transaction {
Signature
}
Instruction {
Accounts {
Address
IsWritable
Token {
Mint
Owner
ProgramId
}
}
Program {
AccountNames
Address
Method
Name
Parsed
Arguments {
Name
Type
Value {
... on Solana_ABI_Json_Value_Arg {
json
}
... on Solana_ABI_Float_Value_Arg {
float
}
... on Solana_ABI_Boolean_Value_Arg {
bool
}
... on Solana_ABI_Bytes_Value_Arg {
hex
}
... on Solana_ABI_BigInt_Value_Arg {
bigInteger
}
... on Solana_ABI_Address_Value_Arg {
address
}
... on Solana_ABI_String_Value_Arg {
string
}
... on Solana_ABI_Integer_Value_Arg {
integer
}
}
}
}
}
}
}
}

Latest Price of a Token on OpenBook​

This returns the most recent trade for a token on the order book, with the price in the quote token and in USD.

Open it in the Bitquery IDE: latest token price.

{
Solana {
DEXTradeByTokens(
limit: {count: 1}
orderBy: {descending: Block_Time}
where: {Trade: {Dex: {ProtocolFamily: {is: "OpenBook"}}, Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}}}
) {
Block {
Time
}
Trade {
Currency {
MintAddress
}
Side {
Currency {
MintAddress
}
}
Price
PriceInUSD
}
}
}
}

OpenBook OHLC API​

If you want to get OHLC data for any specific currency pair on OpenBook, you can use this api. Only use this API as query and not subscription websocket as Aggregates and Time Intervals don't work well with subscriptions.

{
Solana {
DEXTradeByTokens(
orderBy: {descendingByField: "Block_Timefield"}
where: {Trade: {Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}, Dex: {ProtocolFamily: {is: "OpenBook"}}, PriceAsymmetry: {lt: 0.1}}}
limit: {count: 10}
) {
Block {
Timefield: Time(interval: {in: minutes, count: 1})
}
volume: sum(of: Trade_Amount)
Trade {
high: Price(maximum: Trade_Price)
low: Price(minimum: Trade_Price)
open: Price(minimum: Block_Slot)
close: Price(maximum: Block_Slot)
}
count
}
}
}

Get the Top Traders of a specific Token on OpenBook DEX​

This ranks the wallets trading one token on the venue, USDC in the example. Run it as a plain request rather than a WebSocket subscription, because aggregates are recomputed per message on a subscription and the totals come back wrong. Open it in the Bitquery IDE: top traders on OpenBook

query TopTraders($token: String) {
Solana {
DEXTradeByTokens(
orderBy: {descendingByField: "volumeUsd"}
limit: {count: 100}
where: {Trade: {Currency: {MintAddress: {is: $token}}, Dex: {ProtocolFamily: {is: "OpenBook"}}}, Transaction: {Result: {Success: true}}}
) {
Trade {
Account {
Owner
}
Side {
Account {
Address
}
Type
}
}
bought: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: buy}}}})
sold: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: sell}}}})
volume: sum(of: Trade_Amount)
volumeUsd: sum(of: Trade_Side_AmountInUSD)
}
}
}
{
"token": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
}

Get trading volume, buy volume, sell volume of a token​

This reads the Trading cube rather than the chain-level DEXTradeByTokens. Every Trading row carries a vetted USD price and the cube covers roughly the last 30 days in full, while the Solana archive and combined datasets return about a fifth fewer trades than realtime over the same window, so volume totals taken from them read low.

Side is the trader's own side. Markets here are quoted in USDC, so the example sums every USDC-quoted market on the venue, matching what the previous chain-level version measured. Filter Token as well to narrow it to one pair. Open it in the Bitquery IDE: trade volume.

{
Trading {
Trades(
where: {
Pair: {
Market: { ProtocolFamily: { is: "OpenBook" }, Network: { is: "Solana" } }
QuoteToken: {
Address: { is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" }
}
}
Block: { Time: { since_relative: { days_ago: 7 } } }
}
) {
volumeUsd: sum(of: AmountsInUsd_Base)
buy_volume: sum(of: AmountsInUsd_Base, if: { Side: { is: "Buy" } })
sell_volume: sum(of: AmountsInUsd_Base, if: { Side: { is: "Sell" } })
buys: count(if: { Side: { is: "Buy" } })
sells: count(if: { Side: { is: "Sell" } })
}
}
}

Volatility of a Pair on OpenBook​

Volatility is an important factor in trading world as it determines the fluctuation in price that implies the possibility of profit and risk of loss. Lesser volatility denotes that the pair is stable.

Open the Bitquery IDE: token volatility to read volatility for a token over the last 24 hours.

query Volatility {
Solana {
DEXTrades(
where: {
Trade: {
Dex: { ProtocolFamily: { is: "OpenBook" } }
Sell: {
Currency: {
MintAddress: {
is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
}
}
}
}
Block: { Time: { after: "2025-03-18T00:00:00Z" } }
}
) {
volatility: standard_deviation(of: Trade_Buy_Price)
}
}
}

Video Tutorial | How to Listen to OpenBook v2 Instruction Calls in Realtime - Bitquery API​

Build with Bitquery

Ready to run this in production?

Get an API key and run these queries in minutes, or talk to us about plans and enterprise delivery.