> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fairground.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# getOrder

> Python SDK reference for getOrder.

Retrieve a single order by ID and return it as a JSON object.

<ParamField path="order_id" type="int" required>
  The unique order identifier
</ParamField>

<ParamField path="market_id" type="object" required>
  The market identifier
</ParamField>

<ParamField path="reduce_only" type="bool">
  Whether this is a reduce-only order
</ParamField>

<ResponseField name="returns" type="object" required>
  Dictionary containing order data if found, None otherwise
</ResponseField>

**Raises**

* **ValueError** — If API\_SERVER\_URL environment variable is not set

**Example**

```python theme={null}
>>> import os
>>> os.environ["API_SERVER_URL"] = "http://localhost:8080"
>>> order = await getOrder(order_id=123, market_id=1)
>>> print(order["orderId"])
123
```

```python theme={null}
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
```
