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, including custom artificial endpoints for enhanced functionality. This SDK ensures developers have the most current tools for seamless integration with Backpack services.
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_query("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
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_query("SOL_USDC",
limit=10,
window=10000)
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
import asyncio
async def main():
public = Public()
assets = await public.get_assets()
await asyncio.sleep(1)
klines = await public.get_klines("SOL_USDC", "1d")
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.request_configuration 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.
bpx.constants
- constants that may help if you don't know which variables are existing.
Useful sources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bpx_py-1.2.2.tar.gz
.
File metadata
- Download URL: bpx_py-1.2.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53bd575558600d3af7f3d04863ab4167bff247e7b78751e54b45b9d8c0b259bb |
|
MD5 | 8126c3e4ee1eb245ce5ab45fc63e9139 |
|
BLAKE2b-256 | 36b781fc897645bf2a50d986c2cd726e69ca8772a464108d1db28a651aff0eab |
File details
Details for the file bpx_py-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: bpx_py-1.2.2-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f3fc803d52c514c991919f2e6c382da6e6bd720a99b9bd74f361fc0232c6f9 |
|
MD5 | ef712a8c4b0468cf7115a4bf5bb5f2a3 |
|
BLAKE2b-256 | 27783cdbbc66f14c1419f9bca3ca445a3f0021cde11631b91e6df9c0d6fd5fe3 |