Skip to content

Commit 80adcef

Browse files
feat: enhance async order management system with detailed descriptions and examples across documentation.
Co-authored-by: Genie <[email protected]>
1 parent 4bbf104 commit 80adcef

File tree

7 files changed

+194
-17
lines changed

7 files changed

+194
-17
lines changed

src/project_x_py/order_manager/__init__.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
"""
2-
Order Manager Module for ProjectX Trading Platform.
3-
4-
This module provides comprehensive order management functionality including:
5-
- Order placement (market, limit, stop, trailing stop)
6-
- Order modification and cancellation
7-
- Bracket order strategies
8-
- Position-based order management
9-
- Real-time order tracking and monitoring
2+
Async order management for ProjectX trading.
3+
4+
Overview:
5+
This package provides the async OrderManager system for ProjectX, offering robust,
6+
extensible order placement, modification, cancellation, tracking, and advanced
7+
bracket/position management. Integrates with both API and real-time clients for
8+
seamless trading workflows.
9+
10+
Key Features:
11+
- Unified async order placement (market, limit, stop, trailing, bracket)
12+
- Modification/cancellation with tick-size alignment
13+
- Position-based order and risk management
14+
- Real-time tracking, event-driven callbacks, and statistics
15+
- Modular design for strategy and bot development
16+
17+
Example Usage:
18+
```python
19+
from project_x_py import ProjectX
20+
from project_x_py.order_manager import OrderManager
21+
22+
async with ProjectX.from_env() as client:
23+
om = OrderManager(client)
24+
await om.place_market_order("MNQ", 0, 1) # Buy 1 contract at market
25+
```
26+
27+
See Also:
28+
- `order_manager.core.OrderManager`
29+
- `order_manager.bracket_orders`
30+
- `order_manager.order_types`
31+
- `order_manager.position_orders`
32+
- `order_manager.tracking`
33+
- `order_manager.utils`
1034
"""
1135

1236
from project_x_py.order_manager.core import OrderManager

src/project_x_py/order_manager/bracket_orders.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
"""Bracket order functionality for complex order strategies."""
1+
"""
2+
Async bracket order strategies for ProjectX.
3+
4+
Overview:
5+
Provides mixin logic for placing and managing bracket orders—sophisticated, three-legged
6+
order strategies consisting of entry, stop loss, and take profit orders. Ensures risk
7+
controls are established atomically and linked to positions for robust trade automation.
8+
9+
Key Features:
10+
- Place async bracket orders (entry, stop, target) as a single operation
11+
- Price/side validation and position link management
12+
- Automatic risk management: stops and targets managed with entry
13+
- Integrates with core OrderManager and position tracking
14+
15+
Example Usage:
16+
```python
17+
# Assuming om is an instance of OrderManager
18+
await om.place_bracket_order(
19+
contract_id="MGC", side=0, size=1,
20+
entry_price=2050.0, stop_loss_price=2040.0, take_profit_price=2070.0
21+
)
22+
```
23+
24+
See Also:
25+
- `order_manager.core.OrderManager`
26+
- `order_manager.position_orders`
27+
- `order_manager.order_types`
28+
"""
229

330
import logging
431
from typing import TYPE_CHECKING

src/project_x_py/order_manager/core.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
"""
2-
Core OrderManager class for comprehensive order operations.
3-
4-
This module provides the main OrderManager class that handles all order-related
5-
operations including placement, modification, cancellation, and tracking.
2+
Async OrderManager core for ProjectX trading.
3+
4+
Overview:
5+
Contains the main OrderManager class, orchestrating all async order operations
6+
(placement, modification, cancellation, tracking) and integrating mixins for
7+
bracket, position, and order type strategies. Provides thread-safe, eventful,
8+
and real-time capable order workflows for automated and manual trading.
9+
10+
Key Features:
11+
- Unified async API for order lifecycle (market, limit, stop, trailing, OCO)
12+
- Bracket and position-based order strategies
13+
- Real-time tracking, event-driven callbacks, and statistics
14+
- Price alignment, concurrent safety, and health metrics
15+
- Extensible for custom bots and strategy engines
16+
17+
Example Usage:
18+
```python
19+
from project_x_py import ProjectX
20+
from project_x_py.order_manager import OrderManager
21+
22+
async with ProjectX.from_env() as client:
23+
om = OrderManager(client)
24+
await om.place_limit_order("ES", 0, 1, 5000.0)
25+
```
26+
27+
See Also:
28+
- `order_manager.bracket_orders`
29+
- `order_manager.position_orders`
30+
- `order_manager.order_types`
31+
- `order_manager.tracking`
632
"""
733

834
import asyncio

src/project_x_py/order_manager/order_types.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
"""Order placement methods for different order types."""
1+
"""
2+
Async order type placement mixin for ProjectX.
3+
4+
Overview:
5+
Implements mixin methods for placing specific order types (market, limit,
6+
stop, trailing stop) in the async OrderManager system. Encapsulates order-type
7+
validation, parameter handling, and delegates to the unified underlying API.
8+
9+
Key Features:
10+
- Async placement of market, limit, stop, and trailing stop orders
11+
- Standardized argument validation and contract handling
12+
- Integrates with bracket and position order mixins
13+
- Returns model-typed responses for downstream logic
14+
15+
Example Usage:
16+
```python
17+
# Assuming om is an instance of OrderManager
18+
await om.place_limit_order("MES", 1, 2, 5000.0)
19+
await om.place_market_order("MGC", 0, 1)
20+
```
21+
22+
See Also:
23+
- `order_manager.core.OrderManager`
24+
- `order_manager.bracket_orders`
25+
- `order_manager.position_orders`
26+
"""
227

328
import logging
429
from typing import TYPE_CHECKING

src/project_x_py/order_manager/position_orders.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
"""Position-related order management functionality."""
1+
"""
2+
Async position-based order management for ProjectX.
3+
4+
Overview:
5+
Provides mixin logic for managing orders at the position level: closing open positions,
6+
adding stop losses/take profits, and synchronizing/canceling related orders as position
7+
size changes. Enables robust, risk-aware trading automations.
8+
9+
Key Features:
10+
- Async close, stop loss, and take profit for open positions
11+
- Automatic order/position tracking and synchronization
12+
- Bulk cancellation and modification of position-related orders
13+
- Integrates with order callbacks and bracket strategies
14+
15+
Example Usage:
16+
```python
17+
# Assuming om is an instance of OrderManager
18+
await om.close_position("MNQ")
19+
await om.add_stop_loss("MNQ", stop_price=2030.0)
20+
```
21+
22+
See Also:
23+
- `order_manager.core.OrderManager`
24+
- `order_manager.bracket_orders`
25+
- `order_manager.order_types`
26+
"""
227

328
import logging
429
from typing import TYPE_CHECKING, Any

src/project_x_py/order_manager/tracking.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
"""Order tracking and real-time monitoring functionality."""
1+
"""
2+
Async order tracking and real-time monitoring for ProjectX.
3+
4+
Overview:
5+
Implements mixin logic for tracking order status, maintaining local state and cache,
6+
and handling real-time updates from websocket events. Supports callback registration
7+
for fills/cancels, cache queries, and system health validation.
8+
9+
Key Features:
10+
- Real-time tracking via websocket/callbacks and local cache
11+
- Order-to-position relationship mapping
12+
- Async event/callback system for fills, cancels, rejections
13+
- Cache clearing, health/status reporting, and metrics
14+
- Integrates with OrderManager main class
15+
16+
Example Usage:
17+
```python
18+
# Assuming om is an instance of OrderManager
19+
await om.initialize(realtime_client)
20+
tracked = await om.get_tracked_order_status("12345")
21+
```
22+
23+
See Also:
24+
- `order_manager.core.OrderManager`
25+
- `order_manager.position_orders`
26+
- `order_manager.utils`
27+
"""
228

329
import asyncio
430
import logging

src/project_x_py/order_manager/utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
"""Utility functions for order management."""
1+
"""
2+
Order management utility functions for ProjectX.
3+
4+
Overview:
5+
Provides async/sync helpers for price alignment to instrument tick size, contract
6+
resolution, and other utility operations used throughout the async OrderManager system.
7+
8+
Key Features:
9+
- Aligns prices to valid instrument tick size (async and sync)
10+
- Resolves contract IDs to instrument metadata
11+
- Precision rounding and validation helpers
12+
13+
Example Usage:
14+
```python
15+
# Aligning a price to tick size
16+
aligned = align_price_to_tick(2052.17, 0.25)
17+
# Resolving contract ID
18+
details = await resolve_contract_id("MNQ", project_x_client)
19+
```
20+
21+
See Also:
22+
- `order_manager.core.OrderManager`
23+
- `order_manager.tracking`
24+
- `order_manager.position_orders`
25+
"""
226

327
import logging
428
from decimal import ROUND_HALF_UP, Decimal

0 commit comments

Comments
 (0)