A comprehensive Python SDK for the Backpack Exchange API, providing both REST and WebSocket functionality for trading and market data access.
- 🚀 Complete API Coverage: Full support for all Backpack Exchange API endpoints
- 🔐 Secure Authentication: ED25519 signature-based authentication
- 📡 Real-time Data: WebSocket support for live market data
- ⚡ Async Support: Both synchronous and asynchronous operations
- 🛡️ Type Safety: Full type hints and Pydantic models
- 📊 Market Data: Order books, tickers, trades, and more
- 💼 Trading: Order management, positions, and account operations
pip install -r requirements.txtfrom backpack import ApiClient, Configuration
from backpack.api.markets_api import MarketsApi
# Create configuration
config = Configuration(host="https://api.backpack.exchange")
api_client = ApiClient(config)
# Get markets
markets_api = MarketsApi(api_client)
markets = markets_api.get_markets()
print(f"Found {len(markets)} markets")
# Get market info
market_info = markets_api.get_market("SOL_USDC")
print(f"SOL_USDC info: {market_info}")
# Get order book
depth = markets_api.get_depth("SOL_USDC", limit=10)
print(f"Order book: {depth}")from backpack import SignerClient
# Create signer client with your API credentials
signer_client = SignerClient(
api_key="your_api_key",
api_secret="your_api_secret"
)
# Get account information
account = signer_client.get_account()
print(f"Account: {account}")
# Get balances
balances = signer_client.get_balances()
print(f"Balances: {balances}")
# Create an order
order = signer_client.create_order(
symbol="SOL_USDC",
side="Bid",
order_type="Limit",
quantity="1.0",
price="20.50"
)
print(f"Order created: {order}")from backpack import WsClient
def on_message(data):
print(f"Received: {data}")
def on_error(error):
print(f"Error: {error}")
# Create WebSocket client
ws_client = WsClient(
on_message=on_message,
on_error=on_error
)
# Connect and subscribe
if ws_client.connect():
# Subscribe to order book updates
ws_client.subscribe("depth.SOL_USDC")
# Subscribe to ticker updates
ws_client.subscribe("ticker.SOL_USDC")
# Run the client
ws_client.run()import asyncio
from backpack import ApiClient, Configuration
from backpack.api.markets_api import MarketsApi
async def main():
config = Configuration(host="https://api.backpack.exchange")
api_client = ApiClient(config)
markets_api = MarketsApi(api_client)
# Get markets asynchronously
markets = await markets_api.get_markets(async_req=True)
print(f"Found {len(markets)} markets")
await api_client.close()
# Run async function
asyncio.run(main())- MarketsApi: Market data, order books, trades
- AssetsApi: Asset information
- SystemApi: System status
- TradesApi: Public trade data
- AccountApi: Account information and balances
- OrderApi: Order management
- PositionApi: Position management
- CapitalApi: Capital operations
- HistoryApi: Historical data
- FundingApi: Funding rates
- BorrowLendApi: Borrowing and lending
ticker.<symbol>: 24hr ticker statisticsdepth.<symbol>: Order book depth updatesbookTicker.<symbol>: Best bid/ask pricestrade.<symbol>: Public trade datakline.<interval>.<symbol>: K-line/candlestick data
account.orderUpdate: Order updatesaccount.positionUpdate: Position updatesaccount.rfqUpdate: RFQ updates
python examples/backpack_price_monitor.pypython examples/backpack_example.pypython examples/backpack_price_monitor.py asyncexport BACKPACK_API_KEY="your_api_key"
export BACKPACK_API_SECRET="your_api_secret"
export BACKPACK_HOST="https://api.backpack.exchange"from backpack import Configuration
config = Configuration(
host="https://api.backpack.exchange",
api_key="your_api_key",
api_secret="your_api_secret",
timeout=30,
retry_count=3
)The Backpack Exchange API uses ED25519 signature-based authentication:
- API Key: Your public key (base64 encoded)
- API Secret: Your private key for signing requests
- Signing: All authenticated requests must be signed with ED25519
- Build the signing string with instruction, parameters, timestamp, and window
- Sign the string with your private key using ED25519
- Include the signature in the
X-Signatureheader
from backpack.exceptions import ApiException, AuthenticationError
try:
account = signer_client.get_account()
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ApiException as e:
print(f"API error: {e}")The API has rate limits that vary by endpoint:
- Public endpoints: 120 requests per minute
- Authenticated endpoints: 60 requests per minute
- WebSocket connections: 1 connection per API key
# Automatic reconnection
ws_client = WsClient(
on_message=handle_message,
on_error=handle_error,
on_close=handle_close
)
# Manual connection management
if ws_client.connect():
ws_client.subscribe("ticker.SOL_USDC")
ws_client.run()pytest tests/black backpack/
flake8 backpack/mypy backpack/This project is licensed under the MIT License.
For issues and questions:
- GitHub Issues: Create an issue
- Documentation: Backpack Exchange API Docs
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
- Initial release
- Full API coverage
- WebSocket support
- Async operations
- Type safety with Pydantic