Skip to content

Add a TWAP price endpoint returning the time-weighted average price for a creator key over a configurable window #866

Description

@Chucks1093

Summary

The client TWAP display needs a backend endpoint. A GET /keys/:keyId/twap endpoint that reads price snapshots and computes the average over a requested window should be added.

Scope

  • Add GET /keys/:keyId/twap?window=1h|24h|7d endpoint (no auth required)
  • Call the get_twap contract view function with the window converted to ledger units
  • Return twapPrice, spotPrice, windowLedgers, and snapshotCount in the response
  • Cache the response in Redis for 60 seconds and invalidate on each trade
  • Return null for twapPrice when fewer than 2 snapshots exist in the window

Acceptance Criteria

  • twapPrice computed correctly for each window
  • spotPrice included alongside twapPrice
  • null returned for twapPrice when insufficient snapshots exist
  • Redis cache invalidated after each trade
  • Invalid window param returns 422

ETA: 12 hours


Coordinate on Telegram

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions