/** * @name tools/backpack/backpack-client * @description Typed REST client for Backpack Exchange public and signed * endpoints. Signing follows the documented Ed25519 header scheme * (X-Timestamp, X-Window, X-API-Key, X-Signature) with the instruction * prefixed to an alphabetically ordered parameter string. Response * compaction mirrors the Phoenix gateway caps so large upstream payloads * never reach an MCP client verbatim. * * @module tools/backpack/backpack-client */ /** Default Backpack REST base URL. */ export declare const BACKPACK_API_BASE_URL = "https://api.backpack.exchange"; /** Default signing window in milliseconds (docs default). */ export declare const DEFAULT_WINDOW_MS = 5000; /** * @name BackpackApiError * @description Typed error surfaced for every non-2xx upstream response. * `code` carries the upstream JSON error code or a derived label for * plain-text bodies (e.g. 'not_found'). */ export declare class BackpackApiError extends Error { readonly status: number; readonly code: string; constructor(status: number, code: string, message: string); } /** Upstream Backpack REST API paths (verified against docs.backpack.exchange). */ export declare const BACKPACK_PATHS: { readonly markets: "/api/v1/markets"; readonly market: "/api/v1/market"; readonly ticker: "/api/v1/ticker"; readonly tickers: "/api/v1/tickers"; readonly depth: "/api/v1/depth"; readonly trades: "/api/v1/trades"; readonly klines: "/api/v1/klines"; readonly markPrices: "/api/v1/markPrices"; readonly fundingRates: "/api/v1/fundingRates"; readonly openInterest: "/api/v1/openInterest"; readonly collateral: "/api/v1/collateral"; readonly assets: "/api/v1/assets"; readonly securities: "/api/v1/securities"; readonly marketSessions: "/api/v1/market-sessions"; readonly marketHolidays: "/api/v1/market-holidays"; readonly borrowLendMarkets: "/api/v1/borrowLend/markets"; readonly status: "/api/v1/status"; readonly ping: "/api/v1/ping"; readonly time: "/api/v1/time"; readonly capital: "/api/v1/capital"; readonly order: "/api/v1/order"; readonly orders: "/api/v1/orders"; readonly fills: "/api/v1/fills"; readonly depositAddress: "/api/v1/deposit/address"; readonly maxOrderQuantity: "/api/v1/maxOrderQuantity"; readonly withdrawal: "/api/v1/capital/withdrawal"; }; /** Valid Backpack kline intervals (upstream is lowercase except monthly 1M). */ export declare const KLINE_INTERVALS: readonly ["1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "12h", "1d", "3d", "1w", "1M"]; export type BackpackKlineInterval = (typeof KLINE_INTERVALS)[number]; /** Ed25519 credentials used for signed Backpack endpoints. */ export interface BackpackApiKey { /** Base64-encoded 32-byte Ed25519 verifying key (sent as X-API-Key). */ readonly publicKeyB64: string; /** Base64-encoded 32-byte Ed25519 private seed (never leaves this process). */ readonly secretSeedB64: string; } /** Options accepted by the BackpackApiClient constructor. */ export interface BackpackClientOptions { readonly baseUrl?: string; readonly apiKey?: BackpackApiKey; readonly windowMs?: number; } /** Order body accepted by POST /api/v1/order (orderExecute). */ export interface BackpackOrderBody { readonly symbol: string; readonly side: 'Bid' | 'Ask'; readonly orderType: 'Market' | 'Limit' | 'IOC' | 'PostOnly' | 'ReduceOnly' | 'Scale' | 'TWAP'; readonly quantity: string; readonly price?: string; readonly clientOrderId?: string; readonly postOnly?: boolean; readonly timeInForce?: string; readonly stopPrice?: string; readonly triggerCondition?: string; readonly selfTradePreventionMode?: string; } /** Withdrawal body accepted by the withdraw instruction. */ export interface BackpackWithdrawalBody { readonly address: string; readonly blockchain: string; readonly symbol: string; readonly quantity: string; readonly clientOrderId?: string; } /** * @name buildSigningString * @description Builds the exact Backpack signing string: * `instruction=&×tamp=&window=`. * Null/undefined params are omitted. With no params the string contains * only instruction, timestamp, and window. */ export declare function buildSigningString(instruction: string, params: Record, timestampMs: number, windowMs: number): string; /** * @name deriveBackpackPublicKeyB64 * @description Derives the base64 32-byte verifying key from a base64 seed. */ export declare function deriveBackpackPublicKeyB64(secretSeedB64: string): string; /** * @name signBackpackMessage * @description Signs a UTF-8 message with an Ed25519 seed (base64) and * returns the base64 64-byte signature. */ export declare function signBackpackMessage(message: string, secretSeedB64: string): string; /** * @name compactBackpackResponse * @description Caps upstream payloads: arrays at 50 entries (with a remainder * marker), strings at 500 chars (real Solana transactions preserved), * BigInts as strings, and a 30k total character cap with _truncated * markers. Never mutates the input. */ export declare function compactBackpackResponse(payload: unknown): unknown; /** * @name BackpackApiClient * @description REST client for Backpack Exchange. Public methods require no * credentials; signed methods require an API key and throw a structured * `backpack_credentials_required` error (no network call) otherwise. */ export declare class BackpackApiClient { private readonly baseUrl; private readonly apiKey?; private readonly windowMs; constructor(options?: BackpackClientOptions); /** True when signed endpoints can be used. */ hasCredentials(): boolean; private buildUrl; private requestText; private getJson; private requireCredentials; private signedRequest; /** Lists all markets, optionally filtered by SPOT|PERP. */ getMarkets(marketType?: 'SPOT' | 'PERP'): Promise; /** Returns a single market by symbol via the markets endpoint + client filter. */ getMarket(symbol: string): Promise; /** Returns the 24h ticker for one symbol. */ getTicker(symbol: string): Promise; /** Returns 24h tickers for every market. */ getTickers(): Promise; /** Returns the order book (bids/asks) for a symbol. */ getDepth(symbol: string, limit?: number): Promise; /** Returns recent public trades. */ getTrades(symbol: string, limit?: number): Promise; /** Returns klines; startTime/endTime are epoch SECONDS upstream. */ getKlines(symbol: string, interval: BackpackKlineInterval, startTimeSec: number, endTimeSec: number): Promise; /** Returns mark/index price and funding rate for a perp symbol. */ getMarkPrices(symbol: string): Promise; /** Returns funding interval rates for a perp symbol. */ getFundingRates(symbol: string): Promise; /** Returns open interest in contracts. */ getOpenInterest(symbol: string): Promise; /** Returns collateral haircut/IMF/MMF parameters per asset. */ getCollateral(): Promise; /** Returns all assets with deposit/withdraw metadata (large — compact before display). */ getAssets(): Promise; /** Returns tokenized securities with sessions and quantity limits. */ getSecurities(): Promise; /** Returns stock market session hours. */ getMarketSessions(): Promise; /** Returns market holidays and shortened sessions. */ getMarketHolidays(): Promise; /** Returns borrow/lend markets with rates and utilization. */ getBorrowLendMarkets(): Promise; /** Returns system status. */ getStatus(): Promise; /** Pings the API (plain 'pong'). */ getPing(): Promise; /** Returns the server time in epoch milliseconds. */ getServerTime(): Promise; /** Account balances (instruction balanceQuery). */ getBalances(): Promise; /** Open orders (instruction orderQueryAll). */ getOpenOrders(symbol?: string): Promise; /** Order history (instruction orderHistoryQueryAll). */ getOrderHistory(symbol?: string, limit?: number): Promise; /** Fill history (instruction fillHistoryQueryAll). */ getFills(symbol?: string, limit?: number): Promise; /** Maximum order quantity preflight (instruction maxOrderQuantity). */ getMaxOrderQuantity(symbol: string, side: 'Bid' | 'Ask', price?: string, leverage?: string): Promise; /** Executes an order (instruction orderExecute). */ executeOrder(body: BackpackOrderBody): Promise; /** Executes a batch of orders (instruction orderExecute per order). */ executeOrderBatch(orders: readonly BackpackOrderBody[]): Promise; /** Cancels one order (instruction orderCancel). */ cancelOrder(symbol: string, orderId: string): Promise; /** Cancels all open orders, optionally per symbol (orderCancelAll). */ cancelAllOrders(symbol?: string): Promise; /** Deposit address for an asset (instruction depositAddressQuery). */ getDepositAddress(asset: string): Promise; /** Requests a withdrawal (instruction withdraw). Requires explicit confirmation upstream. */ requestWithdrawal(body: BackpackWithdrawalBody): Promise; } //# sourceMappingURL=backpack-client.d.ts.map