A command-line interface (CLI) application for managing and tracking stock trades, funds, and portfolio positions with multiple accounts. Built with Python and SQLite, featuring a rich terminal UI powered by the Rich library.
- View Holdings Summary: Display all your stock positions with shares, total cost, market value, and unrealized/realized P/L
- Open Positions Tracking: Track all open buy positions with real-time profit/loss calculations
- Account Totals: View total funds, cash balance, fees, VAT, and net worth at a glance
- Buy Trades: Record stock purchases with automatic cost calculation (including fees and VAT)
- Sell Trades: Record stock sales with profit/loss tracking and position closing
- Delete Trades: Remove incorrect trade entries
- View Trade Details: Inspect individual trade records in a formatted table
- Deposit Funds: Record fund deposits with multi-currency support (USD and configurable secondary currency)
- Withdraw Funds: Record fund withdrawals
- Funds History: View complete deposit/withdrawal history
- Real-Time Price Updates: Fetch current stock prices from Yahoo Finance (yfinance)
- Trade Filtering: Filter and search through trade history
- Risk Management Planner: Plan risk scenarios with technical levels and drawdown calculations
- Calculator: Built-in percentage and currency conversion calculator
- Create and manage multiple trading accounts
- Each account has its own database, exchange rate, and default ticker settings
- Easy switching between accounts
Import your existing trades and funds from Excel spreadsheets with two methods:
Method 1: Using Markers (Automated) Add markers in your Excel file to define data sections. The app will automatically detect and import:
| Marker Start | Marker End | Data Type |
|---|---|---|
#FDB |
#FDE |
Fund Deposits |
#FWB |
#FWE |
Fund Withdrawals |
#TBB |
#TBE |
Buy Trades |
#TSB |
#TSE |
Sell Trades |
Method 2: Manual Row Selection
Specify row numbers or ranges (e.g., 1-5, 7, 10-12) to import specific rows.
Excel Column Mapping:
For Funds (deposits/withdrawals):
| Column | Field |
|---|---|
| C (3) | Date |
| D (4) | Source |
| E (5) | Amount (Secondary Currency) |
| F (6) | Amount (USD) |
| G (7) | Exchange Rate |
For Trades (buy/sell):
| Column | Field |
|---|---|
| A (1) | Is Position Open (buy only) |
| C (3) | Trade Date |
| D (4) | Symbol |
| E (5) | Quantity |
| F (6) | Price |
| G (7) | Fees |
| H (8) | VAT |
| J (10) | Cost Value |
| K (11) | Profit/Loss (sell only) |
To load data: Press M β L and follow the prompts. Default file: stocks_transactions.xlsx
- Python 3.13 or higher
- pip or Poetry package manager
-
Clone the repository:
git clone <repository-url> cd tradercli
-
Install dependencies using Poetry:
pip install poetry poetry install
-
Run the application:
poetry run python src/main.py
-
Clone the repository:
git clone <repository-url> cd tradercli
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install pandas openpyxl rich "yfinance>=0.2.66,<0.3.0" -
Run the application:
python src/main.py
To create a standalone executable using PyInstaller:
poetry run pyinstaller main.specThe executable will be available in the dist/ folder.
When you start the application, you'll see:
- Trades for Open Positions: Table showing all your open buy positions
- Summary of Holdings: Overview of your portfolio by ticker
- Account Totals: Financial summary including funds, cash, fees, and net worth
From the main screen, use these single-letter commands:
| Key | Action |
|---|---|
B |
Record a Buy trade |
S |
Record a Sell trade |
D |
Delete a trade |
T |
Change selected ticker |
U |
Update prices from Yahoo Finance |
F |
Filter trades |
P |
Risk management planner |
C |
Open calculator |
M |
Access main menu (accounts, settings, data management) |
Q |
Quit application |
You can also enter a price directly to update the selected ticker's current price.
Press M to access additional options:
| Key | Action |
|---|---|
A |
Switch or create accounts |
R |
Reset/migrate database schema |
L |
Load data from external files |
F |
View funds history |
D |
Record a deposit |
W |
Record a withdrawal |
P |
Edit position settings |
S |
Modify account settings |
The application uses a settings.json file to store:
- Default account name
- Multiple account configurations with:
- Exchange rate and currency label (e.g., SAR, EUR)
- Default selected ticker
- Trading fees (USD)
TraderCLI uses SQLite databases with the following tables:
Tracks all deposits and withdrawals:
ID: Auto-increment primary keyopr: Operation type ('deposit' or 'withdraw')fund_date: Date of the transactionsource: Source/destination of fundsamount_SAR: Amount in secondary currencyamount_USD: Amount in USDrate_exchange: Exchange rate used
Records all buy and sell trades:
ID: Auto-increment primary keytrade_date: Date of the tradesymbol: Stock ticker symbolopr: Operation type ('buy' or 'sell')filled_qty: Number of sharesprice: Price per sharefees: Trading feesvat: Value Added Taxcost_value: Total cost/value of the tradeprofit_loss: Realized profit/loss (for sells)is_position_open: Whether the position is still open
- pandas: Data manipulation and analysis
- openpyxl: Excel file reading/writing
- rich: Terminal formatting and tables
- yfinance: Yahoo Finance API for real-time stock prices
- pyinstaller: For building standalone executables
tradercli/
βββ src/
β βββ main.py # Application entry point
β βββ trade.py # Trade operations (buy, sell, delete, view)
β βββ menu.py # Main menu and funds management
β βββ planner.py # Risk management planner
β βββ calculator.py # Calculator utilities
β βββ filter_trades.py # Trade filtering
β βββ load_data.py # Data import functionality
β βββ migrate.py # Database migration
β βββ settings.py # Settings management
β βββ stocks_reader.py # Stock data reader
β βββ utils.py # Utility functions
βββ build/ # PyInstaller build files
βββ pyproject.toml # Project configuration
βββ schema.sql # Database schema
βββ settings.json # Application settings
βββ README.md # This file
This project is provided as-is for personal use.
Developed by bugyboo ([email protected])

