Download OpenAPI specification:Download
Welcome to the Backpack Exchange API. This API is for programmatic trade execution. All of the endpoints require requests to be signed with an ED25519 keypair for authentication.
The API is hosted at https://api.backpack.exchange/
and the WS API is hosted at wss://ws.backpack.exchange/
.
Signed requests are required for any API calls that mutate state. Additionally, some read only requests can be performed by signing or via session authentication.
Signed requests require the following additional headers:
X-Timestamp
- Unix time in milliseconds that the request was sent.X-Window
- Time window in milliseconds that the request is valid for, default is 5000
and maximum is 60000
.X-API-Key
- Base64 encoded verifying key of the ED25519 keypair.X-Signature
- Base64 encoded signature generated according to the instructions below.To generate a signature perform the following:
The key/values of the request body or query parameters should be ordered alphabetically and then turned into query string format.
Append the header values for the timestamp and receive window to the above generated string in the format ×tamp=<timestamp>&window=<window>
. If no X-Window
header is passed the default value of 5000
still needs to be added to the signing string.
Each request also has an instruction type, valid instructions are:
accountQuery
balanceQuery
borrowHistoryQueryAll
depositAddressQuery
depositQueryAll
fillHistoryQueryAll
interestHistoryQueryAll
orderCancel
orderCancelAll
orderExecute
orderHistoryQueryAll
orderQuery
orderQueryAll
withdraw
withdrawalQueryAll
The correct instruction type should be prefixed to the signing string. The instruction types for each request are documented alongside the request.
For example, an API request to cancel an order with the following body:
{
"orderId": 28
"symbol": "BTC_USDT",
}
Would require the following to be signed:
instruction=orderCancel&orderId=28&symbol=BTC_USDT×tamp=1614550000000&window=5000
If the API endpoint requires query parameters instead of a request body, the same procedure should be used on the query parameters. If the API endpoint does not have a request body or query parameters, only the timestamp and receive window need to be signed.
This message should be signed using the private key of the ED25519 keypair that corresponds to the public key in the X-API-Key
header. The signature should then be base64 encoded and submitted in the X-Signature
header.
orderId
filter to order history endpoint.from
and to
timestamp to order fills endpoint.t
was added to the private order update stream. It is the trade_id
of the fill that generated the order update.X-Window
header of 60000
.wss://ws.backpack.exchange
. Please see the documentation. The previous API remains on the same endpoint and will be deprecated after a migration period. The new API changes the following:wss://ws.backpack.exchange
instead of wss://ws.backpack.exchange/stream
.params
field.signature
field.accountQuery
to subscribe
.microseconds
instead of milliseconds
.bookTicker
, depth
, and order
streams.depthEvent
to depth
.<symbol>@<type>
to <type>.<symbol>
or kline.<interval>.<symbol>
for K-lines.identifier
field on deposits with transaction_hash
and provider_id
.
This aims to provide clearer representation of the field, particularly for fiat deposits.pending
values from the WithdrawalStatus
and DepositStatus
spec enum.[- {
- "symbol": "BTC",
- "tokens": [
- {
- "blockchain": "Solana",
- "contractAddress": "string",
- "depositEnabled": true,
- "minimumDeposit": "string",
- "withdrawEnabled": true,
- "minimumWithdrawal": "string",
- "maximumWithdrawal": "string",
- "withdrawalFee": "string"
}
]
}
]
[- {
- "symbol": "string",
- "imfBase": "string",
- "imfFactor": "string",
- "mmfBase": "string",
- "mmfFactor": "string",
- "positiveBase": "string",
- "positiveCurvePenalty": "string",
- "weight": "string"
}
]
[- {
- "symbol": "string",
- "baseSymbol": "BTC",
- "quoteSymbol": "BTC",
- "filters": {
- "price": {
- "minPrice": "string",
- "maxPrice": "string",
- "tickSize": "string",
- "maxMultiplier": "string",
- "minMultiplier": "string",
- "maxImpactMultiplier": "string",
- "minImpactMultiplier": "string",
- "meanMarkPriceBand": {
- "maxMultiplier": "string",
- "minMultiplier": "string"
}, - "meanPremiumBand": {
- "tolerancePct": "string"
}
}, - "quantity": {
- "minQuantity": "string",
- "maxQuantity": "string",
- "stepSize": "string"
}, - "leverage": {
- "minLeverage": 0,
- "maxLeverage": 0,
- "stepSize": 0
}
}, - "fundingInterval": 0
}
]
Retrieves a market supported by the exchange.
symbol required | string |
{- "symbol": "string",
- "baseSymbol": "BTC",
- "quoteSymbol": "BTC",
- "filters": {
- "price": {
- "minPrice": "string",
- "maxPrice": "string",
- "tickSize": "string",
- "maxMultiplier": "string",
- "minMultiplier": "string",
- "maxImpactMultiplier": "string",
- "minImpactMultiplier": "string",
- "meanMarkPriceBand": {
- "maxMultiplier": "string",
- "minMultiplier": "string"
}, - "meanPremiumBand": {
- "tolerancePct": "string"
}
}, - "quantity": {
- "minQuantity": "string",
- "maxQuantity": "string",
- "stepSize": "string"
}, - "leverage": {
- "minLeverage": 0,
- "maxLeverage": 0,
- "stepSize": 0
}
}, - "fundingInterval": 0
}
Retrieves summarised statistics for the last 24 hours for the given market symbol.
symbol required | string |
{- "symbol": "string",
- "firstPrice": "string",
- "lastPrice": "string",
- "priceChange": "string",
- "priceChangePercent": "string",
- "high": "string",
- "low": "string",
- "volume": "string",
- "quoteVolume": "string",
- "trades": "string"
}
Retrieves summarised statistics for the last 24 hours for all market symbols.
[- {
- "symbol": "string",
- "firstPrice": "string",
- "lastPrice": "string",
- "priceChange": "string",
- "priceChangePercent": "string",
- "high": "string",
- "low": "string",
- "volume": "string",
- "quoteVolume": "string",
- "trades": "string"
}
]
Retrieves the order book depth for a given market symbol.
symbol required | string |
{- "asks": [
- [
- "21.9",
- "500.123"
], - [
- "22.1",
- "2321.11"
]
], - "bids": [
- [
- "20.12",
- "255.123"
], - [
- "20.5",
- "499.555"
]
], - "lastUpdateId": "1684026955123"
}
Get K-Lines for the given market symbol, optionally providing a
startTime
and endTime
. If no startTime
is provided, the interval
duration will be used. If no endTime
is provided, the current time
will be used.
symbol required | string |
interval required | string (KlineInterval) Enum: "1m" "3m" "5m" "15m" "30m" "1h" "2h" "4h" "6h" "8h" "12h" "1d" "3d" "1w" "1month" |
startTime required | integer <int64> UTC timestamp in seconds. |
endTime | integer <int64> UTC timestamp in seconds. Set to the current time if not provided. |
[- {
- "start": "string",
- "end": "string",
- "open": "string",
- "high": "string",
- "low": "string",
- "close": "string",
- "volume": "string",
- "quoteVolume": "string",
- "trades": "string"
}
]
Retrieves mark price, index price and funding rate for the given market symbol.
symbol required | string |
{- "fundingRate": "string",
- "indexPrice": "string",
- "markPrice": "string",
- "nextFundingTimestamp": 0,
- "symbol": "string"
}
Retrieve the most recent trades for a symbol. This is public data and is not specific to any account.
The maximum available recent trades is 1000
. If you need more than
1000
trades use the historical trades endpoint.
symbol required | string Market symbol to query fills for. |
limit | integer <uint16> Limit the number of fills returned. Default |
[- {
- "id": 0,
- "price": "string",
- "quantity": "string",
- "quoteQuantity": "string",
- "timestamp": 0,
- "isBuyerMaker": true
}
]
Retrieves all historical trades for the given symbol. This is public trade data and is not specific to any account.
symbol required | string |
limit | integer <int64> Limit the number of trades returned. Default |
offset | integer <int64> Offset. Default |
[- {
- "id": 0,
- "price": "string",
- "quantity": "string",
- "quoteQuantity": "string",
- "timestamp": 0,
- "isBuyerMaker": true
}
]
Instruction: accountQuery
X-API-KEY required | string API key |
X-SIGNATURE required | string Signature of the request |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
{- "borrowLimit": "string",
- "futuresMakerFee": "string",
- "futuresTakerFee": "string",
- "leverageLimit": "string",
- "limitOrders": 0,
- "liquidating": true,
- "positionLimit": "string",
- "spotMakerFee": "string",
- "spotTakerFee": "string",
- "triggerOrders": 0,
- "continuousPnlRealization": true,
- "reconciliationAutoBorrow": true
}
Update account settings.
Instruction: accountUpdate
X-API-KEY required | string API key |
X-SIGNATURE required | string Signature of the request |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
leverageLimit | string <decimal> Determines the maximum leverage allowed for the main account or subaccount. |
continuousPnlRealization | boolean Determines if the account should have continuous PnL realization. |
reconciliationAutoBorrow | boolean If true, then tries to borrow during collateral reconciliation. Collateral reconciliation is a process in which the system reconciles the negative account debt or positive account equity. |
{- "leverageLimit": "string",
- "continuousPnlRealization": true,
- "reconciliationAutoBorrow": true
}
{- "code": "FORBIDDEN",
- "message": "string"
}
Retrieves account balances and the state of the balances (locked or available).
Locked assets are those that are currently in an open order.
Instruction: balanceQuery
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
{- "property1": {
- "available": "string",
- "locked": "string",
- "staked": "string"
}, - "property2": {
- "available": "string",
- "locked": "string",
- "staked": "string"
}
}
Retrieves collateral information for an account.
Instruction: collateralQuery
subaccountId | integer <uint16> |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
{- "assetsValue": "string",
- "borrowLiability": "string",
- "collateral": [
- {
- "symbol": "string",
- "assetMarkPrice": "string",
- "totalQuantity": "string",
- "balanceNotional": "string",
- "collateralWeight": "string",
- "collateralValue": "string",
- "openOrderQuantity": "string",
- "lendQuantity": "string",
- "availableQuantity": "string"
}
], - "imf": "string",
- "unsettledEquity": "string",
- "liabilitiesValue": "string",
- "marginFraction": "string",
- "mmf": "string",
- "netEquity": "string",
- "netEquityAvailable": "string",
- "netEquityLocked": "string",
- "netExposureFutures": "string",
- "pnlUnrealized": "string",
- "subaccountId": 0,
- "userId": 0
}
Retrieves deposit history.
Instruction: depositQueryAll
from | integer <int64> Filter to minimum time (milliseconds). |
to | integer <int64> Filter to maximum time (milliseconds). |
limit | integer <int64> Maximum number to return. Default |
offset | integer <int64> Offset. Default |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "id": 0,
- "toAddress": "string",
- "fromAddress": "string",
- "confirmationBlockNumber": 0,
- "source": "administrator",
- "status": "cancelled",
- "transactionHash": "string",
- "symbol": "BTC",
- "quantity": "string",
- "createdAt": "string"
}
]
Retrieves the user specific deposit address if the user were to deposit on the specified blockchain.
Instruction: depositAddressQuery
blockchain required | string (Blockchain) Enum: "Solana" "Ethereum" "Polygon" "Bitcoin" Blockchain symbol to get a deposit address for. |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
{- "address": "string"
}
Retrieves withdrawal history.
Instruction: withdrawalQueryAll
from | integer <int64> Filter to minimum time (milliseconds). |
to | integer <int64> Filter to maximum time (milliseconds). |
limit | integer <int64> Maximum number to return. Default |
offset | integer <int64> Offset. Default |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "id": 0,
- "blockchain": "Solana",
- "clientId": "string",
- "identifier": "string",
- "quantity": "string",
- "fee": "string",
- "symbol": "BTC",
- "status": "confirmed",
- "subaccountId": 0,
- "toAddress": "string",
- "transactionHash": "string",
- "createdAt": "string",
- "isInternal": true
}
]
Requests a withdrawal from the exchange.
The twoFactorToken
field is required if the withdrawal address is not
an address that is configured in the address book to not require
2FA. These addresses can be configured here.
Instruction: withdraw
X-API-KEY required | string API key |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
X-SIGNATURE required | string Signature of the request |
address required | string Address to withdraw to. |
blockchain required | string Enum: "Solana" "Ethereum" "Polygon" "Bitcoin" Blockchain to withdraw on. |
clientId | string Custom client id. |
quantity required | string <decimal> Quantity to withdraw. |
symbol required | string Enum: "BTC" "ETH" "SOL" "USDC" "USDT" "PYTH" "JTO" "BONK" "HNT" "MOBILE" "WIF" "JUP" "RENDER" "WEN" "W" "TNSR" "PRCL" "SHARK" "KMNO" "MEW" "BOME" "RAY" "HONEY" "SHFL" "BODEN" "IO" "DRIFT" "PEPE" "SHIB" "LINK" "UNI" "ONDO" "FTM" "MATIC" "STRK" "BLUR" "WLD" "GALA" "NYAN" "HLG" "MON" "ZKJ" "MANEKI" "HABIBI" "UNA" "ZRO" "ZEX" "AAVE" "LDO" "MOTHER" "CLOUD" "MAX" "POL" "TRUMPWIN" "HARRISWIN" "MOODENG" "DBR" Symbol of the asset to withdraw. |
twoFactorToken | string Issued two factor token. |
{- "address": "string",
- "blockchain": "Solana",
- "clientId": "string",
- "quantity": "string",
- "symbol": "BTC",
- "twoFactorToken": "string"
}
{- "id": 0,
- "blockchain": "Solana",
- "clientId": "string",
- "identifier": "string",
- "quantity": "string",
- "fee": "string",
- "symbol": "BTC",
- "status": "confirmed",
- "subaccountId": 0,
- "toAddress": "string",
- "transactionHash": "string",
- "createdAt": "string",
- "isInternal": true
}
History of borrow and lend operations for the account.
Instruction: borrowHistoryQueryAll
symbol | string Filter to the given symbol. |
limit | integer <uint64> Maximum number to return. Default |
offset | integer <uint64> Offset for pagination. Default |
type | string (BorrowLendSide) Enum: "Borrow" "Lend" Filter to return movements for either borrows or lends. |
direction | string (BorrowLendDirection) Enum: "Increase" "Decrease" Filter to return movements associated to creations or repayments/redemptions. |
source | string (BorrowLendSource) Enum: "Manual" "SpotMargin" "Reconciliation" "Liquidation" "LiquidationAdl" "LiquidationBackstop" Filter to return movements of a particular source. |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "direction": "Increase",
- "eventType": "Borrow",
- "quantity": "string",
- "source": "Manual",
- "symbol": "string",
- "timestamp": "string"
}
]
History of the interest payments for borrows and lends for the account.
Instruction: interestHistoryQueryAll
symbol | string Market symbol to query. If not set, all markets are returned. |
limit | integer <uint64> Maximum number to return. Default |
offset | integer <uint64> Offset for pagination. Default |
source | string (InterestPaymentSource) Enum: "UnrealizedPnl" "BorrowLend" Filter to return interest payments of a particular source. Borrow interest payments through two mechanisms: borrow lend positions; interest paid on unrealized pnl. |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "timestamp": "string",
- "paymentType": "EntryFee",
- "quantity": "string",
- "interestRate": "string",
- "interval": 0,
- "symbol": "BTC"
}
]
Retrieves historical fills, with optional filtering for a specific order or symbol.
Instruction: fillHistoryQueryAll
orderId | string Filter to the given order. |
from | integer <int64> Filter to minimum time (milliseconds). |
to | integer <int64> Filter to maximum time (milliseconds). |
symbol | string Filter to the given symbol. |
limit | integer <int64> Maximum number to return. Default |
offset | integer <int64> Offset. Default |
fillType | string (FillType) Enum: "user" "liquidation" "collateralConversion" "adl" "allLiquidation" Filter to return fills for different fill types |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "timestamp": "string",
- "tradeId": 0,
- "orderId": "string",
- "symbol": "string",
- "side": "Bid",
- "price": "string",
- "quantity": "string",
- "fee": "string",
- "feeSymbol": "string",
- "isMaker": true,
- "systemOrderType": "string"
}
]
Retrieves the order history for the user. This includes orders that have
been filled and are no longer on the book. It may include orders
that are on the book, but the /orders
endpoint contains more up to
date data.
Instruction: orderHistoryQueryAll
orderId | string Filter to the given order. |
symbol | string Filter to the given symbol. |
limit | integer <int64> Maximum number to return. Default |
offset | integer <int64> Offset. Default |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "id": "string",
- "orderType": "Market",
- "symbol": "string",
- "side": "Bid",
- "price": "string",
- "triggerPrice": "string",
- "quantity": "string",
- "quoteQuantity": "string",
- "executedQuantity": "string",
- "executedQuoteQuantity": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "postOnly": true,
- "status": "Cancelled"
}
]
History of PNL realization for an account.
Instruction: pnlHistoryQueryAll
subaccountId | integer <uint16> Filter for a subaccount. |
symbol | string Market symbol to query. If not set, all markets are returned. |
limit | integer <uint64> Maximum number to return. Default |
offset | integer <uint64> Offset for pagination. Default |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "symbol": "string",
- "pnlRealized": "string",
- "timestamp": "string"
}
]
History of settlement operations for the account.
Instruction: settlementHistoryQueryAll
limit | integer <uint64> Maximum number to return. Default |
offset | integer <uint64> Offset for pagination. Default |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "quantity": "string",
- "source": "TradingFees",
- "timestamp": "string"
}
]
Retrieves an open order from the order book. This only returns the order if it is resting on the order book (i.e. has not been completely filled, expired, or cancelled).
One of orderId
or clientId
must be specified. If both are specified
then the request will be rejected.
Instruction: orderQuery
clientId | integer <uint32> Client ID of the order. |
orderId | string ID of the order. |
symbol required | string Market symbol for the order. |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
{- "orderType": "Market",
- "id": "string",
- "clientId": 0,
- "symbol": "string",
- "side": "Bid",
- "quantity": "string",
- "executedQuantity": "string",
- "quoteQuantity": "string",
- "executedQuoteQuantity": "string",
- "triggerPrice": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "status": "Cancelled",
- "createdAt": 0
}
Submits an order to the matching engine for execution.
Instruction: orderExecute
X-API-KEY required | string API key |
X-SIGNATURE required | string Signature of the request |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
clientId | integer <uint32> Custom order id. |
orderType required | string Enum: "Market" "Limit" Order type, market or limit. |
postOnly | boolean Whether the order is post only or not |
price | string <decimal> The order price if this is a limit order |
quantity | string <decimal> The order quantity. Market orders must specify either a |
quoteQuantity | string <decimal> The maximum amount of the quote asset to spend (Ask) or receive (Bid)
for market orders. This is used for reverse market orders. The
order book will execute a |
selfTradePrevention | string Enum: "RejectTaker" "RejectMaker" "RejectBoth" "Allow" Action to take in the event the user crosses themselves in the order book. |
side required | string Enum: "Bid" "Ask" The order side. It will be matched against the resting orders on the other side of the order book. |
symbol required | string The market for the order. |
timeInForce | string Enum: "GTC" "IOC" "FOK" How long the order is good for. |
triggerPrice | string <decimal> Trigger price if this is a conditional order. |
reduceOnly | boolean Default: null If true then the order can only reduce the positon. Futures only. |
autoBorrow | boolean Default: null If true then the order can borrow. Spot margin only. |
{- "clientId": 0,
- "orderType": "Market",
- "postOnly": true,
- "price": "string",
- "quantity": "string",
- "quoteQuantity": "string",
- "selfTradePrevention": "RejectTaker",
- "side": "Bid",
- "symbol": "string",
- "timeInForce": "GTC",
- "triggerPrice": "string",
- "reduceOnly": null,
- "autoBorrow": null
}
{- "orderType": "Market",
- "id": "string",
- "clientId": 0,
- "symbol": "string",
- "side": "Bid",
- "quantity": "string",
- "executedQuantity": "string",
- "quoteQuantity": "string",
- "executedQuoteQuantity": "string",
- "triggerPrice": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "status": "Cancelled",
- "createdAt": 0
}
Cancels an open order from the order book.
One of orderId
or clientId
must be specified. If both are specified
then the request will be rejected.
Instruction: orderCancel
X-API-KEY required | string API key |
X-SIGNATURE required | string Signature of the request |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
clientId | integer <uint32> Client ID of the order. |
orderId | string ID of the order. |
symbol required | string Market the order exists on. |
{- "clientId": 0,
- "orderId": "string",
- "symbol": "string"
}
{- "orderType": "Market",
- "id": "string",
- "clientId": 0,
- "symbol": "string",
- "side": "Bid",
- "quantity": "string",
- "executedQuantity": "string",
- "quoteQuantity": "string",
- "executedQuoteQuantity": "string",
- "triggerPrice": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "status": "Cancelled",
- "createdAt": 0
}
Retrieves all open orders. If a symbol is provided, only open orders for that market will be returned, otherwise all open orders are returned.
Instruction: orderQueryAll
symbol | string The symbol of the market for the orders. |
X-API-KEY | string API key |
X-SIGNATURE | string Signature of the request |
X-TIMESTAMP | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
[- {
- "orderType": "Market",
- "id": "string",
- "clientId": 0,
- "symbol": "string",
- "side": "Bid",
- "quantity": "string",
- "executedQuantity": "string",
- "quoteQuantity": "string",
- "executedQuoteQuantity": "string",
- "triggerPrice": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "status": "Cancelled",
- "createdAt": 0
}
]
Cancels all open orders on the specified market.
Instruction: orderCancelAll
X-API-KEY required | string API key |
X-SIGNATURE required | string Signature of the request |
X-TIMESTAMP required | integer <int64> Timestamp of the request in milliseconds |
X-WINDOW | integer <uint64> Time the request is valid for in milliseconds (default |
symbol required | string Market to cancel orders for. |
{- "symbol": "string"
}
[- {
- "orderType": "Market",
- "id": "string",
- "clientId": 0,
- "symbol": "string",
- "side": "Bid",
- "quantity": "string",
- "executedQuantity": "string",
- "quoteQuantity": "string",
- "executedQuoteQuantity": "string",
- "triggerPrice": "string",
- "timeInForce": "GTC",
- "selfTradePrevention": "RejectTaker",
- "status": "Cancelled",
- "createdAt": 0
}
]
To use the websocket API, connect to
wss://ws.backpack.exchange
.
To subscribe to a stream with the name stream
send a text frame
over the websocket connection with the following JSON payload:
{
"method": "SUBSCRIBE",
"params": ["stream"]
}
Similarly, to unsubscribe from a stream with the name stream
:
{
"method": "UNSUBSCRIBE",
"params": ["stream"]
}
You can subscribe or unsubscribe from multiple streams if you include more than one in the params field.
All data from streams is wrapped in a JSON object of the following form:
{
"stream": "<stream>",
"data": "<payload>"
}
The following command can be used to test subscribing to a stream:
(sleep 1; \
echo '{"method":"SUBSCRIBE","params":["depth.SOL_USDC"]}';\
cat) |\
wscat -c wss://ws.backpack.exchange
The payloads for each stream time are outlined below.
Timestamps are in microseconds (except for the K-line start and end times). The event timestamp is the time the event was emitted from the websocket server, and the engine timestamp is the time the event was generated by the matching engine.
If a message aggregates more than one event (for example, a depth message), the engine timestamp will be the timestamp of the last matching engine event.
To keep the connection alive, a Ping
frame will be sent from the
server every 60s, and a Pong
is expected to be received from the
client. If a Pong
is not received within 120s, a Close
frame will be
sent and the connection will be closed.
If the server is shutting down, a Close
frame will be sent and then a
grace period of 30s will be given before the connection is closed. The
client should reconnect after receiving the Close
frame. The client
will be reconnected to a server that is not shutting down.
Subscribing to a private stream requires a valid signature generated from an ED25519 keypair. For stream subscriptions, the signature should be of the form:
instruction=subscribe×tamp=1614550000000&window=5000
Where the timestamp and window are in milliseconds.
Private streams are prefixed with account.
and require signature data
to be submitted in the subscribe parameters. The verifying key and
signature should be base64 encoded.
{
"method": "SUBSCRIBE",
"params": ["stream"],
"signature": ["<verifying key>", "<signature>", "<timestamp>", "<window>"]
}
On any mutation to an order the order will be pushed to the order update stream. The event type of the order update will be one of the following:
orderAccepted
orderCancelled
orderExpired
orderFill
Stream name format for all markets: account.orderUpdate
Stream name format for single market: account.orderUpdate.<symbol>
{
"e": "orderAccepted", // Event type
"E": 1694687692980000, // Event time in microseconds
"s": "SOL_USD", // Symbol
"c": 123, // Client order ID
"S": "Bid", // Side
"o": "LIMIT", // Order type
"f": "GTC", // Time in force
"q": "32123", // Quantity
"Q": "32123", // Quantity in quote
"p": "20", // Price
"P": "21", // Trigger price
"X": "Filled", // Order state
"i": "1111343026172067" // Order ID
"t": 567, // Trade ID
"l": "1.23", // Fill quantity
"z": "321", // Executed quantity
"Z": "123", // Executed quantity in quote
"L": "20", // Fill price
"m": true, // Whether the order was maker
"n": "23", // Fee
"N": "USD", // Fee symbol
"V": "RejectTaker", // Self trade prevention
"T": 1694687692989999 // Engine timestamp in microseconds
}
Some fields are conditional on the order settings or event type:
c
- Only present if the order has a client order ID.q
- Only present if the order has a quantity set.Q
- Only present if the order is reverse market order.p
- Only present if the order is a limit order.P
- Only present if the order is a trigger order.t
- Only present if the event is a orderFill
event.l
- Only present if the event is a orderFill
event.L
- Only present if the event is a orderFill
event.m
- Only present if the event is a orderFill
event.n
- Only present if the event is a orderFill
event.N
- Only present if the event is a orderFill
event.Stream name format: bookTicker.<symbol>
{
"e": "bookTicker", // Event type
"E": 1694687965941000, // Event time in microseconds
"s": "SOL_USDC", // Symbol
"a": "18.70", // Inside ask price
"A": "1.000", // Inside ask quantity
"b": "18.67", // Inside bid price
"B": "2.000", // Inside bid quantity
"u": "111063070525358080", // Update ID of event
"T": 1694687965940999 // Engine timestamp in microseconds
}
Contains incremental depth updates. Each depth update has the absolute value of the depths at the given levels, and only changes when the depth has changed.
To obtain an initial snapshot of the depth, the client should query the REST API.
The depth stream will push updates as quickly as possible, but under
load it may aggregate more than one update into a single event. In
this case the U
and u
fields will not be the same. The U
field
is the first update ID in the event, and the u
field is the final
update ID in the event.
There is an alternative depth stream that aggregates updates into a single message over a 200ms period instead of pushing updates in realtime. This is useful for reducing network traffic.
Updates are sequential, so U
will always be u + 1
from the previous
message. If this is not the case, the client should assume that the
depth has been invalidated and requery the REST API.
Stream name format: depth.<symbol>
(realtime)
Stream name format: depth.200ms.<symbol>
(aggregated)
{
"e": "depth", // Event type
"E": 1694687965941000, // Event time in microseconds
"s": "SOL_USDC", // Symbol
"a": [ // Asks
[
"18.70",
"0.000"
]
],
"b": [ // Bids
[
"18.67",
"0.832"
],
[
"18.68",
"0.000"
]
],
"U": 94978271, // First update ID in event
"u": 94978271, // Last update ID in event
"T": 1694687965940999 // Engine timestamp in microseconds
}
Stream name format: kline.<interval>.<symbol>
{
"e": "kline", // Event type
"E": 1694687692980000, // Event time in microseconds
"s": "SOL_USD", // Symbol
"t": 123400000, // K-Line start time in seconds
"T": 123460000, // K-Line close time in seconds
"o": "18.75", // Open price
"c": "19.25", // Close price
"h": "19.80", // High price
"l": "18.50", // Low price
"v": "32123", // Base asset volume
"n": 93828, // Number of trades
"X": false // Is this k-line closed?
}
Stream name format: markPrice.<symbol>
{
"e": "markPrice", // Event type
"E": 1694687965941000, // Event time in microseconds
"s": "SOL_USDC", // Symbol
"p": "18.70", // Mark price
"f": "1.70", // Estimated funding rate
"i": "19.70", // Index price
"n": 1694687965941000, // Next funding timestamp in microseconds
}
The ticker stream pushes 24hr rolling statistics for a single symbol.
Stream name format: ticker.<symbol>
{
"e": "ticker", // Event type
"E": 1694687692980000, // Event time in microseconds
"s": "SOL_USD", // Symbol
"o": "18.75", // First price
"c": "19.24", // Last price
"h": "19.80", // High price
"l": "18.50", // Low price
"v": "32123", // Base asset volume
"V": "928190", // Quote asset volume
"n": 93828 // Number of trades
}
Contains public trade data for a single symbol. The trade ID is a sequential number specific to the symbol.
Stream name format: trade.<symbol>
{
"e": "trade", // Event type
"E": 1694688638091000, // Event time in microseconds
"s": "SOL_USDC", // Symbol
"p": "18.68", // Price
"q": "0.122", // Quantity
"b": "111063114377265150", // Buyer order ID
"a": "111063114585735170", // Seller order ID
"t": 12345, // Trade ID
"T": 1694688638089000, // Engine timestamp in microseconds
"m": true // Is the buyer the maker?
}