Core Data Objects
Order
The primary data object representing a trading order in the perpetuals platform.Fields
| Field | Type | Description |
|---|---|---|
order_id | int32 | Unique identifier for the order |
owner | string | The owner identifier for the order |
timestamp | string | Order creation timestamp (ISO 8601 format) |
market_id | int32 | Identifier for the trading market |
market | string | Human-readable market name (e.g., “BTC-PERP”) |
type | OrderType | Type of order (MARKET, LIMIT, etc.) |
side | Side | Order side (LONG or SHORT) |
threshold_price | float | Price threshold for order execution |
size | float | Order size/quantity |
leverage | int32 | Leverage multiplier |
status | OrderStatus | Current order status |
filled_size | float | Amount of the order that has been filled |
reduce_only | bool | Whether this is a reduce-only order |
Example
Position
The data object representing an open trading position in the perpetuals platform.Fields
| Field | Type | Description |
|---|---|---|
owner | string | The owner identifier for the position |
market_id | int32 | Identifier for the trading market |
market | string | Human-readable market name (e.g., “BTC-PERP”) |
side | Side | Position side (LONG or SHORT) |
size | float | Position size/quantity |
leverage | int32 | Leverage multiplier for the position |
entry_price | float | Average entry price for the position |
mark_price | float | Current mark price for the position |
unrealized_pnl | float | Unrealized profit and loss |
realized_pnl | float | Realized profit and loss |
margin_type | MarginType | Type of margin (CROSS or ISOLATED) |
margin_amount | float | Amount of margin allocated to the position |
liquidation_price | float | Price at which position would be liquidated |
timestamp | string | Position creation/update timestamp (ISO 8601 format) |
Example
GetOrderRequest
Request object for retrieving order information.Fields
| Field | Type | Description |
|---|---|---|
order_id | int32 | The unique order identifier to retrieve |
market_id | int32 | The market identifier where the order exists |
reduce_only | bool | Filter for reduce-only orders |
Example
GetOrderResponse
Response object containing order information.Fields
| Field | Type | Description |
|---|---|---|
order | Order | The requested order object |
Example
GetOrdersRequest
Request object for retrieving multiple orders with filtering options.Fields
| Field | Type | Description |
|---|---|---|
owner | string | Filter orders by owner identifier |
market_id | int32 | Filter orders by market identifier |
side | Side | Filter orders by side (optional) |
status | OrderStatus | Filter orders by status (optional) |
limit | int32 | Maximum number of orders to return |
Example
GetOrdersResponse
Response object containing multiple orders.Fields
| Field | Type | Description |
|---|---|---|
orders | repeated Order | List of order objects matching the request criteria |
Example
GetOpenPositionsRequest
Request object for retrieving open positions with filtering options.Fields
| Field | Type | Description |
|---|---|---|
owner | string | Filter positions by owner identifier |
market_id | int32 | Filter positions by market identifier (optional) |
side | Side | Filter positions by side (optional) |
Example
GetOpenPositionsResponse
Response object containing open positions.Fields
| Field | Type | Description |
|---|---|---|
positions | repeated Position | List of position objects matching the request criteria |
Example
Enums
OrderType
Defines the type of order being placed.| Value | Description |
|---|---|
ORDER_TYPE_MARKET | Market order - executes immediately at current market price |
Side
Defines the direction of the order.| Value | Description |
|---|---|
SIDE_LONG | Long position - betting price will go up |
SIDE_SHORT | Short position - betting price will go down |
OrderStatus
Defines the current status of an order.| Value | Description |
|---|---|
ORDER_STATUS_PENDING | Order has been submitted but not yet processed |
ORDER_STATUS_PARTIALLY_FILLED | Order has been partially executed |
ORDER_STATUS_FULLY_FILLED | Order has been completely executed |
ORDER_STATUS_CLOSED | Order has been closed |
ORDER_STATUS_CANCELLED | Order has been cancelled |
TimeInForce
Defines how long an order remains active.| Value | Description |
|---|---|
TIME_IN_FORCE_GTC | Good Till Cancelled - order remains active until filled or cancelled |
MarginType
Defines the type of margin used for a position.| Value | Description |
|---|---|
MARGIN_TYPE_CROSS | Cross margin - uses entire account balance as collateral |
MARGIN_TYPE_ISOLATED | Isolated margin - uses only allocated margin as collateral |
Working with Data Objects
Converting to Python Dictionaries
Use the utility functions to convert protobuf objects to Python dictionaries:Enum Conversions
The SDK provides utility enums that can convert from protobuf enum values:Formatting for Display
Use the formatting utilities for human-readable summaries:Type Safety
All data objects are fully typed for use with mypy and other type checkers:Best Practices
- Always validate data: Check that required fields are set before using order or position objects
- Use enums for comparisons: Compare against enum values rather than raw integers
- Handle partial fills: Check
filled_sizevssizefor partially filled orders - Monitor position health: Regularly check
liquidation_priceandunrealized_pnlfor risk management - Timestamp handling: Parse timestamps as needed for your timezone requirements
- Error handling: Always wrap API calls in try-catch blocks for robust error handling
- Margin management: Understand the difference between CROSS and ISOLATED margin types
- Batch operations: Use
get_orders()andget_open_positions()for efficient bulk data retrieval
Protobuf Details
The data objects are generated from protobuf definitions located in theproto/ submodule. When the protobuf definitions are updated:
- Run
git submodule update --remoteto get the latest definitions - Run
buf generateto regenerate the Python classes - Update any custom wrapper code if field names or types change
- Serialization to/from binary protobuf format
- JSON serialization support
- Field validation and type checking
- Default values for optional fields