ClearML Integration

Purple Flea for ClearML

ClearML is the fully open-source MLOps platform. Combined with Purple Flea's financial APIs, you can track every trading model experiment, automate backtesting pipelines, and deploy models that execute live trades automatically.

Get Free API Key → View API Docs
100%
Open Source MLOps
6
Financial APIs
Auto
Pipeline Execution
Live
Trade Deployment

ClearML + Trading Workflow

Three steps from raw market data to production trading agent, tracked and versioned end-to-end.

1
Track Experiments with ClearML Task
Initialize a ClearML Task at the start of every training or backtest run. Log hyperparameters (lookback window, leverage, entry threshold), scalar metrics (Sharpe ratio, max drawdown, win rate), and model artifacts automatically. Every run is versioned, comparable, and reproducible — no more lost experiments in stray notebooks.
2
Build Automated Backtesting Pipelines
Use ClearML Pipelines to chain DataFetch → Preprocess → Backtest → Evaluate steps. Each step pulls market data from Purple Flea's historical API, runs your strategy logic, and logs results. Pipelines are triggered on schedule or on-demand, giving you a continuous model improvement loop without manual intervention.
3
Deploy Best Model to Production with Live Trade Execution
When a model exceeds your performance threshold in backtesting, ClearML's model promotion step triggers automatic deployment. The champion model connects to Purple Flea's trading API and begins executing real positions. ClearML monitors live performance metrics and can roll back to previous versions if live Sharpe drops below target.

Experiment Tracking Example

Instrument your trading strategy with ClearML in under 20 lines. Every run is logged automatically to the ClearML web UI.

from clearml import Task import requests # Initialize ClearML task — appears in ClearML web UI under the project task = Task.init(project_name="Purple Flea Trading", task_name="BTC Momentum v4") # Log hyperparameters — tracked and diffable across runs task.connect({"lookback": 14, "threshold": 0.02, "leverage": 2}) HEADERS = {"Authorization": "Bearer YOUR_PURPLEFLEA_API_KEY"} PF_BASE = "https://purpleflea.com/api" # Fetch historical data from Purple Flea history = requests.get( f"{PF_BASE}/v1/markets/BTC-PERP/history", params={"days": 90}, headers=HEADERS ).json() # ... train/backtest your model on history ... # sharpe, max_dd computed from backtest results sharpe = 1.87 max_dd = -0.12 # Log scalar metrics — visible in ClearML dashboard logger = task.get_logger() logger.report_scalar("Sharpe", "train", iteration=0, value=sharpe) logger.report_scalar("Max Drawdown", "train", iteration=0, value=max_dd) # Upload model artifact for later retrieval and deployment # task.upload_artifact("model", model) # If Sharpe exceeds threshold, tag for production promotion if sharpe > 1.5: task.add_tags(["production-candidate"]) print(f"Model qualifies for live deployment: Sharpe={sharpe}") task.close()

ClearML Pipeline for Live Trading

Fully automated pipeline from data ingestion to live trade execution. Each stage is independently versioned, logged, and can be rolled back independently.

DataFetch
Preprocess
Backtest
EvaluateModel
DeployToProduction
ExecuteTrades
DataFetch Stage
Calls Purple Flea's market history endpoint to pull OHLCV data for the configured lookback period. Output is versioned as a ClearML dataset artifact — identical data is reused across runs for reproducibility.
Backtest Stage
Applies the strategy to historical data using a walk-forward method. Outputs Sharpe, drawdown, win rate, and P&L curve. All metrics logged automatically to ClearML scalars for comparison.
EvaluateModel Stage
Compares current model metrics against the baseline champion. If the new model wins on Sharpe + drawdown, it's tagged as the new production candidate. Otherwise it's archived and the pipeline terminates without deploying.
ExecuteTrades Stage
The deployed model runs as a continuous loop, calling Purple Flea's trading API for position management. ClearML's monitoring hooks log trade count and live P&L back to the experiment dashboard for ongoing visibility.
from clearml.automation import PipelineController pipe = PipelineController( project="Purple Flea Trading", name="BTC Momentum Pipeline", add_pipeline_tags=True ) pipe.add_step(name="DataFetch", base_task_project="Purple Flea Trading", base_task_name="fetch_market_data") pipe.add_step(name="Backtest", parents=["DataFetch"], base_task_project="Purple Flea Trading", base_task_name="run_backtest") pipe.add_step(name="EvaluateModel", parents=["Backtest"], base_task_project="Purple Flea Trading", base_task_name="evaluate_and_promote") pipe.add_step(name="ExecuteTrades", parents=["EvaluateModel"], base_task_project="Purple Flea Trading", base_task_name="live_trading_loop") pipe.set_default_execution_queue("default") pipe.start()

Available APIs

Six financial APIs your ClearML pipelines can call for data, execution, and payments.

📈
Open, close, and manage perpetual futures positions. Funding rate data, OHLCV history, and mark price streams for backtesting and live execution.
🎰
Provably fair games (crash, coin flip, dice) with statistically trackable outcomes. Ideal for testing agent decision-making under risk.
👛
Multi-chain wallet management: generate addresses, check balances, and send transactions across BTC, ETH, SOL, XMR, and TRON.
🤝
Trustless agent-to-agent payments. Lock funds in escrow, define conditions, and release automatically. 1% fee, 15% referral commission.
🪙
Access Aave and Compound lending markets. Deposit collateral, borrow USDC, and monitor liquidation risk from pipeline steps.
🚰
New agents get free credits to test the casino and trading APIs without depositing real funds. Zero-risk first experiments.

Use Cases

What teams build when they connect ClearML's MLOps stack to Purple Flea's live financial infrastructure.

🏆
Automated Strategy Tournament
Run dozens of strategy variants in parallel using ClearML's HPO controller. Strategies compete on real market data pulled from Purple Flea. The winner is auto-promoted to live trading.
📊
Model Monitoring Dashboard
Log live trade metrics (P&L, win rate, drawdown) back to ClearML in real time. Set alerts when live Sharpe drops below the backtest benchmark. Trigger automatic retraining when drift is detected.
🗄️
Market Data Versioning
Store Purple Flea OHLCV snapshots as ClearML Dataset artifacts. Every backtest run references an exact, versioned data snapshot — eliminating look-ahead bias and ensuring reproducible results.
🚀
Production Model Promotion
Gate production deployment behind a quantitative threshold: only models with Sharpe > 1.5 and max drawdown < 15% are promoted. ClearML's pipeline conditions enforce this automatically without human sign-off.

Internal Links

Explore the full Purple Flea API suite and MLOps integrations.

Start Tracking Trading Experiments

Connect ClearML to Purple Flea in minutes. Track every backtest, automate deployment, and let your best model trade live.