No seam for fetching rates from an outside source #49

Closed
opened 2026-08-18 00:39:12 +00:00 by rosa · 1 comment
Owner

Problem

Rates come from outside — a central bank feed, a broker, a cached file — but
the crate names no interface for one. A caller that swaps feeds, or writes a
fake feed for a test, has nothing to write against.

The crate does no I/O and should keep it that way. HTTP and async belong in
the caller or in a companion crate.

Proposal

A RateProvider trait for looking up a rate, with Exchange as the offline
implementation over rates already in hand.

Open questions

  • What is the method? Handing back an ExchangeRate for a pair, or restating
    a Money directly?
  • One error type for the trait, or an associated one per implementation? A
    network feed fails in ways a table does not.
  • The trait is synchronous, so an async feed has to fill an Exchange and
    implement the trait over that cache. Is that shape enough for a real caller,
    or does the trait need to admit failure that is worth retrying?
  • Does a trait with one implementation inside the crate earn its place yet, or
    should it wait until a companion crate needs it? Writing it early fixes a
    shape before anything has pushed on it.

Out of scope

Triangulation, dated rates, and two-sided quotes. Each is its own issue.

## Problem Rates come from outside — a central bank feed, a broker, a cached file — but the crate names no interface for one. A caller that swaps feeds, or writes a fake feed for a test, has nothing to write against. The crate does no I/O and should keep it that way. HTTP and async belong in the caller or in a companion crate. ## Proposal A `RateProvider` trait for looking up a rate, with `Exchange` as the offline implementation over rates already in hand. ## Open questions - What is the method? Handing back an `ExchangeRate` for a pair, or restating a `Money` directly? - One error type for the trait, or an associated one per implementation? A network feed fails in ways a table does not. - The trait is synchronous, so an async feed has to fill an `Exchange` and implement the trait over that cache. Is that shape enough for a real caller, or does the trait need to admit failure that is worth retrying? - Does a trait with one implementation inside the crate earn its place yet, or should it wait until a companion crate needs it? Writing it early fixes a shape before anything has pushed on it. ## Out of scope Triangulation, dated rates, and two-sided quotes. Each is its own issue.
Author
Owner

This was generated by AI during triage.

Closing as out of scope, recorded in
.out-of-scope/rate-provider-trait.md.

The short version, taking the open questions in order:

  • Does the trait earn its place yet? No. Nothing in the crate takes a rate
    source as a parameter, so the trait would have one implementation and no
    caller.
  • What is the method? Undecidable today. Since #48 landed, the two types
    that would implement it read differently: desk.rate(pair) against
    past.rate(moment, pair). One signature does not cover both.
  • Is the synchronous shape enough? It does not reach the source it is named
    for. The crate does no I/O, so an async feed fills an Exchange and the trait
    sits over the cache, one call short of the feed itself.
  • One error type or an associated one? A table's lookup cannot fail; a feed's
    can. Neither answer can be checked against a real implementation yet.

Worth revisiting when a companion feed crate exists. Orphan rules make lucre
the only crate that can define a trait such a feed and an application both name,
and at that point the shape has something real pushing on it.

> *This was generated by AI during triage.* Closing as out of scope, recorded in [`.out-of-scope/rate-provider-trait.md`](../src/branch/main/.out-of-scope/rate-provider-trait.md). The short version, taking the open questions in order: - **Does the trait earn its place yet?** No. Nothing in the crate takes a rate source as a parameter, so the trait would have one implementation and no caller. - **What is the method?** Undecidable today. Since #48 landed, the two types that would implement it read differently: `desk.rate(pair)` against `past.rate(moment, pair)`. One signature does not cover both. - **Is the synchronous shape enough?** It does not reach the source it is named for. The crate does no I/O, so an async feed fills an `Exchange` and the trait sits over the cache, one call short of the feed itself. - **One error type or an associated one?** A table's lookup cannot fail; a feed's can. Neither answer can be checked against a real implementation yet. Worth revisiting when a companion feed crate exists. Orphan rules make `lucre` the only crate that can define a trait such a feed and an application both name, and at that point the shape has something real pushing on it.
rosa closed this issue 2026-08-22 14:45:22 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#49
No description provided.