{"id":48734593,"url":"https://github.com/mrin9/tradebot-python","last_synced_at":"2026-04-12T03:38:51.098Z","repository":{"id":349173753,"uuid":"1196881345","full_name":"mrin9/tradebot-python","owner":"mrin9","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-11T15:39:23.000Z","size":51432,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-12T03:38:47.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrin9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-31T06:06:54.000Z","updated_at":"2026-04-11T15:39:30.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mrin9/tradebot-python","commit_stats":null,"previous_names":["mrin9/tradebot-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrin9/tradebot-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrin9%2Ftradebot-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrin9%2Ftradebot-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrin9%2Ftradebot-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrin9%2Ftradebot-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrin9","download_url":"https://codeload.github.com/mrin9/tradebot-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrin9%2Ftradebot-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31703501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T21:17:31.016Z","status":"online","status_checked_at":"2026-04-12T02:00:06.763Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-12T03:38:50.542Z","updated_at":"2026-04-12T03:38:51.087Z","avatar_url":"https://github.com/mrin9.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Trade Bot V2\n\n**Python Trading Engine for Indian Markets (XTS Connect)**\n\nThis project contains a **multi‑timeframe trading engine**, **backtest framework**, and **live trading wrapper** for the Indian markets using XTS. The focus of this README is the **core engine, data layer, and CLI**; the UI and HTTP API are optional layers and are not required to understand or operate the trading logic.\n\n---\n\n## Quickstart\n\n### 1. Prerequisites\n\n- **Python 3.10+** (3.11 recommended)\n- **MongoDB** (local or remote)\n- **XTS Credentials** (for live trading)\n\n### 2. Setup\n\n```bash\ngit clone \u003crepo_url\u003e\ncd trade-bot-v2\n\npython -m venv .venv\nsource .venv/bin/activate      # Windows: .venv\\Scripts\\activate\npip install -r requirements.txt\n\ncp .env.example .env\n# Edit .env with:\n# - DB_NAME (e.g., tradebot, tradebot_test, tradebot_frozen)\n# - Mongo connection details\n# - XTS API keys (if you plan to trade live)\n```\n\n### 3. First‑Time Initialization\n\nRun these once per environment:\n\n```bash\n# Ensure DB indexes\npython apps/cli/main.py ensure_indexes\n\n# Seed default strategy indicator configs\npython apps/cli/main.py seed_strategies\n\n# Sync instrument master and recent history\npython apps/cli/main.py update_master\npython apps/cli/main.py sync_history --date-range \"5dago|now\"\n```\n\n---\n\n## Core Workflows (CLI‑Driven)\n\nThe main entry point for operating the engine is the **CLI**:\n\n```bash\npython apps/cli/main.py --help\npython apps/cli/main.py menu      # Interactive console\n```\n\n### Backtesting\n\nRun a strategy against historical data:\n\n```bash\npython apps/cli/main.py backtest \\\n  --strategy-id triple-confirmation \\\n  --start 2024-02-01 \\\n  --end 2024-02-02 \\\n  --mode db \\\n  --budget 200000 \\\n  --invest-mode compound \\\n  --sl-pct 4.0 \\\n  --target-pct \"3\" \\\n  --tsl-pct 0.5 \\\n  --strike-selection ATM\n```\n\nYou can also use `python apps/cli/main.py interactive_backtest` or the `menu` command for a guided flow. See `docs/testing_guide.md` for detailed backtest options and test suites.\n\n### Live Trading\n\nStart the live engine (XTS sockets + FundManager):\n\n```bash\npython apps/cli/main.py live_trade \\\n  --strategy-id triple-confirmation \\\n  --strike-selection ATM \\\n  --budget 200000 \\\n  --sl-pct 4.0 \\\n  --target-pct \"3\" \\\n  --tsl-pct 0.5 \\\n  --use-be \\\n  --tsl-id active-ema-5 \\\n  --record-papertrade \\\n  --log-active-indicator \\\n  --debug\n```\n\nSee `docs/live_trading_guide.md` for a deeper explanation of how live trading works and how to operate it safely.\n\n### Data Maintenance\n\n```bash\n# Sync instrument master and history\npython apps/cli/main.py update_master\npython apps/cli/main.py sync_history --date-range \"2dago|now\"\n\n# Manage data quality and size\npython apps/cli/main.py check_gaps --date-range \"2dago|now\"\npython apps/cli/main.py fill_gaps --date-range \"2dago|now\"\npython apps/cli/main.py age_out --days 60\n```\n\nSee `docs/data_management.md` for full details on collections, suffixes, and gap handling.\n\n---\n\n## API \u0026 UI (Optional)\n\nThe project includes an optional FastAPI backend and a Nuxt.js frontend for monitoring trades and backtest results.\n\n### 1. Start the API Server\n\nThe API provides data to the UI and can be started via the Makefile or directly using Uvicorn:\n\n```bash\n# Using Makefile\nmake api\n\n# Or directly\npython -m apps.api.run\n```\nThe API runs on `http://localhost:8000`.\n\n### 2. Start the UI Dashboard\n\nThe dashboard is built with Nuxt.js and requires Node.js/npm:\n\n```bash\ncd apps/ui\nnpm install    # First time only\nnpm run dev\n```\nThe UI runs on `http://localhost:3000`.\n\n---\n\n## Documentation\n\nUpdated documentation is in the `docs/` folder:\n\n- **Architecture \u0026 Layout**\n  - `docs/project_layout_and_architecture.md` – Folder structure, core modules, and runtime architecture.\n- **Operations \u0026 DevOps**\n  - `docs/operational_guide.md` – Local setup, CLI usage, backtest and live workflows.\n  - `docs/devops_guide.md` – Docker/compose usage, container logs, DB strategy.\n- **Testing**\n  - `docs/testing_guide.md` – Test layers (no‑DB, read/write DB, frozen DB, XTS) and backtest runner.\n- **Trading \u0026 Data**\n  - `docs/live_trading_guide.md` – How the live engine works with XTS and Mongo.\n  - `docs/data_management.md` – Master data, history sync, gaps, age‑out, frozen DB.\n- **Deep Dive**\n  - `docs/functional_and_code_explanation.md` – Detailed mapping of concepts (indicators, resampling, fund manager, strategies) to concrete code.\n\nIf you see `old_docs/` in the repo, treat those files as historical notes; the `docs/` directory described above is the canonical, up‑to‑date documentation.\n\n---\n\n## Key Engine Features\n\n- **Multi‑Timeframe Analysis (MTFA)** via `FundManager` and `CandleResampler`.\n- **Vectorized Indicators** using Polars in `IndicatorCalculator` (EMA, RSI, Supertrend, MACD, Bollinger Bands, etc.).\n- **Unified Strategy Runtime**:\n  - Same `FundManager`, `PositionManager`, and Python strategy classes power both backtests and live trading.\n- **Robust Risk Management**:\n  - Fixed SL, multi‑target exits, pyramiding, BE, and indicator‑driven trailing SL.\n- **Deterministic Testing**:\n  - Frozen DB and a shared backtest runner for golden test scenarios.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrin9%2Ftradebot-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrin9%2Ftradebot-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrin9%2Ftradebot-python/lists"}