Skip to content

Commit b35c278

Browse files
committed
update documentation
1 parent ecb7ec9 commit b35c278

File tree

6 files changed

+326
-6
lines changed

6 files changed

+326
-6
lines changed

docs/guide/trading-suite.md

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ The TradingSuite simplifies SDK usage by:
2222

2323
```python
2424
import asyncio
25+
2526
from project_x_py import TradingSuite
2627

28+
2729
async def main():
2830
# Traditional single instrument (still supported)
2931
suite = await TradingSuite.create(["MNQ"]) # List notation recommended
@@ -41,18 +43,24 @@ async def main():
4143
# Clean shutdown
4244
await suite.disconnect()
4345

46+
4447
asyncio.run(main())
4548
```
4649

4750
### Multi-Instrument Setup (v3.5.0 New)
4851

4952
```python
53+
import asyncio
54+
55+
from project_x_py import TradingSuite
56+
57+
5058
async def multi_instrument_main():
5159
# Revolutionary multi-instrument support
5260
suite = await TradingSuite.create(
5361
instruments=["MNQ", "ES", "MGC"], # Multiple futures
5462
timeframes=["1min", "5min"],
55-
features=["orderbook", "risk_manager"]
63+
features=["orderbook", "risk_manager"],
5664
)
5765

5866
print(f"Managing {len(suite)} instruments: {list(suite.keys())}")
@@ -69,18 +77,29 @@ async def multi_instrument_main():
6977

7078
await suite.disconnect()
7179

80+
7281
asyncio.run(multi_instrument_main())
7382
```
7483

7584
### Multi-Timeframe Setup
7685

7786
```python
87+
import asyncio
88+
89+
from project_x_py import TradingSuite
90+
91+
92+
async def main():
93+
await multi_timeframe_setup()
94+
await multi_instrument_timeframes()
95+
96+
7897
async def multi_timeframe_setup():
7998
# Setup with multiple timeframes for analysis
8099
suite = await TradingSuite.create(
81100
["MNQ"], # Single instrument with multiple timeframes
82101
timeframes=["1min", "5min", "15min"],
83-
initial_days=10 # Load 10 days of historical data
102+
initial_days=10, # Load 10 days of historical data
84103
)
85104

86105
mnq = suite["MNQ"]
@@ -90,40 +109,61 @@ async def multi_timeframe_setup():
90109
bars_5min = await mnq.data.get_data("5min")
91110
bars_15min = await mnq.data.get_data("15min")
92111

112+
if bars_1min is None or bars_5min is None or bars_15min is None:
113+
raise Exception("No data available")
114+
93115
print(f"MNQ 1min bars: {len(bars_1min)}")
94116
print(f"MNQ 5min bars: {len(bars_5min)}")
95117
print(f"MNQ 15min bars: {len(bars_15min)}")
96118

97119
await suite.disconnect()
98120

121+
99122
# Multi-instrument with multiple timeframes
100123
async def multi_instrument_timeframes():
101124
suite = await TradingSuite.create(
102125
["MNQ", "ES"], # List of instruments
103-
timeframes=["1min", "5min", "15min"]
126+
timeframes=["1min", "5min", "15min"],
104127
)
105128

106129
# Each instrument has all timeframes available
107130
for symbol, context in suite.items():
131+
bars_1min = await context.data.get_data("1min")
108132
bars_5min = await context.data.get_data("5min")
133+
bars_15min = await context.data.get_data("15min")
134+
135+
if bars_1min is None or bars_5min is None or bars_15min is None:
136+
raise Exception("No data available")
137+
print(f"{symbol} 1min bars: {len(bars_1min)}")
109138
print(f"{symbol} 5min bars: {len(bars_5min)}")
139+
print(f"{symbol} 15min bars: {len(bars_15min)}")
110140

111141
await suite.disconnect()
112142

113-
asyncio.run(multi_timeframe_setup())
143+
144+
asyncio.run(main())
114145
```
115146

116147
### Multi-Instrument with Optional Features
117148

118149
```python
150+
import asyncio
151+
152+
from project_x_py import TradingSuite
153+
from project_x_py.trading_suite import Features
154+
155+
119156
async def feature_setup():
120157
# Enable optional features for multiple instruments
121158
suite = await TradingSuite.create(
122-
["MNQ", "ES"], # List of instruments
159+
["MNQ", "MES"], # List of instruments
123160
timeframes=["1min", "5min"],
124-
features=["orderbook", "risk_manager"],
161+
features=[Features.ORDERBOOK, Features.RISK_MANAGER],
125162
)
126163

164+
# Wait for 120 seconds to ensure features are initialized
165+
await asyncio.sleep(20)
166+
127167
# Each instrument has its own feature instances
128168
total_exposure = 0.0
129169
for symbol, context in suite.items():
@@ -132,6 +172,8 @@ async def feature_setup():
132172
# Level 2 order book data (per instrument)
133173
if context.orderbook:
134174
snapshot = await context.orderbook.get_orderbook_snapshot()
175+
176+
print(snapshot)
135177
print(
136178
f" Order book depth: {len(snapshot['bids'])} bids, {len(snapshot['asks'])} asks"
137179
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
3+
from project_x_py import TradingSuite
4+
5+
6+
async def multi_instrument_main():
7+
# Revolutionary multi-instrument support
8+
suite = await TradingSuite.create(
9+
instruments=["MNQ", "ES", "MGC"], # Multiple futures
10+
timeframes=["1min", "5min"],
11+
features=["orderbook", "risk_manager"],
12+
)
13+
14+
print(f"Managing {len(suite)} instruments: {list(suite.keys())}")
15+
16+
# Dictionary-like access to each instrument
17+
mnq_context = suite["MNQ"]
18+
es_context = suite["ES"]
19+
mgc_context = suite["MGC"]
20+
21+
# Get prices for all instruments
22+
for symbol, context in suite.items():
23+
price = await context.data.get_current_price()
24+
print(f"{symbol}: ${price:.2f}")
25+
26+
await suite.disconnect()
27+
28+
29+
asyncio.run(multi_instrument_main())
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import asyncio
2+
3+
from project_x_py import TradingSuite
4+
from project_x_py.trading_suite import Features
5+
6+
7+
async def feature_setup():
8+
# Enable optional features for multiple instruments
9+
suite = await TradingSuite.create(
10+
["MNQ", "MES"], # List of instruments
11+
timeframes=["1min", "5min"],
12+
features=[Features.ORDERBOOK, Features.RISK_MANAGER],
13+
)
14+
15+
# Wait for 120 seconds to ensure features are initialized
16+
await asyncio.sleep(20)
17+
18+
# Each instrument has its own feature instances
19+
total_exposure = 0.0
20+
for symbol, context in suite.items():
21+
print(f"\n{symbol} Features:")
22+
23+
# Level 2 order book data (per instrument)
24+
if context.orderbook:
25+
snapshot = await context.orderbook.get_orderbook_snapshot()
26+
27+
print(snapshot)
28+
print(
29+
f" Order book depth: {len(snapshot['bids'])} bids, {len(snapshot['asks'])} asks"
30+
)
31+
32+
# Risk management tools (per instrument)
33+
if context.risk_manager:
34+
# Access risk configuration
35+
config = context.risk_manager.config
36+
print(f" Max position size: {config.max_position_size}")
37+
38+
# Get current risk metrics
39+
metrics = await context.risk_manager.get_risk_metrics()
40+
print(f" Current risk: ${metrics['current_risk']:,.2f}")
41+
print(f" Margin used: ${metrics['margin_used']:,.2f}")
42+
total_exposure += metrics["margin_used"]
43+
44+
# Portfolio-level risk summary
45+
print(f"\nTotal Portfolio Exposure: ${total_exposure:,.2f}")
46+
47+
await suite.disconnect()
48+
49+
50+
asyncio.run(feature_setup())
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import asyncio
2+
3+
from project_x_py import TradingSuite
4+
5+
6+
async def main():
7+
await multi_timeframe_setup()
8+
await multi_instrument_timeframes()
9+
10+
11+
async def multi_timeframe_setup():
12+
# Setup with multiple timeframes for analysis
13+
suite = await TradingSuite.create(
14+
["MNQ"], # Single instrument with multiple timeframes
15+
timeframes=["1min", "5min", "15min"],
16+
initial_days=10, # Load 10 days of historical data
17+
)
18+
19+
mnq = suite["MNQ"]
20+
21+
# Access different timeframe data
22+
bars_1min = await mnq.data.get_data("1min")
23+
bars_5min = await mnq.data.get_data("5min")
24+
bars_15min = await mnq.data.get_data("15min")
25+
26+
if bars_1min is None or bars_5min is None or bars_15min is None:
27+
raise Exception("No data available")
28+
29+
print(f"MNQ 1min bars: {len(bars_1min)}")
30+
print(f"MNQ 5min bars: {len(bars_5min)}")
31+
print(f"MNQ 15min bars: {len(bars_15min)}")
32+
33+
await suite.disconnect()
34+
35+
36+
# Multi-instrument with multiple timeframes
37+
async def multi_instrument_timeframes():
38+
suite = await TradingSuite.create(
39+
["MNQ", "ES"], # List of instruments
40+
timeframes=["1min", "5min", "15min"],
41+
)
42+
43+
# Each instrument has all timeframes available
44+
for symbol, context in suite.items():
45+
bars_1min = await context.data.get_data("1min")
46+
bars_5min = await context.data.get_data("5min")
47+
bars_15min = await context.data.get_data("15min")
48+
49+
if bars_1min is None or bars_5min is None or bars_15min is None:
50+
raise Exception("No data available")
51+
print(f"{symbol} 1min bars: {len(bars_1min)}")
52+
print(f"{symbol} 5min bars: {len(bars_5min)}")
53+
print(f"{symbol} 15min bars: {len(bars_15min)}")
54+
55+
await suite.disconnect()
56+
57+
58+
asyncio.run(main())
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import asyncio
2+
3+
from project_x_py import TradingSuite
4+
5+
6+
async def main():
7+
# Traditional single instrument (still supported)
8+
suite = await TradingSuite.create(["MNQ"]) # List notation recommended
9+
mnq = suite["MNQ"] # Access instrument context
10+
11+
# Everything is ready:
12+
# - Client authenticated
13+
# - Real-time data connected
14+
# - Order and position managers initialized
15+
16+
# Get current price
17+
price = await mnq.data.get_current_price()
18+
print(f"MNQ Current Price: ${price:.2f}")
19+
20+
# Clean shutdown
21+
await suite.disconnect()
22+
23+
24+
asyncio.run(main())

0 commit comments

Comments
 (0)