Overview
The Perpetuals SDK provides both asynchronous and synchronous clients for retrieving data from the Fairground perpetuals platform. All data retrieval is performed through connectRPC calls that return strongly-typed protobuf objects.Client Setup
Async Client (Recommended)
Sync Client
Available Data Retrieval Methods
Get Order
Retrieve detailed information about a specific order.Method Signature
Parameters
- order_id (int): The unique identifier for the order
- market_id (int): The market identifier where the order was placed
- reduce_only (bool): Whether to filter for reduce-only orders (default: False)
- timeout_ms (Optional[int]): Request timeout in milliseconds (overrides client default)
Returns
Returns anOrder protobuf object containing:
- Order details (size, price, leverage, etc.)
- Current status and fill information
- Market and trader information
- Timestamps and metadata
Get Orders (Batch)
Retrieve multiple orders with filtering options for efficient batch operations.Method Signature
Parameters
- address (str): The wallet address to get orders for
- timeout_ms (Optional[int]): Request timeout in milliseconds
Returns
Returns a list ofOrder protobuf objects for the specified address.
Get Open Positions
Retrieve open trading positions with filtering options.Method Signature
Parameters
- address (str): The wallet address to get positions for
- timeout_ms (Optional[int]): Request timeout in milliseconds
Returns
Returns a list ofPosition protobuf objects containing:
- Position details (size, entry price, leverage, etc.)
- Profit and loss information
- Margin and liquidation data
- Market and trader information
Example Usage
Error Handling
ConnectRPC Errors
The SDK uses connectRPC’s error handling system. All API calls can raiseConnectError exceptions:
Common Error Codes
| Code | Description | Typical Causes |
|---|---|---|
NOT_FOUND | Resource not found | Invalid order_id or market_id |
DEADLINE_EXCEEDED | Request timeout | Network issues or server overload |
PERMISSION_DENIED | Access denied | Authentication or authorization failure |
UNAVAILABLE | Service unavailable | Server maintenance or outage |
INVALID_ARGUMENT | Invalid request | Malformed parameters |
Data Processing
Converting to Python Dictionaries
Enum Processing
Formatting for Display
Performance Considerations
Connection Pooling
Reuse HTTP sessions for better performance:Timeout Configuration
Configure appropriate timeouts for different use cases:Concurrent Requests
Use asyncio for concurrent data retrieval and prefer batch operations when possible:Best Practices
- Use async clients for better performance in I/O-bound applications
- Prefer batch operations - Use
get_orders()andget_open_positions()instead of multiple individual calls - Reuse HTTP sessions to avoid connection overhead
- Implement proper error handling for network failures and API errors
- Set appropriate timeouts based on your application’s requirements
- Use connection pooling for high-throughput applications
- Cache frequently accessed data to reduce API calls
- Implement retry logic for transient failures
- Monitor API rate limits and implement backoff strategies
- Filter data server-side using method parameters to reduce bandwidth and processing
- Use concurrent requests wisely - batch operations are usually more efficient than parallel individual calls
Testing Data Retrieval
Mocking for Unit Tests
Future Extensions
As the API expands, additional data retrieval methods will be added following the same patterns:get_market_data()- Retrieve market information and pricing dataget_account_info()- Retrieve account details and balancesget_trade_history()- Retrieve historical trade recordsget_funding_payments()- Retrieve funding payment history
- Async/sync support with consistent signatures
- Comprehensive error handling and timeout configuration
- Type safety with strongly-typed protobuf objects
- Utility function support for formatting and conversion
- Efficient batch operations where applicable