Backpack Exchange Python API guide
Prerequisites
Get your API keys if you are going to use account endpoints: https://backpack.exchange/portfolio/settings/api-keys
Install the required Python libraries:
cryptography โ for X-Signature (account endpoints only)
requests โ for making HTTP requests (or aiohttp if you prefer async)
pip3 install cryptography requests Install dotenv-python to securely manage your keys using environment variables if you are going to use account endpoints
pip3 install python-dotenvCreate a .env file and store your keys like this:
PUBLIC_KEY=zDIJj9qneWIY0IYZ5aXoHcNMCm+XDhVcTssiT0HyY0A=
SECRET_KEY=4odxgSUxFrC/zsKWZF4OQwYAgnNu9hnWH3NxWfLAPz4=Create a .gitignore file and add .env to exclude it from version control.
.envFor all examples, we will use the synchronous requests library. Let's import it:
import requestsPublic endpoints
For public endpoints, simply send a GET request.
No API keys are required.
Example: Accessing Public Data
Note: If you have more than one argument, join them using the & symbol.
Private endpoints
For private endpoints, we need to create specific headers and a request body (for POST requests). This requires authentication with your API keys.
Example: Retrieving a Deposit Address
Let's see how to retrieve a deposit address using the API: https://docs.backpack.exchange/#tag/Capital/operation/get_deposit_address
Now that we have our authentication components ready (X-Timestamp, X-Window, and X-API-Key), let's create the signature.
Signing the Request
Now let's sign the request with our private key:
Creating Headers
Create the required headers for the API request:
Sending the Request
Now we can send the authenticated request to the API:
Using POST Requests
For POST requests, you need to include the JSON body and use the post() method instead of get().
Example: Executing an Order
Let's see how to submit an order to the matching engine for execution using the API: https://api.backpack.exchange/api/v1/order
Sources
SDK makes the development process much easier.
Example SDK: https://github.com/sndmndss/bpx-py
For more information, visit the official documentation: https://docs.backpack.exchange/
Last updated
