Skip to main content

Backpack SDK

This Backpack SDK is a continuously updated and supported Python toolkit that provides comprehensive access to all Backpack endpoints.

Trade on spot/perp markets, manage your account, lend/borrow and retrieve various data using Backpack API.

Installation

bpx-py is stable on python >= 3.8

pip install bpx-py

Usage

Make an account and generate API keys on Backpack

Account example

from bpx.account import Account

public_key = "<KEY>"
secret_key = "<KEY>"
account = Account(public_key, 
        secret_key,
        window=6000, # default value is 5000
        proxy={"http":"132.142.132.12:3128"}) # you can use any requests proxy supported by requests
deposit_address_sol = account.get_deposit_address("Solana")
account_fills = account.get_fill_history("SOL_USDC", 
                                               limit=10,
                                               window=10000) # window only for this order
print(deposit_address_sol)
print(account_fills)

bpx-py supports async code:

from bpx.async_.account import Account
from bpx.constants.enums import MarketTypeEnum
import asyncio

async def main():
    public_key = "<KEY>"
    secret_key = "<KEY>"
    account = Account(public_key, secret_key, proxy="http://your_proxy-address:1234")
    deposit_address_sol = await account.get_deposit_address("Solana")
    await asyncio.sleep(1)
    account_fills = await account.get_fill_history("SOL_USDC", 
                                               limit=10,
                                               window=10000,
                                               market_type=MarketTypeEnum.SPOT)
    print(deposit_address_sol)
    print(account_fills)

asyncio.run(main())

Public

Backpack has public endpoints that don't need API keys:

from bpx.public import Public

public = Public() 
server_time = public.get_time()
markets = public.get_markets()
print(server_time)
print(markets)

Async code:

from bpx.async_.public import Public
from bpx.constants.enums import BorrowLendMarketHistoryIntervalEnum
import asyncio

async def main():
    public = Public()
    assets = await public.get_assets()
    await asyncio.sleep(1)
    klines = await public.get_borrow_lend_market_history(BorrowLendMarketHistoryIntervalEnum.ONE_DAY)
    print(assets)
    print(klines)
    
asyncio.run(main())

Request Configuration

You can get the request configuration using bpx.base.base_account and bpx.base.base_public without doing a request.

from bpx.base.base_account import BaseAccount
from bpx.base.base_public import BasePublic
from bpx.models.objects import RequestConfiguration  # unnecessary

base_public = BasePublic()
base_account = BaseAccount("<PUBLIC_KEY>", "<SECRET_KEY>", window=5000, debug=True)

# let's get url and headers for this account request
request_config: RequestConfiguration = base_account.get_balances()
url = request_config.url
headers = request_config.headers
# let's get url for this public request
request_url: str = base_public.get_ticker_url(symbol="SOL_USDC")

Can be useful

bpx.models - models that are in use by request and response (not full).

bpx.constants.enums - Enums and literals for your use and IDE typing.

Useful sources

Discord channel to get help

Backpack API DOCS

PYPI

Backpack help center

Metadata

Release files for bpx-py 2.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bpx-py 2.0.11
File Size Uploaded
bpx_py-2.0.11.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bpx-py 2.0.11
File Interpreter ABI Platform
bpx_py-2.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 43.2 kB

Release files / bpx_py-2.0.11.tar.gz

Download URL bpx_py-2.0.11.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7e32423e9884773e47d8a06ae40bd0ec7d3061481d564be8f1f548bad8ec8e59
BLAKE2b-256 checksum
How to use checksums
08b9ae67ec5bd05c05e239b49091ed0220c6359e0bc0f5f93c3e4ee42e1cb0cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Linux/6.8.0-1021-azure

Release files / bpx_py-2.0.11-py3-none-any.whl

Download URL bpx_py-2.0.11-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba76bc05fe858c2b5e89ce9fd7857f8ba0f910ec556befb5674c94b65b35ada8
BLAKE2b-256 checksum
How to use checksums
adf095792aaef010ddee57443d289d6314d633b0c87d45910ee65a2fb6e1cd1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

2.0.11 This release

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.1

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page