This document summarizes the 15 new features implemented for pyPortMan.
File: backend/trailing_stop_loss.py
Auto-adjusts stop-loss as price moves favorably to lock in profits.
Features:
- Create trailing stop-loss for LONG or SHORT positions
- Trail by POINTS or PERCENTAGE
- Automatic stop-loss adjustment based on price movement
- Trigger detection and notification
- Support for multiple trailing stop-losses per account
API Endpoints:
POST /trailing-stop-loss/create- Create new trailing stop-lossPUT /trailing-stop-loss/{id}- Update trailing stop-lossDELETE /trailing-stop-loss/{id}- Cancel trailing stop-lossPOST /trailing-stop-loss/check- Check and update all trailing stop-lossesGET /trailing-stop-loss- Get all trailing stop-lossesGET /trailing-stop-loss/summary- Get summary statistics
File: backend/order_templates.py
Save and reuse order configurations for quick order placement.
Features:
- Create reusable order templates
- Support for all order types (MARKET, LIMIT, SL, SL-M, CO, BO, AMO)
- Global and account-specific templates
- Template duplication
- Apply template with overrides
API Endpoints:
POST /order-templates/create- Create new templatePUT /order-templates/{id}- Update templateDELETE /order-templates/{id}- Delete templateGET /order-templates- Get all templatesPOST /order-templates/{id}/apply- Apply template to create orderPOST /order-templates/{id}/duplicate- Duplicate template
File: backend/order_scheduling.py
Schedule orders for specific times (pre-market, post-market).
Features:
- Schedule orders for specific times
- Pre-market and post-market scheduling
- Automatic order execution at scheduled time
- Order status tracking
- Market status monitoring
API Endpoints:
POST /scheduled-orders/create- Schedule new orderDELETE /scheduled-orders/{id}- Cancel scheduled orderPOST /scheduled-orders/execute- Execute due ordersGET /scheduled-orders- Get scheduled ordersGET /scheduled-orders/due- Get due ordersGET /scheduled-orders/upcoming- Get upcoming ordersGET /scheduled-orders/market-status- Get market status
File: backend/partial_exit.py
Configure multiple exit points (e.g., 50% at target1, 50% at target2).
Features:
- Create multi-exit strategies
- Configure quantity and target for each exit point
- Sequential execution of exit points
- Progress tracking
- Automatic execution when targets are reached
API Endpoints:
POST /partial-exit/create- Create exit strategyPUT /partial-exit/{id}- Update strategyDELETE /partial-exit/{id}- Cancel strategyPOST /partial-exit/check- Check and execute exitsGET /partial-exit- Get all strategiesGET /partial-exit/{id}- Get strategy detailsGET /partial-exit/{id}/next- Get next pending exit
File: backend/order_book_depth.py
View market depth for better entry/exit decisions.
Features:
- Fetch real-time order book depth (5 levels)
- Bid/ask analysis
- Spread calculation
- Market sentiment analysis
- Historical depth tracking
- Liquidity scoring
API Endpoints:
GET /order-book-depth/{stock}- Get current order book depthGET /order-book-depth/{stock}/history- Get historical depthGET /order-book-depth/{stock}/analysis- Analyze order bookGET /order-book-depth/summary- Get summary for multiple stocksGET /order-book-depth/{stock}/changes- Get depth changes over time
File: backend/sector_pnl.py
Track performance by industry sector.
Features:
- Automatic sector classification
- Sector-wise P&L calculation
- Sector comparison and analysis
- Historical sector performance
- Portfolio attribution by sector
API Endpoints:
GET /sector-pnl/{account_id}- Calculate sector P&LPOST /sector-pnl/{account_id}/save- Save sector P&L dataGET /sector-pnl/{account_id}/history- Get historical sector P&LGET /sector-pnl/{account_id}/comparison/{sector}- Get sector comparisonGET /sector-pnl/{account_id}/summary- Get sector summaryGET /sector-pnl/{account_id}/attribution- Get portfolio attribution
File: backend/trading_statistics.py
Track trading statistics over time.
Features:
- Calculate win rate and loss rate
- Risk-reward ratio analysis
- Average profit/loss calculation
- Sharpe and Sortino ratios
- Drawdown tracking
- Performance metrics by period
API Endpoints:
POST /trading-statistics/calculate- Calculate statisticsGET /trading-statistics- Get all statisticsGET /trading-statistics/summary- Get statistics summaryGET /trading-statistics/win-rate-trend- Get win rate trendGET /trading-statistics/risk-reward- Get risk-reward analysisGET /trading-statistics/performance- Get performance metricsGET /trading-statistics/distribution- Get trade distribution
File: backend/drawdown_analysis.py
Visualize maximum drawdown periods.
Features:
- Calculate drawdown periods
- Current drawdown tracking
- Maximum drawdown identification
- Drawdown severity classification
- Recovery analysis
- Chart data generation
API Endpoints:
POST /drawdown/calculate- Calculate drawdownsGET /drawdown/current- Get current drawdownGET /drawdown/max- Get maximum drawdownGET /drawdown/history- Get drawdown historyGET /drawdown/summary- Get drawdown summaryGET /drawdown/chart-data- Get chart dataGET /drawdown/recovery- Get recovery analysis
File: backend/correlation_manager.py
Show correlation between holdings.
Features:
- Calculate correlation matrix
- High/low correlation pair identification
- Diversification scoring
- Sector correlation analysis
- Historical correlation tracking
API Endpoints:
POST /correlation/calculate- Calculate correlation matrixGET /correlation/matrix- Get correlation matrixGET /correlation/high- Get high correlation pairsGET /correlation/low- Get low correlation pairsGET /correlation/summary- Get correlation summaryGET /correlation/diversification- Get diversification scoreGET /correlation/sector- Get sector correlation
File: backend/tax_reports.py
Generate tax-ready statements for monthly/quarterly reporting.
Features:
- Generate monthly/quarterly/yearly tax reports
- Holdings and trades summary
- Short-term and long-term gains/losses
- Tax liability estimation
- Export to JSON/CSV
API Endpoints:
POST /tax-reports/generate- Generate tax reportGET /tax-reports- Get all tax reportsGET /tax-reports/{id}- Get specific reportGET /tax-reports/{id}/export- Export reportGET /tax-reports/summary- Get tax summary
File: backend/discord_alerts.py
Send alerts via Discord webhook or bot.
Features:
- Discord webhook support
- Rich embed formatting
- GTT triggered alerts
- Loss alerts
- Order placement alerts
- Daily summary alerts
API Endpoints:
POST /discord/config- Save Discord configurationGET /discord/config- Get Discord configurationPOST /discord/test- Test Discord connectionGET /discord/history- Get alert history
File: backend/email_alerts.py
Send email alerts for critical events (large losses, margin calls).
Features:
- SMTP email support
- HTML and plain text emails
- Loss threshold alerts
- Margin call alerts
- Daily summary emails
- GTT triggered alerts
API Endpoints:
POST /email/config- Save email configurationGET /email/config- Get email configurationPOST /email/test- Test email connectionGET /email/history- Get alert history
File: backend/price_movement_alerts.py
Alert when stock moves X% in Y minutes.
Features:
- Create price movement alerts
- UP/DOWN movement detection
- Time window configuration
- Repeat alerts support
- Automatic trigger detection
API Endpoints:
POST /price-movement-alerts/create- Create alertPUT /price-movement-alerts/{id}- Update alertDELETE /price-movement-alerts/{id}- Cancel alertGET /price-movement-alerts- Get all alertsPOST /price-movement-alerts/check- Check for triggersGET /price-movement-alerts/summary- Get summary
File: backend/volume_spike_alerts.py
Detect unusual trading activity.
Features:
- Create volume spike alerts
- Average volume calculation
- Volume multiplier configuration
- Unusual activity detection
- Volume trend analysis
API Endpoints:
POST /volume-spike-alerts/create- Create alertPUT /volume-spike-alerts/{id}- Update alertDELETE /volume-spike-alerts/{id}- Cancel alertGET /volume-spike-alerts- Get all alertsPOST /volume-spike-alerts/check- Check for spikesGET /volume-spike-alerts/{stock}/analysis- Analyze volumeGET /volume-spike-alerts/unusual- Detect unusual activity
File: backend/news_integration.py
Fetch and display relevant news for watchlist stocks.
Features:
- Fetch news for stocks
- Sentiment analysis
- News relevance scoring
- Watchlist news aggregation
- Top stories by relevance
- News search functionality
API Endpoints:
POST /news/fetch/{stock}- Fetch news for stockPOST /news/fetch-watchlist- Fetch news for watchlistGET /news- Get news with filtersGET /news/summary- Get news summaryGET /news/{stock}/sentiment- Get sentiment analysisGET /news/top-stories- Get top storiesGET /news/search- Search news
The following new models were added to backend/models.py:
TrailingStopLoss- Trailing stop-loss ordersOrderTemplate- Reusable order templatesScheduledOrder- Scheduled ordersPartialExitStrategy- Partial exit strategiesPartialExitPoint- Individual exit pointsSectorPnL- Sector-wise P&L dataTradingStatistics- Trading statisticsDrawdownRecord- Drawdown recordsCorrelationData- Correlation matrix dataTaxReport- Tax reportsDiscordConfig- Discord configurationEmailConfig- Email configurationPriceMovementAlert- Price movement alertsVolumeSpikeAlert- Volume spike alertsNewsItem- News items
To use these new features, ensure you have the required dependencies:
pip install numpy requestsThe features are now ready to use through the API endpoints listed above.