Skip to content

Latest commit

 

History

History
378 lines (291 loc) · 10.9 KB

File metadata and controls

378 lines (291 loc) · 10.9 KB

pyPortMan New Features Implementation Summary

This document summarizes the 15 new features implemented for pyPortMan.

🎯 Trading & Order Management

1. Trailing Stop-Loss Orders ✅

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-loss
  • PUT /trailing-stop-loss/{id} - Update trailing stop-loss
  • DELETE /trailing-stop-loss/{id} - Cancel trailing stop-loss
  • POST /trailing-stop-loss/check - Check and update all trailing stop-losses
  • GET /trailing-stop-loss - Get all trailing stop-losses
  • GET /trailing-stop-loss/summary - Get summary statistics

2. Order Templates ✅

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 template
  • PUT /order-templates/{id} - Update template
  • DELETE /order-templates/{id} - Delete template
  • GET /order-templates - Get all templates
  • POST /order-templates/{id}/apply - Apply template to create order
  • POST /order-templates/{id}/duplicate - Duplicate template

3. Order Scheduling ✅

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 order
  • DELETE /scheduled-orders/{id} - Cancel scheduled order
  • POST /scheduled-orders/execute - Execute due orders
  • GET /scheduled-orders - Get scheduled orders
  • GET /scheduled-orders/due - Get due orders
  • GET /scheduled-orders/upcoming - Get upcoming orders
  • GET /scheduled-orders/market-status - Get market status

4. Partial Exit Strategy ✅

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 strategy
  • PUT /partial-exit/{id} - Update strategy
  • DELETE /partial-exit/{id} - Cancel strategy
  • POST /partial-exit/check - Check and execute exits
  • GET /partial-exit - Get all strategies
  • GET /partial-exit/{id} - Get strategy details
  • GET /partial-exit/{id}/next - Get next pending exit

5. Order Book Depth ✅

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 depth
  • GET /order-book-depth/{stock}/history - Get historical depth
  • GET /order-book-depth/{stock}/analysis - Analyze order book
  • GET /order-book-depth/summary - Get summary for multiple stocks
  • GET /order-book-depth/{stock}/changes - Get depth changes over time

📊 Analytics & Insights

6. Sector-wise P&L Attribution ✅

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&L
  • POST /sector-pnl/{account_id}/save - Save sector P&L data
  • GET /sector-pnl/{account_id}/history - Get historical sector P&L
  • GET /sector-pnl/{account_id}/comparison/{sector} - Get sector comparison
  • GET /sector-pnl/{account_id}/summary - Get sector summary
  • GET /sector-pnl/{account_id}/attribution - Get portfolio attribution

7. Win Rate & Risk-Reward Analysis ✅

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 statistics
  • GET /trading-statistics - Get all statistics
  • GET /trading-statistics/summary - Get statistics summary
  • GET /trading-statistics/win-rate-trend - Get win rate trend
  • GET /trading-statistics/risk-reward - Get risk-reward analysis
  • GET /trading-statistics/performance - Get performance metrics
  • GET /trading-statistics/distribution - Get trade distribution

8. Drawdown Analysis ✅

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 drawdowns
  • GET /drawdown/current - Get current drawdown
  • GET /drawdown/max - Get maximum drawdown
  • GET /drawdown/history - Get drawdown history
  • GET /drawdown/summary - Get drawdown summary
  • GET /drawdown/chart-data - Get chart data
  • GET /drawdown/recovery - Get recovery analysis

9. Correlation Heatmap ✅

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 matrix
  • GET /correlation/matrix - Get correlation matrix
  • GET /correlation/high - Get high correlation pairs
  • GET /correlation/low - Get low correlation pairs
  • GET /correlation/summary - Get correlation summary
  • GET /correlation/diversification - Get diversification score
  • GET /correlation/sector - Get sector correlation

10. Tax Reports ✅

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 report
  • GET /tax-reports - Get all tax reports
  • GET /tax-reports/{id} - Get specific report
  • GET /tax-reports/{id}/export - Export report
  • GET /tax-reports/summary - Get tax summary

🔔 Alerts & Notifications

11. Discord Alerts Integration ✅

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 configuration
  • GET /discord/config - Get Discord configuration
  • POST /discord/test - Test Discord connection
  • GET /discord/history - Get alert history

12. Email Alerts ✅

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 configuration
  • GET /email/config - Get email configuration
  • POST /email/test - Test email connection
  • GET /email/history - Get alert history

13. Price Movement Alerts ✅

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 alert
  • PUT /price-movement-alerts/{id} - Update alert
  • DELETE /price-movement-alerts/{id} - Cancel alert
  • GET /price-movement-alerts - Get all alerts
  • POST /price-movement-alerts/check - Check for triggers
  • GET /price-movement-alerts/summary - Get summary

14. Volume Spike Alerts ✅

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 alert
  • PUT /volume-spike-alerts/{id} - Update alert
  • DELETE /volume-spike-alerts/{id} - Cancel alert
  • GET /volume-spike-alerts - Get all alerts
  • POST /volume-spike-alerts/check - Check for spikes
  • GET /volume-spike-alerts/{stock}/analysis - Analyze volume
  • GET /volume-spike-alerts/unusual - Detect unusual activity

15. News Integration ✅

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 stock
  • POST /news/fetch-watchlist - Fetch news for watchlist
  • GET /news - Get news with filters
  • GET /news/summary - Get news summary
  • GET /news/{stock}/sentiment - Get sentiment analysis
  • GET /news/top-stories - Get top stories
  • GET /news/search - Search news

Database Models Added

The following new models were added to backend/models.py:

  1. TrailingStopLoss - Trailing stop-loss orders
  2. OrderTemplate - Reusable order templates
  3. ScheduledOrder - Scheduled orders
  4. PartialExitStrategy - Partial exit strategies
  5. PartialExitPoint - Individual exit points
  6. SectorPnL - Sector-wise P&L data
  7. TradingStatistics - Trading statistics
  8. DrawdownRecord - Drawdown records
  9. CorrelationData - Correlation matrix data
  10. TaxReport - Tax reports
  11. DiscordConfig - Discord configuration
  12. EmailConfig - Email configuration
  13. PriceMovementAlert - Price movement alerts
  14. VolumeSpikeAlert - Volume spike alerts
  15. NewsItem - News items

Installation

To use these new features, ensure you have the required dependencies:

pip install numpy requests

The features are now ready to use through the API endpoints listed above.