Skip to content

Add batch price endpoint for multiple assets in a single request #20

Description

@prodbycorne

Overview

Clients frequently need prices for multiple assets at once. The current API requires one request per asset causing N round-trips. A batch endpoint reduces this to one call and allows parallel oracle fetches server-side.

Endpoint

POST /api/v1/prices/batch
Content-Type: application/json

{ "assets": [
    { "code": "XLM" },
    { "code": "USDC", "issuer": "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" }
] }

Response:

{
  "results": {
    "XLM":       { "price_usd": 0.112, "source": "stellar_dex", "is_stale": false },
    "USDC:GA5Z...": { "price_usd": 1.0002, "source": "coingecko",  "is_stale": false }
  },
  "fetched_at": "2024-01-15T10:30:00Z"
}

Requirements

  • Maximum 50 assets per request (Zod validation)
  • All assets fetched in parallel via Promise.allSettled
  • A single asset failure does not fail the whole batch — it appears with price_usd: null
  • Separate rate limit: 10 batch requests per minute per IP
  • Response key format: CODE for native, CODE:ISSUER for issued assets

Acceptance Criteria

  • POST /api/v1/prices/batch implemented
  • Parallel fetches using Promise.allSettled
  • Zod: max 50 assets, valid code (1-12 chars) and issuer (G-address)
  • Partial failures included in response without 500
  • Tighter rate limit applied to batch endpoint
  • Integration tests: single, multiple, partial-failure
  • Documented in OpenAPI spec

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignapiREST API design and endpointsperformancePerformance improvements

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions