Skip to content

ADR-002: Exchange access only from worker, behind glacez-lib-exchanges

Status: Accepted (origin not recorded; documented 2026-11-06)

Context

Glacez talks to many crypto exchanges (Binance, Kraken, Bitstamp, Coinbase and others) through XChange. The client library needs API keys, per-exchange quirks, rate limits and error handling that differ per venue. Three services had a plausible reason to reach an exchange: webservice (immediate user-facing action), core (strategy synchronization) and worker (execution).

Decision

Only glacez-soa-worker performs exchange operations. It does so through glacez-lib-exchanges, the only module in the workspace that depends on XChange.

  • No service in the platform imports org.knowm.* directly; the wrapper is the boundary.
  • Any user-facing "do it now" action is dispatched to worker over RabbitMQ, never executed inline.
  • Adding an exchange capability means extending the library and worker — not adding a client to the service that needs it.

Alternatives considered

  • Call the exchange from webservice for immediate feedback. Rejected: it would duplicate credentials handling, put network flakiness on the user request path, and create a second execution path that the synchronization logic does not know about.
  • One client per service, shared config. Rejected for the same reason plus rate-limit coordination across processes.
  • Keep XChange calls in glacez-lib proper. Rejected: the library is consumed by every SOA, so a dependency there grants exchange access to all of them by construction.

Consequences

  • Exchange-shaped features always have two halves: a job dispatched from webservice/core, and the worker handler that executes it.
  • glacez-lib-exchanges carries the venue knowledge; glacez-soa-worker carries the lifecycle (state, records, events).
  • xchange.version resolves to upstream knowm/XChange, not to the glacez-lib-xchange fork — verified from the resolved artifact's POM. glacez-lib-xchange exists as a fork/PR target and is not currently consumed by any service.
  • glacez-soa-simulator still declares glacez-lib-exchanges without using it (a stale dependency, tracked in its own backlog). A declared dependency is not evidence that a service talks to exchanges — check the imports.