Backpack
Backpack (Spot): Spot trading on Backpack Exchange (mainly USDC-quoted), including the tokenized stocks listed on the exchange; the account reads the spot balances. Access uses an API key created on Backpack (an ED25519 key pair). Perpetual contracts are served by the Futures_Backpack exchange object.
Futures_Backpack (Futures): Backpack Exchange USDC perpetual contracts, including perpetuals on tokenized stocks. The account is a unified collateral account with cross margin and one-way positions only. Access uses an API key created on Backpack (an ED25519 key pair). Spot is served by the Backpack exchange object.
Names and Configuration
exchange.GetName() | Type | Aliases |
|---|---|---|
Backpack | Spot | Backpack Exchange |
Futures_Backpack | Futures | — |
| Field | Required | Description |
| - | - | - |
| Access Key | Yes | The public key of the Backpack API key (base64). |
| Secret Key | Yes | The ED25519 private key matching the public key (32-byte seed, base64 or hex). |
Trading Pairs and Contract Codes
Backpack (Spot)
Pair examples: SOL_USDC, BTC_USDC, SPCX-US_USDC
Trading pairs are written as SOL_USDC. Tokenized stocks whose exchange name contains . (such as SPCX.US) are written with - in pairs and asset names: SPCX-US_USDC.
Futures_Backpack (Futures)
Pair examples: BTC_USDC, ETH_USDC
Backpack perpetuals are quoted in USDC; trading pairs are written as ETH_USDC (USDC is assumed when the quote currency is omitted). Tokenized stocks whose exchange name contains . (such as MU.US) are written with - in pairs and asset names: MU-US_USDC.
| Contract code | Description |
|---|---|
swap | Perpetual contract (exchange code ETH_USDC_PERP); the full symbol looks like ETH_USDC.swap. |
Backpack lists perpetual contracts only; any other contract code is rejected.
Exchange-specific IO Commands
| Command | Arguments | Description | Returns |
|---|---|---|---|
selfTradePreventionMode | string | Self-trade prevention for subsequent orders and conditional orders; one of Allow, RejectTaker, RejectMaker, RejectBoth (case-sensitive). | The value set on success; an error for any other value. |
api | method, path[, params[, raw]] | Call a Backpack endpoint directly; requests are signed by default. (more below the table) | The raw exchange response; an error is raised when the response carries a message or error error message. |
The rest of the longer descriptions in the table:
api: Private endpoints need the exchange's instruction nameinstruction(such asbalanceQueryororderQueryAll) inparams(or in therawobject); it is used for signing only and is not sent with the request. A non-emptyrawreplacesparamsentirely: forGETit may be a JSON object ora=1&b=2, for other methods it must be a JSON object.pathmay also be a full URL. Withfalseas the 4th argument the request is not signed, which only works for publicGETendpoints.
For the common commands base and currency see exchange.IO.
Common Usage
Call private endpoints (signing needs instruction) and public endpoints
javascript
function main() {
// Private endpoint: instruction is the exchange-defined instruction name; it is only
// signed, not sent with the request
var balances = exchange.IO("api", "GET", "/api/v1/capital", {instruction: "balanceQuery"})
Log(balances) // {"USDC": {"available": "...", "locked": "...", "staked": "..."}, ...}
var orders = exchange.IO("api", "GET", "/api/v1/orders", {instruction: "orderQueryAll"})
Log(orders) // array of open orders
// Public endpoint: false as the last argument skips signing (GET only)
var t = exchange.IO("api", "GET", "/api/v1/ticker", "symbol=SOL_USDC", false)
Log(t.lastPrice)
}
Set self-trade prevention (values are case-sensitive)
javascript
function main() {
// Later orders and conditional orders carry it; an unknown value fails and returns null
Log(exchange.IO("selfTradePreventionMode", "RejectTaker")) // RejectTaker
}
Function Support
Not supported (the call fails with an error and returns null): exchange.ModifyOrder, exchange.ModifyConditionOrder.
Served through a fallback:
exchange.GetRecords: Native periods are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M; other periods are synthesized by the docker.
Margin, Account and Simulation
Futures_Backpack (Futures)
Margin mode: Backpack uses a unified collateral account with cross margin only and no cross/isolated switch. exchange.SetMarginLevel() changes the account-level leverage limit (leverageLimit), which applies to all contracts; the call also turns on the account's auto-borrow settings (autoBorrowSettlements, autoLend, autoRepayBorrows).
Position mode: One-way (net) positions only, no hedge mode. Closing orders (closebuy, closesell) are placed as reduce-only (reduceOnly). MarginLevel in exchange.GetPositions() is the reciprocal of the initial margin fraction.
Account: exchange.GetAccount() reads the collateral account: Balance is the available net equity, FrozenBalance the locked net equity and Equity the net equity; each collateral currency is listed in exchange.GetAssets().
Notes
All exchange objects
- The client order ID
clientIdmust be an integer from 0 to 4294967295; any other value fails and the order is not sent. - The batch data of
exchange.GetTickers()has no order book, soBuyandSellare the last trade price; useexchange.GetTicker()for the real best bid and ask. - Conditional orders support take-profit and stop-loss only, not OCO. Backpack trigger orders do not distinguish take-profit from stop-loss, so the type is inferred on query from the trigger price relative to the current last price. With an order price of 0 the order executes at market once triggered. Modifying a conditional order is not supported; cancel and recreate it instead.
exchange.GetHistoryOrders()andexchange.GetHistoryConditionOrders()query one symbol at a time and do not supportsince(the exchange's order history endpoint has no time range); asincegreater than 0 or an empty symbol is rejected.
Backpack (Spot)
- The amount of a market buy order is the quote currency to spend (placed with Backpack's
quoteQuantity); a market sell order uses the base currency amount. Such market buy orders have no order price in queries, soPriceis 0, andAmountis the filled base currency amount. exchange.GetOrders()andexchange.GetHistoryOrders()return regular orders only, without conditional orders; querying a conditional order ID withexchange.GetOrder()fails, so useexchange.GetConditionOrder()for conditional orders, andexchange.GetConditionOrders()/exchange.GetHistoryConditionOrders()for open and historical conditional orders.exchange.GetAccount()andexchange.GetAssets()count available and frozen amounts only, not staked amounts.
Futures_Backpack (Futures)
- The amount of a market order is the contract quantity (in the base currency) for both buys and sells.
exchange.GetOrders()andexchange.GetHistoryOrders()return regular orders only, without conditional orders; querying a conditional order ID withexchange.GetOrder()fails, so useexchange.GetConditionOrder()for conditional orders.- Funding intervals differ between contracts;
exchange.GetFundings()reports each one from the exchange's contract information.