Adrena Protocol Integration
Learn how to use perpetual trading functionality with Adrena Protocol
Ping Agent Kit provides comprehensive integration with Adrena Protocol for perpetual trading. The integration supports both long and short positions with configurable leverage and slippage parameters.
Long/Short position trading
Configurable leverage up to 100x
Slippage protection
Automated token account setup
Price feed integration
Copy
const signature = await agent.methods.openPerpTradeLong({
price: 300, // USD price
collateralAmount: 10, // Amount of collateral
collateralMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"), // jitoSOL
leverage: 50000, // 5x leverage (10000 = 1x)
tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"), // Trading asset
slippage: 0.3, // 0.3% slippage tolerance
});
Copy
const signature = await agent.methods.openPerpTradeShort({
price: 300,
collateralAmount: 10,
collateralMint: TOKENS.USDC, // Default collateral for shorts
leverage: 50000,
tradeMint: TOKENS.jitoSOL,
slippage: 0.3,
});
Copy
const signature = await agent.methods.closePerpTradeLong({
price: 200, // Minimum exit price
tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"),
});
Copy
const signature = await agent.methods.closePerpTradeShort({
price: 200,
tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"),
});
Ping Agent Kit provides LangChain tools for automated trading:
Copy
import { PingPerpOpenTradeTool } from 'ping-agent-kit';
const openTradeTool = new PingPerpOpenTradeTool(agent);
// Tool input format:
const input = {
collateralAmount: 1,
collateralMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
tradeMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
leverage: 50000,
price: 100,
slippage: 0.3,
side: "long" // or "short"
};
Copy
import { PingPerpCloseTradeTool } from 'ping-agent-kit';
const closeTradeTool = new PingPerpCloseTradeTool(agent);
// Tool input format:
const input = {
tradeMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
price: 100,
side: "long" // or "short"
};
For LangChain AI tools, here are example prompts:
Copy
"Open a long position in SOL with 5x leverage using 10 jitoSOL as collateral"
"Short ETH with 3x leverage using 100 USDC as collateral with 0.5% slippage"
"Go long on JitoSOL with maximum leverage of 10x using 5 SOL"
Copy
"Close my long SOL position at $100 minimum price"
"Exit short ETH position when price reaches $2000"
"Close all my open perpetual trades"
Leverage Configuration
Leverage is specified in basis points (10000 = 1x)
Maximum leverage varies by market
Example: 50000 = 5x leverage
Collateral Types
Long positions: Use same token as tradeMint to avoid swaps
Short positions: USDC recommended as collateral
Price and Slippage
Price in USD
Slippage as percentage (0.3 = 0.3%)
Always monitor price impact before trading
Copy
try {
await agent.methods.openPerpTradeLong({...});
} catch (error) {
if (error.message.includes("insufficient funds")) {
// Handle insufficient collateral
} else if (error.message.includes("slippage tolerance exceeded")) {
// Handle price movement
}
}
Copy
const ADRENA_PROGRAM_ID = new PublicKey(
"13gDzEXCdocbj8iAiqrScGo47NiSuYENGsRqi3SEAwet"
);
Copy
const PRICE_DECIMALS = 10;
Copy
const DEFAULT_OPTIONS = {
LEVERAGE_BPS: 50000, // 5x leverage
};
jitoSOL
USDC
Additional assets based on protocol liquidity
Last updated