Skip to main content

🧠 Trade Manager

A production-grade Intraday Auto Trading Manager with full trade persistence, rule-based risk management, and daily performance tracking.


📘 Overview

TradeManager.py is a Python-based automated trade manager that combines professional risk control, performance logging, and capital discipline.
Designed for intraday traders, investors, and quantitative analysts, it helps manage trades with strict loss/profit limits, ensuring capital protection and consistency.


⚙️ Core Features

💼 Portfolio & Risk Management

  • Capital Tracking – Auto carry-forward of daily closing balance.
  • Position Sizing – Based on risk % of total capital.
  • Max Daily Drawdown / Profit Cap – Automatically halts trading when daily limits are reached.
  • Capital Update Menu – Modify default capital interactively and persist across sessions.

📊 Trade Rules

  • Limit simultaneous open trades: max_open_trades
  • Restrict total daily loss and profit trades:
    • max_loss_trades
    • max_target_trades
  • Auto-block further entries after hitting limits.
  • Hardcoded Startup Trades – Useful for testing and demo environments.

🧾 Database Persistence (SQLite)

All trade and performance data are stored locally in trade_manager.db:

  • open_trades – Current running trades
  • trade_log – Historical closed trade performance
  • daily_stats – Day-wise P&L and metrics

📈 Reports

Generate and review analytics directly in the terminal:

  • Intraday Stock-wise Report (Today or custom date)
  • Weekly Summary (Last 4 weeks)
  • Monthly Performance Summary

🧠 Intelligent Auto-Stop Logic

Automatically pauses the system if:

  • Daily drawdown limit exceeded
  • Profit target achieved
  • Too many loss trades occurred

pip install TradeManager

Usage

#!/usr/bin/env python3
"""
Launcher file for AutoTradeManager class.
Edit the variables below to configure your session.
"""

from Trademanager import AutoTradeManager

# CONFIG / HARDCODED TRADES
# =========================================================

DB_FILE                     = "trade_manager.db"

DEFAULT_CAPITAL             = 10000.0
DEFAULT_RISK_PCT            = 1.0             # Percent of capital risked per trade (2%)

# Auto-stop defaults (percent of initial capital)
DEFAULT_MAX_DRAWDOWN_PCT    = 3.0             # -3% daily drawdown
DEFAULT_MAX_PROFIT_PCT      = 5.0             # +5% daily profit cap (optional)

MAX_OPEN_TRADES             = 3
MAX_LOSS_TRADES             = 1
MAX_TARGET_TRADES           = 2

# Hardcoded startup option (you asked for this — not ignored)
HARD_CODED_MODE_ON_START = False              # True  False

HARDCODED_TRADES = [
    {"symbol": "NIFTY", "entry": 25000, "stop_loss": 24800, "target": 25200, "lot_size": 50},
    {"symbol": "BANKNIFTY", "entry": 61000, "stop_loss": 60500, "target": 62000, "lot_size": 25},
]


if __name__ == "__main__":
    atm = AutoTradeManager(
        db_file                 = DB_FILE,
        default_capital         = DEFAULT_CAPITAL,
        default_risk_pct        = DEFAULT_RISK_PCT,
        max_drawdown_pct        = DEFAULT_MAX_DRAWDOWN_PCT,
        max_profit_pct          = DEFAULT_MAX_PROFIT_PCT,
        max_open_trades         = MAX_OPEN_TRADES,
        max_loss_trades         = MAX_LOSS_TRADES,
        max_target_trades       = MAX_TARGET_TRADES,
        hardcoded_mode          = HARD_CODED_MODE_ON_START,
        hardcoded_trades        = HARDCODED_TRADES,
    )
    atm.run()

🧩 Configuration Parameters

Parameter Type Description Default
db_file str SQLite database filename trade_manager.db
default_capital float Starting capital 10000.0
default_risk_pct float Risk % per trade 1.0
max_drawdown_pct float Daily drawdown stop 3.0
max_profit_pct float Daily profit stop 5.0
max_open_trades int Concurrent open positions 3
max_loss_trades int Max allowed loss trades per day 1
max_target_trades int Max allowed target hits per day 2
HARD_CODED_MODE_ON_START bool Enable/disable startup trades False

Example Workflow

  1. Start the manager → initializes database
  2. Add new trade with stop loss and target
  3. Manager auto-adjusts available capital
  4. Logs results upon close
  5. Displays P&L and risk compliance report

📂 Database Schema

open_trades

Field Type Description
id INTEGER Auto ID
symbol TEXT Stock/Instrument
entry_price REAL Entry level
stop_loss REAL SL value
target REAL Target price
qty INTEGER Quantity
status TEXT Active/Closed

trade_log

Field Type Description
id INTEGER Auto ID
symbol TEXT Stock
pnl REAL Profit/Loss
exit_reason TEXT Target/SL/Manual
date TEXT Trade date

daily_stats

Field Type Description
date TEXT Trading date
capital REAL End-of-day capital
daily_gain REAL Day P&L
drawdown REAL Daily drawdown %

🧰 Key Modules Used

  • sqlite3 – Data persistence
  • pandas – Data manipulation and reporting
  • rich – Colored and formatted terminal output
  • datetime – Trade and report timestamps

🧑‍💼 Example Output (Terminal View)

📋 ORDER REVIEW
────────────────────────────────────
💰 Available Capital: ₹10000.00
💸 Risk per Trade: ₹100.00 (1%)
📈 Symbol: RELIANCE
🎯 Target: ₹2800.00
🛑 Stop Loss: ₹2700.00
✔️ Quantity: 10
────────────────────────────────────
✅ Trade Added Successfully!

🧠 Future Enhancements

  • 🔮 ML-based profit probability prediction
  • 📡 Live market data integration
  • 💬 Telegram / Discord alerts
  • 🧾 CSV export of reports
  • 🕹️ GUI dashboard (Tkinter / Streamlit)

⚠️ Disclaimer

This tool is built for educational and analytical use.
It does not execute real trades.
Always verify decisions manually before executing orders in live markets.


Metadata

Release files for TradeManager 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for TradeManager 0.0.6
File Size Uploaded Provenance Actions
trademanager-0.0.6.tar.gz 23.7 kB Without provenance Details for trademanager-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for TradeManager 0.0.6
File Interpreter ABI Platform Actions
trademanager-0.0.6-py3-none-any.whl Python 3 none any Details for trademanager-0.0.6-py3-none-any.whl

Total release size: 48.9 kB

Release files / trademanager-0.0.6.tar.gz

Download URL trademanager-0.0.6.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2b86d22bd9002c3f51ab133c1de2380328b0a4d0f43a5e4fe38712809890d5d6
BLAKE2b-256 checksum
How to use checksums
8101911f66ae74fd235f4d684d461c022316365a91cf8d4fc7073fad3db4b842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / trademanager-0.0.6-py3-none-any.whl

Download URL trademanager-0.0.6-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37d4e06e5b1df1c90fa5348520932480e7c3d375ef781a9aa6fc460ab2074e88
BLAKE2b-256 checksum
How to use checksums
70fb7132184cc62ea172c542b3a6898d5112fdb70b6d99a239ecf6b51611ac1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for TradeManager 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page