# 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)
Raw data
{
"_id": null,
"home_page": "https://backpack.exchange",
"name": "bpx-py",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "api, sdk, backpack, client, wrapper",
"author": "sndmndss",
"author_email": "yanfedorov120505@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0b/94/82783303006bd5ac241ca870efadd0138ac29317ed86b20be85806667365/bpx_py-2.0.1.tar.gz",
"platform": null,
"description": "\n# Backpack SDK\n\nThis Backpack SDK is a continuously updated and supported Python toolkit that provides comprehensive access to all Backpack endpoints. \n\nTrade on spot/perp markets, manage your account, lend/borrow and retrieve various data using Backpack API.\n\n\n## Installation\n\nbpx-py is stable on _python_ >= 3.8\n\n```bash\npip install bpx-py\n```\n\n## Usage\n\nMake an account and generate API keys on [Backpack](https://backpack.exchange/settings/api-keys)\n\n### Account example\n\n```python\nfrom bpx.account import Account\n\npublic_key = \"<KEY>\"\nsecret_key = \"<KEY>\"\naccount = Account(public_key, \n secret_key,\n window=6000, # default value is 5000\n proxy={\"http\":\"132.142.132.12:3128\"}) # you can use any requests proxy supported by requests\ndeposit_address_sol = account.get_deposit_address(\"Solana\")\naccount_fills = account.get_fill_history(\"SOL_USDC\", \n limit=10,\n window=10000) # window only for this order\nprint(deposit_address_sol)\nprint(account_fills)\n```\n\nbpx-py supports **async** code:\n```python\nfrom bpx.async_.account import Account\nfrom bpx.constants.enums import MarketTypeEnum\nimport asyncio\n\nasync def main():\n public_key = \"<KEY>\"\n secret_key = \"<KEY>\"\n account = Account(public_key, secret_key, proxy=\"http://your_proxy-address:1234\")\n deposit_address_sol = await account.get_deposit_address(\"Solana\")\n await asyncio.sleep(1)\n account_fills = await account.get_fill_history(\"SOL_USDC\", \n limit=10,\n window=10000,\n market_type=MarketTypeEnum.SPOT)\n print(deposit_address_sol)\n print(account_fills)\n\nasyncio.run(main())\n```\n\n### Public\n\nBackpack has public endpoints that don't need API keys:\n\n```python\nfrom bpx.public import Public\n\npublic = Public() \nserver_time = public.get_time()\nmarkets = public.get_markets()\nprint(server_time)\nprint(markets)\n```\n**Async** code:\n\n```python\nfrom bpx.async_.public import Public\nfrom bpx.constants.enums import BorrowLendMarketHistoryIntervalEnum\nimport asyncio\n\nasync def main():\n public = Public()\n assets = await public.get_assets()\n await asyncio.sleep(1)\n klines = await public.get_borrow_lend_market_history(BorrowLendMarketHistoryIntervalEnum.ONE_DAY)\n print(assets)\n print(klines)\n \nasyncio.run(main())\n```\n\n### Request Configuration\n\nYou can get the request configuration using `bpx.base.base_account` and `bpx.base.base_public` without doing a request.\n\n```python\nfrom bpx.base.base_account import BaseAccount\nfrom bpx.base.base_public import BasePublic\nfrom bpx.models.objects import RequestConfiguration # unnecessary\n\nbase_public = BasePublic()\nbase_account = BaseAccount(\"<PUBLIC_KEY>\", \"<SECRET_KEY>\", window=5000, debug=True)\n\n# let's get url and headers for this account request\nrequest_config: RequestConfiguration = base_account.get_balances()\nurl = request_config.url\nheaders = request_config.headers\n# let's get url for this public request\nrequest_url: str = base_public.get_ticker_url(symbol=\"SOL_USDC\")\n```\n\n### Can be useful \n\n`bpx.models` - models that are in use by request and response (not full).\n\n`bpx.constants.enums` - Enums and literals for your use and IDE typing.\n\n## Useful sources\n\n[Discord channel to get help](https://discord.gg/backpack)\n\n[Backpack API DOCS](https://docs.backpack.exchange)\n\n[PYPI](https://pypi.org/project/bpx-py/)\n\n[Backpack help center](https://support.backpack.exchange)\n\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Backpack API SDK tool",
"version": "2.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/sndmndss/bpx-py/issues",
"Get help in discord": "https://discord.gg/backpack",
"Homepage": "https://backpack.exchange",
"Repository": "https://github.com/sndmndss/bpx-py/"
},
"split_keywords": [
"api",
" sdk",
" backpack",
" client",
" wrapper"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c8fe60519eb2ffe43ef7e75419aa6c7d45e96c25665001317efd12909d6f3ac",
"md5": "c5926951e998dd3641151c7b3e275441",
"sha256": "c51fb3114b9a288ef55cf5a9fbff52483e206012dbb80ce315f928a8ac11b743"
},
"downloads": -1,
"filename": "bpx_py-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c5926951e998dd3641151c7b3e275441",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 23439,
"upload_time": "2025-02-03T04:57:04",
"upload_time_iso_8601": "2025-02-03T04:57:04.182770Z",
"url": "https://files.pythonhosted.org/packages/9c/8f/e60519eb2ffe43ef7e75419aa6c7d45e96c25665001317efd12909d6f3ac/bpx_py-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0b9482783303006bd5ac241ca870efadd0138ac29317ed86b20be85806667365",
"md5": "b6576d756213265871c8109111e730f0",
"sha256": "36ba645a5735dadf9a3aa83f842274c2adc51064d6641d63b8adf47de0207be6"
},
"downloads": -1,
"filename": "bpx_py-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b6576d756213265871c8109111e730f0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 17030,
"upload_time": "2025-02-03T04:57:06",
"upload_time_iso_8601": "2025-02-03T04:57:06.002300Z",
"url": "https://files.pythonhosted.org/packages/0b/94/82783303006bd5ac241ca870efadd0138ac29317ed86b20be85806667365/bpx_py-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-03 04:57:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sndmndss",
"github_project": "bpx-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "aiohttp",
"specs": [
[
"==",
"3.10.2"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"42.0.5"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.32.0"
]
]
}
],
"lcname": "bpx-py"
}