@@ -128,37 +128,117 @@ if __name__ == "__main__":
128128 asyncio.run(main())
129129```
130130
131- ### Real-time Trading Suite
131+ ### Trading Suite (NEW in v2.0.8)
132+
133+ The easiest way to get started with a complete trading setup:
132134
133135``` python
134136import asyncio
135- from project_x_py import ProjectX, create_trading_suite
136-
137- async def on_tick (tick_data ):
138- print (f " Price: $ { tick_data[' price' ]} " )
137+ from project_x_py import ProjectX, create_initialized_trading_suite
139138
140139async def main ():
141140 async with ProjectX.from_env() as client:
142141 await client.authenticate()
143142
144- # Create complete trading suite
145- suite = await create_trading_suite (
143+ # One line creates and initializes everything!
144+ suite = await create_initialized_trading_suite (
146145 instrument = " MNQ" ,
147146 project_x = client,
148- timeframes = [" 1min" , " 5min" , " 15min" ]
147+ timeframes = [" 5min" , " 15min" , " 1hr" ],
148+ initial_days = 5
149149 )
150150
151- # Connect real-time services
152- await suite[" realtime_client" ].connect()
153- await suite[" data_manager" ].initialize(initial_days = 5 )
151+ # Everything is ready to use:
152+ # ✅ Realtime client connected
153+ # ✅ Historical data loaded
154+ # ✅ Market data streaming
155+ # ✅ All components initialized
154156
155- # Subscribe to real-time data
157+ # Access components
158+ data = await suite[" data_manager" ].get_data(" 5min" )
159+ orderbook = suite[" orderbook" ]
160+ order_manager = suite[" order_manager" ]
161+ position_manager = suite[" position_manager" ]
162+
163+ # Your trading logic here...
164+
165+ if __name__ == " __main__" :
166+ asyncio.run(main())
167+ ```
168+
169+ ### Factory Functions (v2.0.8+)
170+
171+ The SDK provides powerful factory functions to simplify setup:
172+
173+ #### create_initialized_trading_suite
174+ The simplest way to get a fully initialized trading environment:
175+
176+ ``` python
177+ suite = await create_initialized_trading_suite(
178+ instrument = " MNQ" ,
179+ project_x = client,
180+ timeframes = [" 5min" , " 15min" , " 1hr" ], # Optional, defaults to ["5min"]
181+ enable_orderbook = True , # Optional, defaults to True
182+ initial_days = 5 # Optional, defaults to 5
183+ )
184+ # Everything is connected and ready!
185+ ```
186+
187+ #### create_trading_suite
188+ For more control over initialization:
189+
190+ ``` python
191+ suite = await create_trading_suite(
192+ instrument = " MNQ" ,
193+ project_x = client,
194+ timeframes = [" 5min" , " 15min" ],
195+ auto_connect = True , # Auto-connect realtime client (default: True)
196+ auto_subscribe = True , # Auto-subscribe to market data (default: True)
197+ initial_days = 5 # Historical data to load
198+ )
199+ ```
200+
201+ #### Manual Setup (Full Control)
202+ If you need complete control:
203+
204+ ``` python
205+ suite = await create_trading_suite(
206+ instrument = " MNQ" ,
207+ project_x = client,
208+ auto_connect = False ,
209+ auto_subscribe = False
210+ )
211+ # Now manually connect and subscribe as needed
212+ await suite[" realtime_client" ].connect()
213+ await suite[" data_manager" ].initialize()
214+ # ... etc
215+ ```
216+
217+ ### Real-time Trading Example
218+
219+ ``` python
220+ import asyncio
221+ from project_x_py import ProjectX, create_initialized_trading_suite
222+
223+ async def on_tick (tick_data ):
224+ print (f " Price: $ { tick_data[' price' ]} " )
225+
226+ async def main ():
227+ async with ProjectX.from_env() as client:
228+ await client.authenticate()
229+
230+ # Create fully initialized trading suite
231+ suite = await create_initialized_trading_suite(" MNQ" , client)
232+
233+ # Add callbacks
156234 suite[" data_manager" ].add_tick_callback(on_tick)
157- await suite[" data_manager" ].start_realtime_feed()
235+
236+ # Get current price
237+ current_price = await suite[" data_manager" ].get_current_price()
158238
159239 # Place a bracket order
160240 response = await suite[" order_manager" ].place_bracket_order(
161- contract_id = instrument .id,
241+ contract_id = suite[ " instrument_info " ] .id,
162242 side = 0 , # Buy
163243 size = 1 ,
164244 entry_price = current_price,
@@ -284,6 +364,8 @@ The `examples/` directory contains comprehensive async examples:
2843647 . ** 07_technical_indicators.py** - Using indicators with async data
2853658 . ** 08_order_and_position_tracking.py** - Integrated async monitoring
2863669 . ** 09_get_check_available_instruments.py** - Interactive async instrument search
367+ 10 . ** 12_simplified_strategy.py** - NEW: Simplified strategy using auto-initialization
368+ 11 . ** 13_factory_comparison.py** - NEW: Comparison of factory function approaches
287369
288370## 🔧 Configuration
289371
@@ -366,6 +448,56 @@ async def place_order(self, ...):
366448 # Method implementation
367449```
368450
451+ ## 🔧 Troubleshooting
452+
453+ ### Common Issues with Factory Functions
454+
455+ #### JWT Token Not Available
456+ ``` python
457+ # Error: "JWT token is required but not available from client"
458+ # Solution: Ensure client is authenticated before creating suite
459+ async with ProjectX.from_env() as client:
460+ await client.authenticate() # Don't forget this!
461+ suite = await create_initialized_trading_suite(" MNQ" , client)
462+ ```
463+
464+ #### Instrument Not Found
465+ ``` python
466+ # Error: "Instrument MNQ not found"
467+ # Solution: Verify instrument symbol is correct
468+ # Common symbols: "MNQ", "MES", "MGC", "ES", "NQ"
469+ ```
470+
471+ #### Connection Timeouts
472+ ``` python
473+ # If initialization times out, try manual setup with error handling:
474+ try :
475+ suite = await create_trading_suite(
476+ instrument = " MNQ" ,
477+ project_x = client,
478+ auto_connect = False
479+ )
480+ await suite[" realtime_client" ].connect()
481+ except Exception as e:
482+ print (f " Connection failed: { e} " )
483+ ```
484+
485+ #### Memory Issues with Long-Running Strategies
486+ ``` python
487+ # The suite automatically manages memory, but for long-running strategies:
488+ # 1. Use reasonable initial_days (3-7 is usually sufficient)
489+ # 2. The data manager automatically maintains sliding windows
490+ # 3. OrderBook has built-in memory limits
491+ ```
492+
493+ #### Rate Limiting
494+ ``` python
495+ # The SDK handles rate limiting automatically, but if you encounter issues:
496+ # 1. Reduce concurrent API calls
497+ # 2. Add delays between operations
498+ # 3. Use batch operations where available
499+ ```
500+
369501## 🤝 Contributing
370502
371503We welcome contributions! Please see [ CONTRIBUTING.md] ( CONTRIBUTING.md ) for guidelines.
0 commit comments