Skip to content

Jupyter Notebook Examples

Interactive Jupyter notebooks for exploring the ProjectX Python SDK.

Available Notebooks

Getting Started

Trading Strategies

Technical Analysis

Risk Management

Market Microstructure

Running the Notebooks

Prerequisites

# Install Jupyter and dependencies
pip install jupyter notebook ipywidgets plotly pandas

# Install the SDK
pip install project-x-py[all]

Environment Setup

Create a .env file in the notebooks directory:

PROJECT_X_API_KEY=your-api-key
PROJECT_X_USERNAME=your-username

Launch Jupyter

# Clone the repository
git clone https://github.com/TexasCoding/project-x-py.git
cd project-x-py/notebooks

# Start Jupyter
jupyter notebook

Notebook Features

Interactive Visualizations

  • Real-time chart updates with Plotly
  • Interactive order book visualization
  • Candlestick charts with indicators
  • Performance dashboards

Live Data Integration

  • Connect to real-time WebSocket feeds
  • Stream market data into notebooks
  • Place and monitor orders interactively
  • Real-time position tracking

Educational Content

  • Step-by-step explanations
  • Code cells with detailed comments
  • Markdown cells with theory
  • Exercise cells for practice

Best Practices

Safety First

# Always use paper trading for testing
suite = await TradingSuite.create(
    ["MNQ"],
    mode="paper"  # Paper trading mode
)

Memory Management

# Clean up resources in notebooks
try:
    # Your trading code here
    pass
finally:
    await suite.disconnect()

Async in Notebooks

# Use nest_asyncio for async support
import nest_asyncio
nest_asyncio.apply()

# Now you can use await directly
suite = await TradingSuite.create(["MNQ"])

Contributing Notebooks

We welcome notebook contributions! Please ensure:

  1. Clear objectives - State what the notebook demonstrates
  2. Runnable code - Test with paper trading account
  3. Documentation - Explain concepts and code
  4. Visualizations - Use charts to illustrate points
  5. Safety warnings - Include risk disclaimers

Example Notebook Structure

# Cell 1: Setup
import asyncio
import nest_asyncio
from project_x_py import TradingSuite
import plotly.graph_objects as go
import pandas as pd

nest_asyncio.apply()

# Cell 2: Connect
suite = await TradingSuite.create(
    ["MNQ"],
    timeframes=["1min", "5min"],
    features=["orderbook"]
)

# Cell 3: Analysis
# Your strategy or analysis code

# Cell 4: Visualization
fig = go.Figure(data=[
    go.Candlestick(
        x=df['timestamp'],
        open=df['open'],
        high=df['high'],
        low=df['low'],
        close=df['close']
    )
])
fig.show()

# Cell 5: Cleanup
await suite.disconnect()

Resources

License

All notebooks are provided under the MIT License. Use at your own risk for educational purposes only.