Ranger Protocol
Learn how to interact with Ranger Protocol for perpetual trading operations
Interact with Ranger Protocol to execute perpetual trading operations on Solana. Ranger provides a Smart Order Router (SOR) API that allows users to open, close, increase, and decrease positions across various venues like Flash, Jupiter, Drift, and Adrena.
Usage
Methods
openPerpTrade
Open a new perpetual trading position using Ranger SOR API.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Trading pair symbol (e.g., “SOL”, “BTC”) |
side | ”Long” | “Short” | Yes | Position direction |
size | number | Yes | Position size in tokens |
collateral | number | Yes | Collateral amount in USDC |
apiKey | string | Yes | Ranger API key |
Example
closePerpTrade
Close an existing perpetual trading position.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Trading pair symbol (e.g., “SOL”, “BTC”) |
side | ”Long” | “Short” | Yes | Position direction |
apiKey | string | Yes | Ranger API key |
Example
increasePerpPosition
Increase the size of an existing perpetual position.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Trading pair symbol (e.g., “SOL”, “BTC”) |
side | ”Long” | “Short” | Yes | Position direction |
size | number | Yes | Additional position size |
collateral | number | Yes | Additional collateral in USDC |
apiKey | string | Yes | Ranger API key |
Example
decreasePerpPosition
Decrease the size of an existing perpetual position.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Trading pair symbol (e.g., “SOL”, “BTC”) |
side | ”Long” | “Short” | Yes | Position direction |
size | number | Yes | Size to decrease by |
apiKey | string | Yes | Ranger API key |
Example
withdrawBalance
Withdraw available balance from Ranger.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Token symbol (e.g., “USDC”) |
amount | number | Yes | Amount to withdraw |
apiKey | string | Yes | Ranger API key |
Example
withdrawCollateral
Withdraw collateral from an existing position.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
symbol | string | Yes | Trading pair symbol (e.g., “SOL”, “BTC”) |
side | ”Long” | “Short” | Yes | Position direction |
collateral | number | Yes | Collateral amount to withdraw in USDC |
apiKey | string | Yes | Ranger API key |
Example
Example Implementation
Implementation Details
- Smart Order Router (SOR): Ranger’s SOR optimizes trade execution across multiple venues.
- Multiple Venues: Supports trading across various platforms including Flash, Jupiter, Drift, and Adrena.
- Position Management: Complete toolkit for opening, closing, increasing, and decreasing perpetual positions.
- Collateral Management: Functions for adding and withdrawing collateral from positions.
- Data Access: Comprehensive data access for positions, quotes, trade history, and market metrics.
About Ranger Protocol
Ranger is a protocol designed to provide optimized perpetual trading on Solana. It offers a Smart Order Router (SOR) that routes orders across various trading venues to achieve the best execution. Key features include:
- Cross-venue execution: Trade across multiple venues with a single API
- Capital efficiency: Optimize collateral usage across positions
- Low slippage: Smart routing to minimize price impact
- Advanced position management: Sophisticated tools for managing perpetual positions
- Rich market data: Access to funding rates, liquidation data, and other market metrics
Error Handling
Best Practices
-
API Key Management
- Securely store and manage your Ranger API key
- Never expose your API key in client-side code
- Implement proper scoping and permissions for API keys
-
Position Sizing
- Use appropriate position sizes relative to your capital
- Consider market volatility when determining leverage
- Monitor positions regularly to manage risk
-
Collateral Management
- Maintain sufficient collateral to avoid liquidations
- Use the withdrawCollateral function judiciously
- Monitor health factors for positions
-
Error Handling
- Implement robust error handling for all API calls
- Include retry logic for temporary failures
- Monitor transaction status until confirmed
Common Market Symbols
- SOL-PERP
- BTC-PERP
- ETH-PERP
- BONK-PERP
- JTO-PERP
Response Format
Related Functions
getBalance
: Check token balancesgetFundingRateArbs
: Get funding rate arbitrage opportunitiesgetLiquidationsLatest
: Get the latest liquidation eventsgetFundingRatesAccumulated
: Get accumulated funding ratesgetBorrowRatesAccumulated
: Get accumulated borrow rates