Skip to content

Commit 9b08612

Browse files
committed
update documentation
1 parent d8cf962 commit 9b08612

21 files changed

+3790
-905
lines changed

docs/api/indicators.rst

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,29 @@ Quick Start
2121

2222
.. code-block:: python
2323
24+
import asyncio
2425
from project_x_py.indicators import RSI, SMA, MACD, BBANDS
2526
from project_x_py import ProjectX
2627
27-
# Get market data
28-
client = ProjectX.from_env()
29-
data = client.get_data('MGC', days=30, interval=60)
30-
31-
# Class-based interface
32-
rsi = RSI()
33-
data_with_rsi = rsi.calculate(data, period=14)
28+
async def analyze_market():
29+
# Get market data
30+
async with ProjectX.from_env() as client:
31+
await client.authenticate()
32+
data = await client.get_bars('MGC', days=30, interval=60)
33+
34+
# Class-based interface
35+
rsi = RSI()
36+
data_with_rsi = rsi.calculate(data, period=14)
37+
38+
# TA-Lib style functions (direct usage)
39+
data = RSI(data, period=14) # Add RSI
40+
data = SMA(data, period=20) # Add 20-period SMA
41+
data = BBANDS(data, period=20) # Add Bollinger Bands
42+
43+
return data
3444
35-
# TA-Lib style functions (direct usage)
36-
data = RSI(data, period=14) # Add RSI
37-
data = SMA(data, period=20) # Add 20-period SMA
38-
data = BBANDS(data, period=20) # Add Bollinger Bands
45+
# Run the analysis
46+
data = asyncio.run(analyze_market())
3947
4048
Base Classes
4149
------------
@@ -249,21 +257,28 @@ Basic Usage
249257

250258
.. code-block:: python
251259
260+
import asyncio
252261
from project_x_py.indicators import RSI, SMA, MACD
262+
from project_x_py import ProjectX
253263
254-
# Load your data (Polars DataFrame with OHLCV columns)
255-
data = client.get_data('MGC', days=30, interval=60)
256-
257-
# Add indicators using TA-Lib style functions
258-
data = RSI(data, period=14)
259-
data = SMA(data, period=20)
260-
data = SMA(data, period=50)
261-
data = MACD(data, fast_period=12, slow_period=26, signal_period=9)
264+
async def basic_analysis():
265+
# Load your data (Polars DataFrame with OHLCV columns)
266+
async with ProjectX.from_env() as client:
267+
await client.authenticate()
268+
data = await client.get_bars('MGC', days=30, interval=60)
269+
270+
# Add indicators using TA-Lib style functions
271+
data = RSI(data, period=14)
272+
data = SMA(data, period=20)
273+
data = SMA(data, period=50)
274+
data = MACD(data, fast_period=12, slow_period=26, signal_period=9)
275+
276+
# Check latest values
277+
latest = data.tail(1)
278+
print(f"RSI: {latest['rsi_14'].item():.2f}")
279+
print(f"SMA(20): ${latest['sma_20'].item():.2f}")
262280
263-
# Check latest values
264-
latest = data.tail(1)
265-
print(f"RSI: {latest['rsi_14'].item():.2f}")
266-
print(f"SMA(20): ${latest['sma_20'].item():.2f}")
281+
asyncio.run(basic_analysis())
267282
268283
Class-Based Interface
269284
~~~~~~~~~~~~~~~~~~~~~
@@ -287,31 +302,44 @@ Multi-Indicator Strategy
287302

288303
.. code-block:: python
289304
305+
import asyncio
290306
import polars as pl
291307
from project_x_py.indicators import *
308+
from project_x_py import ProjectX
292309
293-
# Comprehensive technical analysis
294-
analysis = (
295-
data
296-
# Trend indicators
297-
.pipe(SMA, period=20)
298-
.pipe(SMA, period=50)
299-
.pipe(EMA, period=21)
300-
.pipe(BBANDS, period=20, std_dev=2.0)
310+
async def multi_indicator_analysis():
311+
# Get data
312+
async with ProjectX.from_env() as client:
313+
await client.authenticate()
314+
data = await client.get_bars('MGC', days=60, interval=60)
301315
302-
# Momentum indicators
303-
.pipe(RSI, period=14)
304-
.pipe(MACD, fast_period=12, slow_period=26, signal_period=9)
305-
.pipe(STOCH, k_period=14, d_period=3)
316+
# Comprehensive technical analysis
317+
analysis = (
318+
data
319+
# Trend indicators
320+
.pipe(SMA, period=20)
321+
.pipe(SMA, period=50)
322+
.pipe(EMA, period=21)
323+
.pipe(BBANDS, period=20, std_dev=2.0)
324+
325+
# Momentum indicators
326+
.pipe(RSI, period=14)
327+
.pipe(MACD, fast_period=12, slow_period=26, signal_period=9)
328+
.pipe(STOCH, k_period=14, d_period=3)
329+
330+
# Volatility indicators
331+
.pipe(ATR, period=14)
332+
.pipe(ADX, period=14)
333+
334+
# Volume indicators
335+
.pipe(OBV)
336+
.pipe(VWAP, period=20)
337+
)
306338
307-
# Volatility indicators
308-
.pipe(ATR, period=14)
309-
.pipe(ADX, period=14)
310-
311-
# Volume indicators
312-
.pipe(OBV)
313-
.pipe(VWAP, period=20)
314-
)
339+
return analysis
340+
341+
# Run the strategy
342+
result = asyncio.run(multi_indicator_analysis())
315343
316344
Indicator Discovery
317345
~~~~~~~~~~~~~~~~~~~
@@ -359,21 +387,30 @@ Performance Tips
359387
2. **Chain operations**: Use ``.pipe()`` for efficient chaining
360388
3. **Reuse instances**: Create indicator instances once and reuse them
361389
4. **Batch calculations**: Calculate multiple indicators in one pass when possible
390+
5. **Async data fetching**: Fetch data once and apply all indicators
362391

363392
.. code-block:: python
364393
365-
# Efficient: Chain multiple indicators
366-
data = (
367-
data
368-
.pipe(RSI, period=14)
369-
.pipe(SMA, period=20)
370-
.pipe(MACD)
371-
)
372-
373-
# Less efficient: Separate calculations
374-
data = RSI(data, period=14)
375-
data = SMA(data, period=20)
376-
data = MACD(data)
394+
async def efficient_analysis():
395+
# Fetch data once
396+
async with ProjectX.from_env() as client:
397+
await client.authenticate()
398+
data = await client.get_bars('MGC', days=30)
399+
400+
# Efficient: Chain multiple indicators
401+
data = (
402+
data
403+
.pipe(RSI, period=14)
404+
.pipe(SMA, period=20)
405+
.pipe(MACD)
406+
)
407+
408+
# Less efficient: Separate calculations
409+
# data = RSI(data, period=14)
410+
# data = SMA(data, period=20)
411+
# data = MACD(data)
412+
413+
return data
377414
378415
TA-Lib Compatibility
379416
--------------------

0 commit comments

Comments
 (0)