Retrieve a single order by ID and return it as a JSON object.
The unique order identifier
Whether this is a reduce-only order
Dictionary containing order data if found, None otherwise
Raises
- ValueError — If API_SERVER_URL environment variable is not set
Example
>>> import os
>>> os.environ["API_SERVER_URL"] = "http://localhost:8080"
>>> order = await getOrder(order_id=123, market_id=1)
>>> print(order["orderId"])
123
async def getOrder(order_id: int, market_id: Union[str, int], reduce_only: bool=False) -> Optional[Dict[str, Any]]:
base_url = os.getenv('API_SERVER_URL')
if not base_url:
raise ValueError('API_SERVER_URL environment variable not set')
async with httpx.AsyncClient() as session:
client = PerpetualsClient(base_url=base_url, session=session)
try:
order = await client.get_order(order_id, market_id, reduce_only)
if order:
order_dict = MessageToDict(order, always_print_fields_with_no_presence=True)
return order_dict
return None
except Exception as e:
print(f'Error getting order: {e}')
print('\nTroubleshooting:')
print(' - Is the server running?')
print(' - Is this a valid order ID in the database?')
print(' - Is the market ID correct?')
return None