Skip to main content

A simple SDK for backpack exchange

Project description

Backpack Exchange SDK

PyPI - Version Python License

English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español | Português

A complete Python SDK for the Backpack Exchange API. Supports all 70 API endpoints including REST and WebSocket.

Project Docs

Features

  • Authentication Client: Full access to authenticated endpoints (orders, capital, history, RFQ, strategies)
  • Public Client: Access public market data, system status, and trade data
  • WebSocket Client: Real-time streaming for market data and account updates
  • Complete Coverage: All 70 API endpoints implemented
  • Type Hints: Full type annotations for better IDE support
  • Enums: Comprehensive enums for type-safe API calls

Installation

pip install backpack-exchange-sdk

Or install from source:

git clone https://github.com/solomeowl/backpack_exchange_sdk.git
cd backpack_exchange_sdk
pip install .

Quick Start

Public Client

from backpack_exchange_sdk import PublicClient

client = PublicClient()

# Get all markets
markets = client.get_markets()

# Get ticker
ticker = client.get_ticker("SOL_USDC")

# Get order book depth
depth = client.get_depth("SOL_USDC")

Authentication Client

from backpack_exchange_sdk import AuthenticationClient

client = AuthenticationClient("<API_KEY>", "<SECRET_KEY>")

# Get account balances
balances = client.get_balances()

# Place an order
order = client.execute_order(
    orderType="Limit",
    side="Bid",
    symbol="SOL_USDC",
    price="100",
    quantity="1"
)

# Get order history
history = client.get_order_history(symbol="SOL_USDC")

Using Enums

from backpack_exchange_sdk import AuthenticationClient
from backpack_exchange_sdk.enums import OrderType, Side, TimeInForce

client = AuthenticationClient("<API_KEY>", "<SECRET_KEY>")

order = client.execute_order(
    orderType=OrderType.LIMIT.value,
    side=Side.BID.value,
    symbol="SOL_USDC",
    price="100",
    quantity="1",
    timeInForce=TimeInForce.GTC.value
)

API Reference

Public Client Methods

Category Method Description
System get_status() Get system status
send_ping() Ping the server
get_system_time() Get server time
get_wallets() Get supported wallets
Assets get_assets() Get all assets
get_collateral() Get collateral info
Markets get_markets() Get all markets
get_market(symbol) Get specific market
get_ticker(symbol) Get ticker
get_tickers() Get all tickers
get_depth(symbol) Get order book
get_klines(symbol, interval, startTime) Get candlesticks
get_mark_price(symbol) Get mark price
get_open_interest(symbol) Get open interest
get_funding_interval_rates(symbol) Get funding rates
Trades get_recent_trades(symbol) Get recent trades
get_historical_trades(symbol, limit, offset) Get trade history
Borrow/Lend get_borrow_lend_markets() Get lending markets
get_borrow_lend_market_history(interval) Get lending history
Prediction get_prediction_markets() Get prediction markets
get_prediction_tags() Get prediction tags

Authentication Client Methods

Category Method Description
Account get_account() Get account settings
update_account(...) Update account settings
get_max_borrow_quantity(symbol) Get max borrow amount
get_max_order_quantity(symbol, side) Get max order size
get_max_withdrawal_quantity(symbol) Get max withdrawal
Capital get_balances() Get balances
get_collateral() Get collateral
get_deposits() Get deposit history
get_deposit_address(blockchain) Get deposit address
get_withdrawals() Get withdrawal history
request_withdrawal(...) Request withdrawal
convert_dust(symbol) Convert dust to USDC
get_withdrawal_delay() Get withdrawal delay
create_withdrawal_delay(hours, token) Create withdrawal delay
update_withdrawal_delay(hours, token) Update withdrawal delay
Orders execute_order(...) Place single order
execute_batch_orders(orders) Place batch orders
get_users_open_orders(symbol) Get user's open orders
get_open_orders(symbol) Get open orders
cancel_open_order(symbol, orderId) Cancel single order
cancel_open_orders(symbol) Cancel all orders
History get_order_history(symbol) Get order history
get_fill_history(symbol) Get fill history
get_borrow_history() Get borrow history
get_interest_history() Get interest history
get_borrow_position_history() Get borrow positions
get_funding_payments() Get funding payments
get_settlement_history() Get settlements
get_dust_history() Get dust conversions
get_position_history() Get position history
get_strategy_history() Get strategy history
get_rfq_history() Get RFQ history
get_quote_history() Get quote history
get_rfq_fill_history() Get RFQ fills
get_quote_fill_history() Get quote fills
Borrow/Lend get_borrow_lend_positions() Get positions
execute_borrow_lend(quantity, side, symbol) Borrow or lend
get_estimated_liquidation_price(borrow) Get liquidation price
Positions get_open_positions() Get open positions
RFQ submit_rfq(symbol, side, quantity) Submit RFQ
submit_quote(rfqId, price) Submit quote
accept_quote(rfqId, quoteId) Accept quote
refresh_rfq(rfqId) Refresh RFQ
cancel_rfq(rfqId) Cancel RFQ
Strategy create_strategy(...) Create strategy
get_strategy(symbol, strategyId) Get strategy
get_open_strategies() Get open strategies
cancel_strategy(symbol, strategyId) Cancel strategy
cancel_all_strategies(symbol) Cancel all strategies

WebSocket Client

from backpack_exchange_sdk import WebSocketClient

# Public streams (no auth required)
ws = WebSocketClient()

# Private streams (auth required)
ws = WebSocketClient(api_key="<API_KEY>", secret_key="<SECRET_KEY>")

# Subscribe to streams
def on_message(data):
    print(data)

ws.subscribe(
    streams=["bookTicker.SOL_USDC"],
    callback=on_message
)

# Private stream example
ws.subscribe(
    streams=["account.orderUpdate"],
    callback=on_message,
    is_private=True
)

Available Enums

from backpack_exchange_sdk.enums import (
    # Order related
    OrderType,          # Limit, Market
    Side,               # Bid, Ask
    TimeInForce,        # GTC, IOC, FOK
    SelfTradePrevention,
    TriggerBy,

    # Market related
    MarketType,         # Spot, Perp
    FillType,
    KlineInterval,

    # Status related
    OrderStatus,
    DepositStatus,
    WithdrawalStatus,

    # And more...
)

Examples

See the examples directory for complete usage examples:

  • example_public.py - Public API examples
  • example_authenticated.py - Authenticated API examples
  • example_websocket.py - WebSocket streaming examples

Documentation

For detailed API documentation, visit the Backpack Exchange API Docs.

Changelog

v1.1.0

  • Added 21 new API endpoints (RFQ, Strategy, Prediction Markets, etc.)
  • Added 25+ new enum types
  • Refactored SDK architecture using mixins
  • 100% API coverage (70 endpoints)
  • Full type hints support

v1.0.x

  • Initial release with basic API support

Support

If this SDK has been helpful, please consider:

  1. Using my referral link to register: Register on Backpack Exchange
  2. Giving this repo a star on GitHub

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backpack_exchange_sdk-1.1.4.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

backpack_exchange_sdk-1.1.4-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file backpack_exchange_sdk-1.1.4.tar.gz.

File metadata

  • Download URL: backpack_exchange_sdk-1.1.4.tar.gz
  • Upload date:
  • Size: 36.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for backpack_exchange_sdk-1.1.4.tar.gz
Algorithm Hash digest
SHA256 a848630afec1d50b0f51b7f66d7f06a799b3d962ee2295adfc1bc125f48cb8f3
MD5 0fece74d6c0402b758a05202892467c3
BLAKE2b-256 d5dbd3f29ecd4d15dc27db503a68874888390a4bde9d181708a347cd69a54eaf

See more details on using hashes here.

File details

Details for the file backpack_exchange_sdk-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for backpack_exchange_sdk-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb2f9dd9ea4709e7333b66f58ad1ac7bc9c13aa65e6f7c707d911f58cf5abac2
MD5 bb129896be4a59d4de4007c59c917857
BLAKE2b-256 be1c865b095e5326bc891818a8f9a40e72d8c1c8284a8cf92248b01d6b64b789

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page