Skip to content

[Phase 2] feat(core): fee recommendation endpoint #82

@Tinna23

Description

@Tinna23

Overview

Add a GET /api/fees/recommend endpoint that reads the latest fee stats already stored in SQLite and returns an optimal fee suggestion based on current network congestion. No new Horizon calls needed — all data is derived from what we already collect.

Recommendation Logic

Congestion is derived from the ratio of avg_fee to base_fee:

  • LOW (ratio < 1.5×) → recommend p20
  • MEDIUM (ratio 1.5–3×) → recommend p50
  • HIGH (ratio > 3×) → recommend p70

Response Shape

{
  "recommended_fee": 120,
  "congestion": "LOW",
  "basis": "p20",
  "base_fee": 100,
  "avg_fee": 110,
  "timestamp": "2026-03-21T10:00:00Z"
}

Acceptance Criteria

  • GET /api/fees/recommend returns the above response shape
  • Congestion logic applied correctly for all three levels
  • Reads from the latest record in SQLite — no new Horizon call
  • Returns a meaningful error if no fee data exists in the database yet
  • Unit tests covering all three congestion levels with mocked fee data
  • CORS headers consistent with existing endpoints

Notes

  • No new database tables or migrations needed
  • Congestion thresholds can be made configurable via env vars in a future iteration
  • Related frontend issue: [Phase 2] feat(ui): dashboard — fee recommendation widget

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend / Rust core work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions