Metadata-Version: 2.3
Name: bpx-py
Version: 2.0.11
Summary: Backpack API SDK tool
License: Apache-2.0
Keywords: api,sdk,backpack,client,wrapper
Author: sndmndss
Author-email: yanfedorov120505@gmail.com
Requires-Python: >=3.8,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
Requires-Dist: cryptography (>=42.0.5,<44.0.0)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Project-URL: Bug Tracker, https://github.com/sndmndss/bpx-py/issues
Project-URL: Get help in discord, https://discord.gg/backpack
Project-URL: Homepage, https://backpack.exchange
Project-URL: Repository, https://github.com/sndmndss/bpx-py/
Description-Content-Type: text/markdown


# 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

```bash
pip install bpx-py
```

## Usage

Make an account and generate API keys on [Backpack](https://backpack.exchange/settings/api-keys)

### Account example

```python
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:
```python
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:

```python
from bpx.public import Public

public = Public() 
server_time = public.get_time()
markets = public.get_markets()
print(server_time)
print(markets)
```
**Async** code:

```python
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.

```python
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](https://discord.gg/backpack)

[Backpack API DOCS](https://docs.backpack.exchange)

[PYPI](https://pypi.org/project/bpx-py/)

[Backpack help center](https://support.backpack.exchange)



