Skip to content

Streaming API for quotes #4057

@MartinquaXD

Description

@MartinquaXD

Problem

Currently the quote API only returns a single result after the deadline is exceeded. This is suboptimal for a responsive UI as it can take ~5s to display a good quote. So far we worked around this in 2 ways:

  • offering a fast endpoint which returns a price early
  • allowing integrators to provide a timeout with their request

The fast price estimate comes with the downside of increased code complexity (multiple price estimator instance governed by different rules, extra config parameters, etc.). The timeout option still is not as responsive as it could be. In practice the baseline estimator will return a quote after a few 100ms at most so even if you have a relatively low timeout of 1s you are still waiting 5 times longer to display something than you need to.

Suggested solution

Rather than an all-or-nothing API that returns a single result we should offer an endpoint that streams requests as the estimators produce them. Since there is no 2 way communication needed server side events should be sufficient (as opposed to full web socket support).

In order to achieve this we need:

  • update the PriceEstimating and NativePriceEstimating trait with a streaming API (the current all-or-nothing API can probably use a default implementation that uses the streaming API under the hood - that should prevent us from updating tons of call sites at once)
  • a way to emit server side events (presumably axum has something for that)

Acceptance criteria

We have new endpoints for /quote and /native_price which stream results to the caller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions