This application is a portfolio management system for handling cash and investment accounts. It features automatic transfers between accounts, email notifications, and a web-based dashboard.
- Dashboard for monitoring cash and investment accounts
- Automated cash transfers based on configurable thresholds
- Email notifications for transfers
- Portfolio allocation management
- Transaction history tracking
- Python 3.9+
- IBKR account (for production use)
- Resend account (for email notifications)
- Clone the repository
git clone https://github.com/avinashparthiban/arki-mvp.git
cd arki-mvp- Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure your email notification settings in
config/client_portal_config.json:
"email": {
"recipient_email": "[email protected]",
"email_service": "resend",
"resend_api_key": "your_resend_api_key",
"resend_from_email": "[email protected]",
"verified_email": "[email protected]"
}- Adjust cash management thresholds:
"cash_management": {
"min_cash_level": 10000.0,
"transfer_threshold": 5000.0,
"allocation_tolerance": 0.02
}- Configure account IDs:
"accounts": {
"cash_account_id": "DU12345",
"investment_account_id": "DU4184147"
}This application uses Resend for email notifications. Important notes:
-
Testing Mode: When using the default
[email protected]sender, emails can only be sent to the verified email address.- Right now emails can only be sent to my personal email. But once we can do a 2FA, I can add your email too.
-
For Production: You'll need to:
- Verify a domain with Resend
- Change the
resend_from_emailto use your verified domain (e.g.,[email protected])
-
Changing the Verified Email: If someone else is running the application, they should update the
verified_emailfield in the configuration to their own email address.
Start the Flask web server:
python client_portal.pyThe dashboard will be available at http://localhost:5001
- View Dashboard: See account balances, asset allocation, and performance charts
- Deposit Funds: Add funds to the cash account via the deposit page
- Automatic Transfers: When cash exceeds the threshold, funds automatically transfer to the investment account
- Portfolio Management: View and modify portfolio allocations in the settings
-
Email Notification Errors: If using Resend's testing mode, ensure the
verified_emailmatches the email associated with your Resend account. -
Transfer Failures: Check that account IDs match between the configuration and what's used in the portfolio manager.
This system provides an automated investment management interface that connects to Interactive Brokers (IBKR) to execute trades based on predefined portfolio allocations.
- Python 3.7+
- Interactive Brokers TWS (Trader Workstation) or IB Gateway
- IBKR demo or live account
-
Clone this repository:
git clone https://github.com/yourusername/investment-demo.git cd investment-demo -
Install required dependencies:
pip install pandas ibapi logging -
Create required directories:
mkdir -p logs config -
Make sure TWS (Trader Workstation) or IB Gateway is running and API connectivity is enabled.
-
Create a
config.jsonfile in theconfigdirectory:{ "ibkr": { "host": "127.0.0.1", "port": 7497, "client_id": 1 }, "accounts": { "investment_account_id": "YOUR_IBKR_ACCOUNT_ID" } } -
Create a portfolio allocation file (optional) at
config/portfolio_allocation.csv:account_type,strategy,instrument,target_percentage,instrument_type,exchange investment,growth,AAPL,0.3,STK,SMART investment,growth,MSFT,0.3,STK,SMART investment,growth,AMZN,0.4,STK,SMART investment,income,JNJ,0.5,STK,SMART investment,income,PG,0.5,STK,SMART
Run the main script:
python investment_demo.py
-
Initialization:
- The system will attempt to connect to IBKR TWS/Gateway
- It will load configuration and portfolio allocations
- A command-line interface will appear with available commands
- Ignore all market data related warnings/errors: the program will work as intended.
-
Commands Available:
deposit <amount>: Simulate a cash deposit and allocate it according to the portfolio strategybalance: Display your current account balance and portfolio valueexit: Safely exit the program
-
Cash Deposit Process:
- When you deposit cash using the
depositcommand, the system will:- Update your account balance
- Calculate how to allocate the funds according to your portfolio allocation
- Place market orders to purchase the required securities
- Show you a summary of the executed trades
- View the ordersheet in the
logs/orders.csvfile
- When you deposit cash using the
-
Scheduler:
- The system runs a scheduler that periodically:
- Processes any pending cash deposits
- Can be configured to automatically rebalance your portfolio
- The system runs a scheduler that periodically:
-
Error Handling:
- If TWS is not running, you'll receive appropriate error messages
- The system will log all operations and errors to the
logsdirectory
- logs/main.log: Contains detailed system logs
- logs/orders.csv: Records all order details for auditing
- This is a demo system and uses default portfolio allocations if none are provided
- The system primarily uses market orders for simplicity
- Portfolio rebalancing is available but disabled by default
- The system caches market data for performance
- Ensure TWS/IB Gateway is running before starting the application
- Check the port settings in TWS (Edit > Global Configuration > API > Settings)
- Verify your IBKR account ID is correct in the config file
- Review logs for detailed error information
- Run the
client_portal.pyand test out the deposit function.
- Run the
investment_demo.pyto test the automated investment management system.