# Use Adrena

The `Use Adrena` tool, part of AgentiPy, allows users to interact with the Adrena perpetual trading protocol on the Solana blockchain. It facilitates opening and closing long and short perpetual positions through an Agentipy proxy service.

## Functionality

This tool is implemented in the `AdrenaTradeManager` class. Operations are routed via an Agentipy proxy service (`agent.base_proxy_url`), which requires the agent's private key to be encrypted and sent with each request. An OpenAI API key also seems to be part of the payload to the proxy.

### Key Methods:

* `open_perp_trade_long(agent: SolanaAgentKit, price: float, collateral_amount: float, collateral_mint: Optional[str] = None, leverage: Optional[float] = None, trade_mint: Optional[str] = None, slippage: Optional[float] = None) -> Optional[Dict[str, Any]]`:
  * Opens a long perpetual position on Adrena.
  * Requires `price` (entry price) and `collateral_amount`.
  * Optional parameters include `collateral_mint` (e.g., USDC mint address), `leverage`, `trade_mint` (the asset being traded, e.g., SOL mint address), and `slippage`.
  * Returns a dictionary with the transaction details or an error.
* `open_perp_trade_short(agent: SolanaAgentKit, price: float, collateral_amount: float, collateral_mint: Optional[str] = None, leverage: Optional[float] = None, trade_mint: Optional[str] = None, slippage: Optional[float] = None) -> Optional[Dict[str, Any]]`:
  * Opens a short perpetual position on Adrena.
  * Parameters are similar to `open_perp_trade_long`.
  * Returns a dictionary with the transaction details or an error.
* `close_perp_trade_long(agent: SolanaAgentKit, price: float, trade_mint: str) -> Optional[Dict[str, Any]]`:
  * Closes an existing long perpetual position.
  * Requires `price` (closing price) and `trade_mint` (the asset of the position).
  * Returns a dictionary with the transaction details or an error.
* `close_perp_trade_short(agent: SolanaAgentKit, price: float, trade_mint: str) -> Optional[Dict[str, Any]]`:
  * Closes an existing short perpetual position.
  * Requires `price` (closing price) and `trade_mint`.
  * Returns a dictionary with the transaction details or an error.

##

**Important Considerations:**

* **Proxy Service:** Relies on an Agentipy proxy service. Understand its terms and ensure it's configured in `SolanaAgentKit`.
* **Financial Risk:** Perpetual trading is highly risky and can lead to rapid loss of funds, including liquidation of collateral. This tool should be used with extreme caution and a thorough understanding of Adrena's mechanics and market risks.
* **API Keys:** An OpenAI API key is passed to the proxy; its purpose in this context should be clarified by the proxy documentation.
* **On-Chain Costs:** All trading operations are on-chain transactions incurring SOL fees and requiring sufficient collateral.
* **Market Parameters:** Correct `trade_mint`, `collateral_mint`, `price`, and `leverage` are crucial and specific to the Adrena markets.

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_adrena.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-adrena.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.
