mcpField
A
algo-expert

algo-expert

github.com/marketcallsOther942 installsUpdated 26w ago
Repository

About algo-expert

A knowledge base for building production-grade algorithmic trading strategies on OpenAlgo, covering both backtesting and live execution. It focuses on practical guidance for risk, costs, data, and orders, including deployment to OpenAlgo’s self-hosted strategy host.

Key features

  1. 01Single-file backtest and live modes
  2. 02VectorBT backtesting and cost modeling
  3. 03OpenAlgo SDK and WebSocket execution
  4. 04Position and portfolio risk guidance
  5. 05Self-hosted strategy deployment patterns

Use cases

  1. 01Design strategies for backtests and live trading
  2. 02Include trading costs and slippage in backtests
  3. 03Plan order execution and risk controls
  4. 04Prepare deployment to OpenAlgo /python

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/marketcalls/openalgo-execution-skills --skill algo-expert

After installing, type/algo-expertin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

rules/
duckdb-data.md
event-loop.md
execution-patterns.md
execution-types.md
rules/assets/atr_breakout/
strategy.py
rules/assets/bb_squeeze/
strategy.py
rules/assets/core/
cost_model.py
data_router.py
indicator_adapter.py
portfolio_runner.py
preflight.py
risk_manager.py
sizing.py
state.py
strategy_loader.py
rules/assets/donchian/
strategy.py
rules/assets/ema_crossover/
strategy.py
rules/assets/event_driven/
strategy.py
rules/assets/iron_condor/
strategy.py
rules/assets/macd/
strategy.py
rules/assets/ml_logistic/
strategy.py
train.py
rules/assets/ml_xgb/
strategy.py
train.py
rules/assets/opening_range/
strategy.py
rules/assets/pairs_trading/
strategy.py
rules/assets/regime_trend/
strategy.py
rules/assets/rsi/
strategy.py
rules/assets/short_straddle/
strategy.py
rules/assets/supertrend/
strategy.py

Details

From the project README

OpenAlgo Execution Expert

Knowledge base for building production-grade algorithmic trading strategies on OpenAlgo. Every strategy is a single Python file that toggles between backtest mode (VectorBT) and live execution mode (OpenAlgo SDK + WebSocket) via one CLI flag (--mode backtest|live) or env var (MODE=...).

Strategies are also upload-ready for OpenAlgo's self-hosted /python strategy host.

Core principles

  1. One file, two modes. The same signals(df) function feeds both VectorBT (backtest) and the live event loop. Risk thresholds and cost assumptions are honored on both sides.
  2. OpenAlgo for everything broker-side. Data via client.history() and WebSocket. Orders via client.placeorder() / placesmartorder() / optionsmultiorder(). Live vs sandbox is decided in OpenAlgo's UI analyzer toggle - the strategy code never knows.
  3. Indicator library is user's choice - openalgo.ta (default) or talib. Specialty indicators (Supertrend, Donchian, Ichimoku, HMA, KAMA) always come from openalgo. See rules/indicator-libraries.md.
  4. Three execution types - eoc (end-of-candle MARKET), limit (real-time pegged LIMIT), stop (broker-side SL-M trigger). User picks at strategy creation. See rules/execution-types.md.
  5. Real-world costs and slippage baked into every backtest (matches vectorbt-backtesting-skills 4-segment Indian model). See rules/transaction-costs.md and rules/slippage-handling.md.
  6. Self-hosted /python compatible - every strategy reads env vars in the canonical priority, traps SIGTERM, logs to stdout. See rules/self-hosted-strategies.md.

When to read which rule

Reading the user wants...Load these rule files
The big-picture strategy templateunified-strategy-pattern.md, mode-toggle.md, execution-types.md
Indicator selectionindicator-libraries.md
Position sizing (the most important fix)position-sizing.md
Preflight checks at startuppreflight-checks.md
Risk on a single positionrisk-management.md
Portfolio-level risk and daily capsportfolio-risk.md
Cost / slippage modelingtransaction-costs.md, slippage-handling.md
Data sources (DuckDB, Historify, API)duckdb-data.md
WebSocket and bar-close patternswebsocket-feeds.md, event-loop.md
Order placement idiomsexecution-patterns.md, order-constants.md
Options strategiesoptions-execution.md
Volatility strategiesvolatility-strategies.md
ML strategiesml-strategies.md
Persistent state between restartsstate-persistence.md
Logging and Telegram alertslogging-and-alerts.md
Common production mistakespitfalls.md
Strategy catalog / template selectionstrategy-catalog.md
OpenAlgo /python self-hostingself-hosted-strategies.md
Symbol formats and lot sizessymbol-format.md, lot-sizes.md, order-constants.md
Full SDK referencesdk-reference.md

Production patterns (lifted from OpenAlgo examples)

  • Two-thread live model: signal poll thread + WS callback thread (from examples/python/emacrossover_strategy_python.py). The WS callback NEVER places orders directly - it spawns a worker thread.
  • Bar-close logic uses iloc[-2] not iloc[-1] - the last bar in client.history() is forming and would cause repaint.
  • Risk exits use client.placesmartorder(position_size=0) to flatten cleanly (from examples/python/stoploss_target_example.py).
  • Multi-leg options entry via client.optionsmultiorder() - BUY legs go first for margin efficiency. Per-leg SL via client.placeorder(price_type="SL") (from examples/python/straddle_with_stops.py).
  • Time-based entries via apscheduler.schedulers.background.BackgroundScheduler with IST cron (from examples/python/straddle_scheduler.py).
  • Always fetch spot quote before any options order - client.quotes() first, then client.optionsorder() with offset="ATM".

Anti-patterns (always avoid)

  • asyncio - the OpenAlgo SDK is synchronous; use threading instead
  • df.iloc[-1] on live data - that's the forming bar; use iloc[-2]
  • Calling client.history(start_date=end_date) - returns 1 candle; always use multi-day lookback
  • Placing exit orders directly inside the WS callback - spawn a worker thread
  • Hardcoding exchange="NSE" when self-hosted - read OPENALGO_STRATEGY_EXCHANGE env var instead
  • Backtests with fees=0 and slippage=0 - the result is fantasy; use the segment-appropriate constants
  • Polling client.get_ltp() faster than 0.5s - use WS callbacks for real-time

Reference docs (in OpenAlgo repo)

  • SDK: D:/openalgo-python/openalgo/docs/prompt/openalgo python sdk.md
  • Services: D:/openalgo-python/openalgo/docs/prompt/services_documentation.md
  • WebSocket protocol: D:/openalgo-python/openalgo/docs/prompt/websockets-format.md
  • Self-hosted /python: D:/openalgo-python/openalgo/strategies/README.md
  • Production examples: D:/openalgo-python/openalgo/examples/python/

Comments

Markdown supported