Skip to main content

GMTrade Perpetuals API — GMX on Solana Perp Data & Streams

GMTrade is the GMX V2 perpetual exchange on Solana. Traders open and close leveraged positions against liquidity pools, and a keeper executes each order at the oracle price. Bitquery indexes GMTrade into the same Solana perpetual cubes as the Phoenix Perpetuals API, so every query on this page also works as a WebSocket subscription.

Related docs

Reading the data model​

Select GMTrade in any cube with the exchange filter:

<Cube>: { Exchange: { Name: { is: "gmtrade" } } }

In the data GMTrade appears as Exchange.Name: "gmtrade", Exchange.Family: "GMX" and Exchange.Program: "Gmso1uvJnLbawvw7yezdfCDcPydwW2s2iqG3w6MDucLo".

CubeWhat GMTrade rows hold
PerpetualFillsOne row per executed trade: market, side, execution price, size, USD notional, collateral, position before and after, liquidation flag.
PerpetualPositionsThe position change from the same trade, with RealizedPnl when a position is reduced or closed.
PerpetualOrdersOrder lifecycle: OrderCreated, OrderUpdated, OrderExecuted and OrderCancelled rows.

How GMTrade differs from Phoenix Perpetuals in these cubes:

  • Markets are keyed by Asset.MarketAddress. Asset.Id is 0 on every GMTrade row. The same symbol can trade in more than one market (two BTC/USD markets backed by different liquidity pools, for example), so group and filter by MarketAddress when you need one market, and by Symbol when you want all markets of an asset.
  • Every fill is against the pool. CounterpartyIsAmm is true and Counterparty and MakerOrderId are empty, because GMX matches orders against liquidity pools, not other traders.
  • Signer is the keeper. Executions are signed by the keeper wallet. Use Trader for the trader's wallet.
  • Size is signed. On fills and positions, a positive Position.Size is a long and a negative one a short. Amount.Size is the signed size change of the trade and Amount.Quote its USD notional.
  • Collateral is a token. Collateral and CollateralCurrency (Symbol, MintAddress) show what the trader posted, for example USDC.
  • Order types in Order.Order.Type include MarketIncrease, MarketDecrease, LimitIncrease, LimitDecrease, StopLossDecrease and Liquidation. Group the order-lifecycle query below by this field to see the current set.
  • Prices and market summaries. GMTrade rows are in PerpetualFills, PerpetualPositions and PerpetualOrders. Take the latest trade price from ExecutionPrice on fills.

GMTrade markets cover crypto majors and memecoins, metals such as gold, silver, platinum and copper, oil and currency pairs such as EUR/USD and USD/JPY, all quoted in USD.

Latest GMTrade trades — PerpetualFills​

The newest executed trades on GMTrade, newest first.

Run this query in the IDE

query GmtradeLatestFills {
Solana {
PerpetualFills(
limit: { count: 20 }
orderBy: { descending: Block_Time }
where: {
Block: { Time: { since_relative: { hours_ago: 1 } } }
Fill: { Exchange: { Name: { is: "gmtrade" } } }
}
) {
Block { Time }
Transaction { Signature }
Fill {
Asset { Symbol MarketAddress }
Side
ExecutionPrice
Amount { Size Quote }
Trader
Collateral
CollateralCurrency { Symbol }
Position { SizeBefore Size EntryPrice }
Liquidation
}
}
}
}

Side is bid for a buy (opening or adding to a long, or reducing a short) and ask for a sell. Compare Position.SizeBefore with Position.Size to tell an open from a close.

Stream GMTrade trades in real time​

The same fields as a WebSocket subscription over wss://streaming.bitquery.io/graphql.

Run this query in the IDE

subscription GmtradeFillsStream {
Solana {
PerpetualFills(
where: { Fill: { Exchange: { Name: { is: "gmtrade" } } } }
) {
Block { Time }
Transaction { Signature }
Fill {
Asset { Symbol MarketAddress }
Side
ExecutionPrice
Amount { Size Quote }
Trader
Liquidation
}
}
}
}

GMTrade volume by market​

USD trade volume, buy and sell volume and trade count per GMTrade market over the last 24 hours, largest first.

Run this query in the IDE

query GmtradeVolumeByMarket {
Solana {
PerpetualFills(
limit: { count: 25 }
orderBy: { descendingByField: "volume_usd" }
where: {
Block: { Time: { since_relative: { hours_ago: 24 } } }
Fill: { Exchange: { Name: { is: "gmtrade" } } }
}
) {
Fill {
Asset { Symbol MarketAddress }
}
trades: count
volume_usd: sum(of: Fill_Amount_Quote)
buy_volume_usd: sum(of: Fill_Amount_Quote, if: { Fill: { Side: { is: "bid" } } })
sell_volume_usd: sum(of: Fill_Amount_Quote, if: { Fill: { Side: { is: "ask" } } })
}
}
}

Drop MarketAddress from the selection to add up all markets of one symbol.

Trades of one GMTrade wallet​

All GMTrade trades of one trader wallet in the last 7 days. Replace the address with the wallet you want; raise days_ago to look further back. No rows means the wallet did not trade on GMTrade in the window.

Run this query in the IDE

query GmtradeWalletFills {
Solana {
PerpetualFills(
limit: { count: 50 }
orderBy: { descending: Block_Time }
where: {
Block: { Time: { since_relative: { days_ago: 7 } } }
Fill: {
Exchange: { Name: { is: "gmtrade" } }
Trader: { is: "B5eBNGi4znKXCpCtMvRQUEQmuiCAYxebawJ2APHARiAp" }
}
}
) {
Block { Time }
Transaction { Signature }
Fill {
Asset { Symbol MarketAddress }
Side
ExecutionPrice
Amount { Size Quote }
Collateral
CollateralCurrency { Symbol }
Position { SizeBefore Size EntryPrice }
Liquidation
}
}
}
}

GMTrade trader PnL leaderboard — PerpetualPositions​

Realized PnL per trader on GMTrade over the last 7 days, from closed and reduced positions. RealizedPnl is in USD and is set on the row where a position is reduced or closed.

Run this query in the IDE

query GmtradePnlLeaderboard {
Solana {
PerpetualPositions(
limit: { count: 25 }
orderBy: { descendingByField: "realized_pnl" }
where: {
Block: { Time: { since_relative: { days_ago: 7 } } }
Position: { Exchange: { Name: { is: "gmtrade" } } }
}
) {
Position { Trader }
realized_pnl: sum(of: Position_RealizedPnl)
position_updates: count
closes: count(if: { Position: { Closed: true } })
liquidations: count(if: { Position: { Liquidation: true } })
}
}
}

Change descendingByField to ascendingByField for the largest losses.

GMTrade liquidations​

Positions liquidated on GMTrade in the last 7 days, newest first. A liquidated position has Liquidation: true and Closed: true; the matching fill in PerpetualFills carries the same Liquidation flag, and the keeper's order has Order.Order.Type: "Liquidation".

Run this query in the IDE

query GmtradeLiquidations {
Solana {
PerpetualPositions(
limit: { count: 25 }
orderBy: { descending: Block_Time }
where: {
Block: { Time: { since_relative: { days_ago: 7 } } }
Position: {
Exchange: { Name: { is: "gmtrade" } }
Liquidation: true
}
}
) {
Block { Time }
Transaction { Signature }
Position {
Asset { Symbol MarketAddress }
Trader
RealizedPnl
Closed
Position { SizeBefore Size EntryPrice }
CollateralCurrency { Symbol }
}
}
}
}

Use it as a subscription to build a live liquidation feed.

GMTrade order lifecycle — PerpetualOrders​

A GMTrade order is created by the trader (OrderCreated), executed by the keeper (OrderExecuted) and then closed (OrderCancelled with CancelReason such as executed or cancelled). Limit and stop-loss orders can also get OrderUpdated rows. This query counts the last 24 hours of order events by event type and order type.

Run this query in the IDE

query GmtradeOrderLifecycle {
Solana {
PerpetualOrders(
limit: { count: 50 }
orderBy: { descendingByField: "events" }
where: {
Block: { Time: { since_relative: { hours_ago: 24 } } }
Order: { Exchange: { Name: { is: "gmtrade" } } }
}
) {
Order {
Type
Order { Type CancelReason }
}
events: count
}
}
}

To follow one order, filter on Order: { Order: { Id: { is: "<order id>" } } } and select Block { Time }, Type, Side, Price { Trigger } (set on limit and stop-loss orders) and Amount { Quote } (the order size in USD).

Frequently Asked Questions

What is GMTrade?

GMTrade is the GMX V2 perpetual exchange on Solana. Traders open leveraged long and short positions against liquidity pools, and a keeper executes orders at the oracle price. In Bitquery data it appears with Exchange Name gmtrade and Exchange Family GMX.

Which Bitquery cubes hold GMTrade data?

PerpetualFills for executed trades, PerpetualPositions for position changes, realized PnL and liquidations, and PerpetualOrders for the order lifecycle. Filter any of them with Exchange Name is gmtrade.

How do I select one GMTrade market?

Filter on Asset.MarketAddress. Asset.Id is 0 on every GMTrade row, and one symbol such as BTC/USD can trade in more than one market, so MarketAddress is the key for a single market and Symbol selects all markets of an asset.

Why is the Signer not the trader on GMTrade fills?

A keeper wallet signs the transaction that executes each order. The trader wallet is in the Trader field, which is the one to filter on for a wallet's trades.

Can I stream GMTrade trades over WebSocket?

Yes. Replace query with subscription, remove limit and orderBy, and connect to wss://streaming.bitquery.io/graphql. The fills stream on this page is a ready example.

How do I get GMTrade liquidations?

Filter PerpetualPositions on Liquidation true with the gmtrade exchange filter. The liquidated trade also appears in PerpetualFills with Liquidation true, and the keeper order in PerpetualOrders has order type Liquidation.

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.