-
Notifications
You must be signed in to change notification settings - Fork 2
feat(funds): implement fund ledger system and wallet management #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.0.0 | ||
| 2.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """add_fund_ledger_system | ||
|
|
||
| Revision ID: a62763117ed4 | ||
| Revises: 762a64d64b9d | ||
| Create Date: 2026-02-25 16:21:58.440948 | ||
|
|
||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = 'a62763117ed4' | ||
| down_revision: Union[str, None] = '762a64d64b9d' | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('fund_ledger', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('user_id', sa.Integer(), nullable=False), | ||
| sa.Column('trading_mode', sa.String(length=20), nullable=False), | ||
| sa.Column('transaction_type', sa.String(length=10), nullable=False), | ||
| sa.Column('category', sa.String(length=50), nullable=False), | ||
| sa.Column('amount', sa.Numeric(precision=15, scale=2), nullable=False), | ||
| sa.Column('balance_before', sa.Numeric(precision=15, scale=2), nullable=False), | ||
| sa.Column('balance_after', sa.Numeric(precision=15, scale=2), nullable=False), | ||
| sa.Column('description', sa.String(length=255), nullable=True), | ||
| sa.Column('reference_id', sa.String(length=100), nullable=True), | ||
| sa.Column('timestamp', sa.DateTime(), nullable=True), | ||
| sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
| op.create_index('idx_ledger_user_mode', 'fund_ledger', ['user_id', 'trading_mode'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_category'), 'fund_ledger', ['category'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_id'), 'fund_ledger', ['id'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_reference_id'), 'fund_ledger', ['reference_id'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_timestamp'), 'fund_ledger', ['timestamp'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_trading_mode'), 'fund_ledger', ['trading_mode'], unique=False) | ||
| op.create_index(op.f('ix_fund_ledger_user_id'), 'fund_ledger', ['user_id'], unique=False) | ||
| op.drop_index('idx_trading_log_level_component', table_name='trading_system_logs') | ||
| op.drop_index('idx_trading_log_timestamp', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_component', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_id', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_log_level', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_timestamp', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_trade_id', table_name='trading_system_logs') | ||
| op.drop_index('ix_trading_system_logs_user_id', table_name='trading_system_logs') | ||
| op.drop_table('trading_system_logs') | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('trading_system_logs', | ||
| sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), | ||
| sa.Column('log_level', sa.VARCHAR(length=20), autoincrement=False, nullable=False), | ||
| sa.Column('component', sa.VARCHAR(length=50), autoincrement=False, nullable=False), | ||
| sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False), | ||
| sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=True), | ||
| sa.Column('trade_id', sa.VARCHAR(length=50), autoincrement=False, nullable=True), | ||
| sa.Column('symbol', sa.VARCHAR(length=20), autoincrement=False, nullable=True), | ||
| sa.Column('latency_ms', sa.INTEGER(), autoincrement=False, nullable=True), | ||
| sa.Column('function_name', sa.VARCHAR(length=100), autoincrement=False, nullable=True), | ||
| sa.Column('line_number', sa.INTEGER(), autoincrement=False, nullable=True), | ||
| sa.Column('stack_trace', sa.TEXT(), autoincrement=False, nullable=True), | ||
| sa.Column('additional_data', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True), | ||
| sa.Column('timestamp', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), | ||
| sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='trading_system_logs_user_id_fkey', ondelete='CASCADE'), | ||
| sa.PrimaryKeyConstraint('id', name='trading_system_logs_pkey') | ||
| ) | ||
| op.create_index('ix_trading_system_logs_user_id', 'trading_system_logs', ['user_id'], unique=False) | ||
| op.create_index('ix_trading_system_logs_trade_id', 'trading_system_logs', ['trade_id'], unique=False) | ||
| op.create_index('ix_trading_system_logs_timestamp', 'trading_system_logs', ['timestamp'], unique=False) | ||
| op.create_index('ix_trading_system_logs_log_level', 'trading_system_logs', ['log_level'], unique=False) | ||
| op.create_index('ix_trading_system_logs_id', 'trading_system_logs', ['id'], unique=False) | ||
| op.create_index('ix_trading_system_logs_component', 'trading_system_logs', ['component'], unique=False) | ||
| op.create_index('idx_trading_log_timestamp', 'trading_system_logs', ['timestamp'], unique=False) | ||
| op.create_index('idx_trading_log_level_component', 'trading_system_logs', ['log_level', 'component'], unique=False) | ||
| op.drop_index(op.f('ix_fund_ledger_user_id'), table_name='fund_ledger') | ||
| op.drop_index(op.f('ix_fund_ledger_trading_mode'), table_name='fund_ledger') | ||
| op.drop_index(op.f('ix_fund_ledger_timestamp'), table_name='fund_ledger') | ||
| op.drop_index(op.f('ix_fund_ledger_reference_id'), table_name='fund_ledger') | ||
| op.drop_index(op.f('ix_fund_ledger_id'), table_name='fund_ledger') | ||
| op.drop_index(op.f('ix_fund_ledger_category'), table_name='fund_ledger') | ||
| op.drop_index('idx_ledger_user_mode', table_name='fund_ledger') | ||
| op.drop_table('fund_ledger') | ||
| # ### end Alembic commands ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,29 @@ | ||
| # 📝 Changelog | ||
| # 📠Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| ## [Unreleased] | ||
| - Ongoing improvements and bug fixes. | ||
| ## [2.0.1] - 2026-02-25 | ||
| ### Added | ||
| - **AI-Powered Development Agents:** | ||
| - Automated Issue Triager for bug analysis using Gemini. | ||
| - Automated PR Reviewer for code quality, complexity (radon), and risk checks. | ||
| - Automated Backtesting for strategy performance validation in pull requests. | ||
| - AI Documentation Agent for automated semantic changelogs. | ||
| - Trading Risk Guard for detecting dangerous code patterns (hardcoded secrets, unlocalized time). | ||
| - **Fund Ledger System:** | ||
| - Database-backed fund ledger tracking all deposits and withdrawals. | ||
| - Integration with `CapitalManager` for accurate balance management across brokers. | ||
| - New UI components: `AddFundsModal`, `FundStatementTable`, and `FundsTab` in profile. | ||
| - **AI Support & Telegram Integration:** | ||
| - `AISupportService` for context-aware support answering queries using project docs and trade history. | ||
| - Telegram bot for remote support and account status tracking. | ||
|
|
||
| ### Changed | ||
| - Refactored `execution_handler.py` and `pnl_tracker.py` to utilize the new `FundManager` for balance synchronization. | ||
| - Enhanced `AutoTradingPage` for better performance and list virtualization. | ||
| - Updated `requirements.txt` with `google-generativeai` and `PyGithub`. | ||
|
|
||
| ### Fixed | ||
| - Improved timezone handling for IST consistency across services. | ||
| - Corrected paper trading P&L logic for accurate balance updates. | ||
| - Refined stock selection direction logic for neutral market conditions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Copilot Autofix
AI 2 months ago
General approach: Do not expose raw exception messages (or derived text like stack traces) in HTTP responses. Instead, log the full exception server‑side and return a generic, user‑safe error message and optionally a stable error code. Internally, service methods should not return raw
str(e)to API layers; they should either raise suitable application exceptions or return generic error fields without implementation details.Best concrete fix here, without changing existing behavior structure:
In
FundManagementService.add_paper_funds, change theexceptblock so that:e) using the existing logger.{"success": False, "error": str(e)}, it returns a generic error message, e.g.{"success": False, "error": "Failed to add paper funds. Please try again later."}. This preserves the response shape (success+errorstring) so existing callers don’t break, but removes sensitive details.In the router’s
/funds/add-paper-fundsendpoint, the current pattern of catching exceptions and raisingHTTPException(status_code=500, detail=str(e))can also leakstr(e)if something fails before reaching the service or if the service raises instead of returning an error dict. Change thatHTTPExceptiondetail to a generic message, e.g."Internal server error while adding funds". Logging already captures the detailed error.These two changes ensure that neither direct exceptions nor service-returned errors expose internal exception text to clients, while leaving overall control flow and result structure intact.
Specific edits:
services/trading_execution/fund_manager.py, withinFundManagementService.add_paper_funds, lines 155–158.router/trading_execution_router.py, withinadd_paper_fundsroute, lines 1914–1916.No new methods or imports are required beyond what’s already present; we continue using the existing
loggerinstances.