# Use Backpack

The `Use Backpack` tool, part of AgentiPy, provides functionalities for interacting with the Backpack Exchange. It allows users to manage their account, including fetching balances, requesting withdrawals, getting deposit history, executing orders, and accessing market data. This tool uses the `backpack-exchange-sdk`.

## Functionality

This tool is implemented in the `BackpackManager` class, which wraps both authenticated and public client functionalities of the Backpack Exchange SDK.

### Key Methods:

**Authenticated (require API key and secret in `SolanaAgentKit`):**

* `__init__(self, agent: SolanaAgentKit)`: Initializes `AuthenticationClient` using `agent.backpack_api_key` and `agent.backpack_api_secret`.
* `get_account_balances() -> dict`: Retrieves current account balances.
* `request_withdrawal(address: str, blockchain: str, quantity: str, symbol: str, ...)`: Initiates a withdrawal request.
* `get_account_settings() -> dict`: Fetches current account settings.
* `update_account_settings(...)`: Modifies account settings like auto-borrow or leverage limits.
* `get_borrow_lend_positions() -> dict`: Retrieves open borrow/lend positions.
* `execute_borrow_lend(quantity: str, side: str, symbol: str)`: Executes a borrow or lend operation.
* `get_account_deposits(fromTimestamp: int = None, ...)`: Fetches deposit history.
* `get_fill_history(order_id: str = None, ...)`: Retrieves historical trade fills.
* `execute_order(order_type: str, side: str, symbol: str, ...)`: Places an order on the exchange.
* `cancel_open_order(symbol: str, order_id: str = None, ...)`: Cancels an open order.
* And many more for fetching order history, open orders, PNL history, etc.

**Public (do not require authentication):**

* `get_supported_assets() -> dict`: Lists all assets supported by the exchange.
* `get_ticker_information(symbol: str) -> dict`: Gets ticker statistics for a specific market symbol.
* `get_markets() -> dict`: Retrieves details for all supported markets.
* `get_depth(symbol: str) -> dict`: Fetches order book depth for a market.
* `get_klines(symbol: str, interval: str, start_time: int, ...)`: Gets K-line (candlestick) data.
* And more for mark price, open interest, system status, etc.

##

**Note:** This tool interacts with the Backpack Exchange.

* Public methods can be used without an API key.
* Authenticated methods (for account management, trading, withdrawals) require a valid Backpack API key and secret to be set in the `SolanaAgentKit` instance (`agent.backpack_api_key`, `agent.backpack_api_secret`).
* Ensure your API keys have the appropriate permissions for the actions you intend to perform. Handle API keys securely.

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_backpack.py>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agentipy.fun/tools/use-backpack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
