Skip to content

feat(core,webapp): persist and expose realized profit breakdown#125

Draft
itamarreif wants to merge 1 commit intomainfrom
itamarreif/feat/realized-profit-detail
Draft

feat(core,webapp): persist and expose realized profit breakdown#125
itamarreif wants to merge 1 commit intomainfrom
itamarreif/feat/realized-profit-detail

Conversation

@itamarreif
Copy link
Copy Markdown
Contributor

Summary

Only the total USDC realized profit was previously stored in successful_trade. This PR persists the full breakdown and exposes it in the API response so the UI can show it alongside the expected profit on the signal detail page.

  • DB (001_initial.sql): 9 nullable columns added to successful_trade — per-token surplus, per-token USDC amount, gas in ETH and USDC, and the three prices used for conversion. Nullable so existing rows remain valid.
  • Core (database/trade.rs): TradeSuccessRow extended; insert_successful_trade now writes all fields from RealizedProfit; get_successful_by_symbols selects the new columns.
  • Backend (routes/trades.rs): new RealizedProfitDetail struct; SuccessfulTradeResponse gains realized_profit_detail: Option<RealizedProfitDetail> (null for pre-migration rows).
  • Frontend (types.ts): RealizedProfitDetail interface + updated SuccessfulTrade type.

Note: requires just db-reset (or an equivalent migration) on any existing dev DB before running.

Test plan

  • Run just db-reset to apply the updated schema
  • Execute a successful trade; confirm GET /trades/successful returns realized_profit_detail with all 9 fields populated
  • Confirm older rows (if any) return realized_profit_detail: null without erroring
  • cargo clippy -p kuma-core -p kuma-backend passes

🤖 Generated with Claude Code

Only the total USDC realized profit was stored. This adds the full
per-token and gas breakdown so it can be displayed alongside expected
profit on the signal detail page.

DB (001_initial.sql):
- Add 9 nullable columns to successful_trade: realized_surplus_{a,b},
  realized_usdc_amount_{a,b}, realized_gas_amount_{eth,usdc},
  realized_token_usdc_price_{a,b}, realized_gas_price_usdc

Core (database/trade.rs):
- Extend TradeSuccessRow with the new optional fields
- Write all fields from RealizedProfit in insert_successful_trade
- Select new columns in get_successful_by_symbols

Backend (routes/trades.rs):
- Add RealizedProfitDetail response struct
- Include it as Option<RealizedProfitDetail> in SuccessfulTradeResponse
  (None for older rows that predate the schema change)

Frontend (types.ts):
- Add RealizedProfitDetail interface
- Add realized_profit_detail: RealizedProfitDetail | null to SuccessfulTrade

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant