SQLite, Risk & Money management, discipline trader with risk rules & reports
Project description
๐ง 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_tradesmax_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
- Start the manager โ initializes database
- Add new trade with stop loss and target
- Manager auto-adjusts available capital
- Logs results upon close
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trademanager-0.0.4.tar.gz.
File metadata
- Download URL: trademanager-0.0.4.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9362e4d432772e363f14be2e69623f7e414497e3fcb100dcbdecf5f0a5196f9e
|
|
| MD5 |
3aa134c7c2e52827d920c54821c0e372
|
|
| BLAKE2b-256 |
9379f54d4889bbce14c96d848a79704f38f2d3799a040367da46692f4159c093
|
File details
Details for the file trademanager-0.0.4-py3-none-any.whl.
File metadata
- Download URL: trademanager-0.0.4-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33393874093c34c863a34d4a51b6fd706b69de876a9c4d01476cb9680e30abbf
|
|
| MD5 |
3beee6d6e2a280fc5d02fcea33a4d983
|
|
| BLAKE2b-256 |
bd068c16e50c35f67f81046a254ef3063630c0fb5d9a36203ed454ea236c6da6
|