npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bpx-api-client

v0.2.1

Published

Backpack Exchange API Client Library for TypeScript

Readme

BPX API Client

A TypeScript client library for the Backpack Exchange API, written by 0xprobe.

All requests, responses, and parameters are strongly typed. Type definitions follow the official Backpack Exchange API specification, and the client modules mirror the categories used in the official documentation.

Installation

npm install bpx-api-client

Quick Start

1. Initialize the client

import { BpxApiClient } from 'bpx-api-client';

const client = new BpxApiClient({
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
  debug: false // if true, prints debug information with console.log()
});

2. HTTP API

HTTP APIs are grouped by category and called in the form client.<category>.<endpoint>(params).

// Get market information (public)
const marketsResponse = await client.markets.getMarket('SOL_USDC');
console.log(marketsResponse.data);

// Execute an order (authenticated)
import { Side, OrderType, TimeInForce } from 'bpx-api-client';

const orderResponse = await client.order.executeOrder({
  symbol: 'SOL_USDC',
  side: Side.Bid,
  orderType: OrderType.Limit,
  quantity: '0.07',
  price: '85',
  timeInForce: TimeInForce.GTC
});
console.log(orderResponse.data);

// Get account information (authenticated)
const accountResponse = await client.account.getAccount();
console.log(accountResponse.data);

All request payloads and responses are typed, enabling strict type checking:

import { ApiResponse, Market, OrderExecutePayload, OpenOrder } from 'bpx-api-client';

const response: ApiResponse<Market> = await client.markets.getMarket('SOL_USDC');

const payload: OrderExecutePayload = {
  symbol: 'SOL_USDC',
  side: Side.Bid,
  orderType: OrderType.Limit,
  quantity: '0.07',
  price: '85',
  timeInForce: TimeInForce.GTC
};
const orderResponse: ApiResponse<OpenOrder> = await client.order.executeOrder(payload);

See docs/USAGE.md for the full per-category method reference and examples.

HTTP API Response Format

All HTTP API responses follow the ApiResponse interface:

export interface ApiResponse<T> {
  statusCode: number;                              // HTTP status code
  data: T | Record<string, never>;                 // Success: actual data, Failure: empty object
  error: ApiErrorResponse | Record<string, never>; // Success: empty object, Failure: error details
}

export interface ApiErrorResponse {
  code: string;
  message: string;
}

Success Response Example

{
  statusCode: 200,
  data: {
    baseSymbol: 'SOL',
    createdAt: '2025-01-21T06:34:54.691858',
    filters: { price: [Object], quantity: [Object] },
    fundingInterval: 28800000,
    marketType: 'SPOT',
    orderBookState: 'Open',
    quoteSymbol: 'USDC',
    symbol: 'SOL_USDC'
  },
  error: {}
}

Error Response Example

{
  statusCode: 400,
  data: {},
  error: { code: 'INVALID_CLIENT_REQUEST', message: 'Market not found' }
}

You can use the isSuccess helper as a type guard:

import { isSuccess } from 'bpx-api-client';

const response = await client.markets.getMarket('SOL_USDC');
if (isSuccess(response)) {
  // response.data is narrowed to Market
  console.log(response.data.symbol);
}

WebSocket API

import { SubscriptionType } from 'bpx-api-client';

// Open WebSocket connection
await client.streams.open();

// Add message handler
client.streams.addMessageHandler((message) => {
  console.log(JSON.stringify(message, null, 2));
});

// Subscribe to public streams
client.streams.bookTicker(SubscriptionType.SUBSCRIBE, 'SOL_USDC');

// Provider-derived streams for tokenized stocks (RWA)
client.streams.externalTicker(SubscriptionType.SUBSCRIBE, 'MU.US_USDC');
client.streams.stockPrice(SubscriptionType.SUBSCRIBE, 'AAPL'); // bare ticker

// Subscribe to private streams (signed automatically)
client.streams.orderUpdate(SubscriptionType.SUBSCRIBE, 'BTC_USDC');
client.streams.balanceUpdate(SubscriptionType.SUBSCRIBE);      // account-wide

// Close WebSocket connection
await client.streams.close();

Authentication

All authentication and signing for private endpoints is handled inside BpxApiClient. You only need to provide your apiKey and apiSecret when initializing the client. Signing uses an ED25519 keypair as required by the Backpack API.

API Surface

The client mirrors the categories in the official API documentation.

Public endpoints

| Category | Accessor | Examples | |----------|----------|----------| | Assets | client.assets | getAssets, getCollateral | | Borrow Lend Markets | client.borrowLendMarkets | getBorrowLendMarkets, getBorrowLendMarketsHistory, getApyRates | | Markets | client.markets | getMarkets, getMarket, getTicker, getDepth, getKlines, getPredictionEvents, getMarketSessions, getSecurities, … | | System | client.system | status, ping, getSystemTime, getWallets | | Trades | client.trades | getRecentTrades, getHistoricalTrades |

Authenticated endpoints

| Category | Accessor | Examples | |----------|----------|----------| | Account | client.account | getAccount, updateAccount, getMaxBorrowQuantity, … | | Borrow Lend | client.borrowLend | getBorrowLendPositions, executeBorrowLend, getBorrowLendHistory, getInterestHistory, … | | Capital | client.capital | getBalances, getCollateral, getDeposits, requestWithdrawal, convertDustBalance, getDustConversionHistory, getSettlementHistory, … | | Order | client.order | executeOrder, getOpenOrder, cancelOpenOrder, getOpenOrders, getFillHistory, getOrderHistory, … | | Position | client.position | getOpenPositions, getFundingPayments, getPositionHistory | | RFQ | client.rfq | submitRequestForQuote, acceptQuote, getOpenRfqs, getRfqHistory, getQuoteFillHistory, … | | Strategy | client.strategy | getStrategy, getOpenStrategies, createStrategy, cancelStrategy, getStrategyHistory, … |

WebSocket

client.streams — order/position/RFQ/balance updates, book ticker, depth, k-line, liquidation, mark price, ticker, external ticker, stock price, open interest, trade.

Features

  • TypeScript support — complete type definitions for all requests and responses
  • REST client — public and private endpoints, grouped by official API category
  • WebSocket client — real-time market data and account update streams
  • Authentication — secure ED25519 API key/secret handling
  • Error handling — consistent ApiResponse envelope with structured error details

Documentation

License

MIT