Skip to main content

Backpack API SDK tool

Project description

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

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

bpx_py-2.0.7.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

bpx_py-2.0.7-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file bpx_py-2.0.7.tar.gz.

File metadata

  • Download URL: bpx_py-2.0.7.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for bpx_py-2.0.7.tar.gz
Algorithm Hash digest
SHA256 1c5280d3a2ea7b4fe622c47efa98a4c488d037f241405952a7ddd1bb2dc58ef8
MD5 2816e367e69fb78637377bb3c54d1d24
BLAKE2b-256 d6c2e89e96483c9707a73595da3f760f45ba4c96d759c84c69bb5df7258dc8c2

See more details on using hashes here.

File details

Details for the file bpx_py-2.0.7-py3-none-any.whl.

File metadata

  • Download URL: bpx_py-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for bpx_py-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9f10460583829e5b5d156d750905f8130e49e08c6ef266427046ab3e353b72f6
MD5 dfa99e48fcc9561e349e4ad0ff609a93
BLAKE2b-256 5a13deab1e40b255f3e021a53529725b0be6734ad905424b9a608d8881b11f18

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