Skip to content

Add helper for computing the percentage change in a creator's key price over a configurable time window #643

Description

@Chucks1093

Summary

The creator detail and trending endpoints both need a price change percentage over different windows (1h, 24h, 7d). Each currently computes this differently with duplicated time window logic. A shared helper should accept a configurable window and return the percentage change for any creator.

Scope

  • Add computePriceChange(creatorId: string, windowMs: number, db: Database): Promise<number | null>
  • Fetch the oldest snapshot within the window and the latest snapshot; return null if fewer than two snapshots exist
  • Return the percentage change as a signed float rounded to two decimal places
  • Add unit tests: positive change, negative change, null when only one snapshot, null when no snapshots

Acceptance Criteria

  • Positive price change returns correct positive percentage
  • Negative price change returns correct negative percentage
  • Fewer than two snapshots returns null
  • Percentage rounded to two decimal places
  • Both creator detail and trending endpoints use the helper

ETA: 12 hours


Coordinate on Telegram

Metadata

Metadata

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