Skip to content

glacez-soa-worker

Lane: backend · Repo: glacez/glacez-soa-worker · Editing rules: Glacez/SOAs/glacez-soa-worker/AGENTS.md

The only service that talks to an exchange. Everything that must reach a venue — a trade, a withdrawal, a balance read — arrives here as an MQ job.

Responsibility

Consumer Queue Does
TradingJobConsumer glacez.trading.queue place and cancel orders through the exchange client
EmailJobConsumer glacez.emails.queue send notifications
RecordJobConsumer glacez.records.queue import balances, transfers, closed orders, spot and earn records

Plus a Feign-triggered import path (/jobs/records/import/*, /jobs/exchange-info/import) the cron uses.

The record collections this service writes are the exchange's statement of a user's activity — turning them into transactions is core's job, not this one's. See Transaction lifecycle.

It does not own: strategy logic (core), portfolio math (portfolio), the user-facing API (webservice). It does not decide whether to trade — it executes what core queued.

Exchange coverage

Through glacez-lib-exchanges only (never XChange directly): Binance, Kraken, Kucoin, Bitstamp as CEX; Etherscan for Ethereum and Arbitrum wallets. That library exposes one client per credential type with four services — account, records, trading, withdrawal. Adding a venue is a credential type plus four implementations in the library, then nothing here.

glacez-lib-exchanges is the platform's only XChange consumer (see ADR-002).

Data it writes

Credential (state observed from the venue), Order, Transfer, TransactionTrack, the five record types (RecordOrder, RecordTransfer, RecordSpot, RecordEarn, RecordFile), ExchangeInfo, Event.

Failure semantics

A job whose handler throws is acked, not requeued — no dead-letter queue, no redelivery. A failed placement stays failed until the next import or a human re-triggers it, and a record import that failed is only visible through the missing rows and the log. This is platform-wide behaviour, not a worker defect: see Communication.

A failed order or transfer is reported as CANCELED. Transaction.Status has no FAILED, so a placement that never reached the venue ends CANCELED on the document and in the status event — which is what the UI badge and the email say. The truthful record is the TransactionTrack event FAILED carrying the venue's own message. Deliberate, not an oversight: a distinguishable FAILED would be a glacez-lib-model value plus a webapp mapping and a consumer release wave, never a worker-local change.

The order path does not probe connectivity. XchangeClient.newClient(credential) is the single credential-to-client step and the venue call's own error is the answer; an explicit connectivity check lives on the credential endpoints (GET /credentials/{credentialId}/check-connexion → CredentialService.canConnectToExchangeOrErrorMsg), which is where an operator asks that question.

A dead venue does not stop the balances we derive ourselves. WalletRecordService.importLatestRecords runs two independent legs: the wallet import (transfers, closed orders, spot and earn from the wallet provider) and the generation of the balance rows from our own RecordTransfer/RecordOrder documents. Each fails and logs on its own, so a venue outage still regenerates the derived balances, and the last venue-read ETH balance is kept rather than zeroed.

A venue failure names its reason. Every provider call goes through HttpRetrier (glacez-lib-exchanges): it retries 429, 5xx and timeouts (honouring Retry-After), fails fast on the rest, and the thrown message carries the HTTP status plus the provider's own message — so a refused provider account reads with its own words rather than a bare "after 3 attempts".

Jobs

Endpoint ctlq prod
/jobs/records/import/credentials/latest every 3 h every 5 min
/jobs/records/import/wallets/latest daily 04:30 every 50 min
/jobs/records/import/closed-orders daily 08:38 daily 03:38
/jobs/exchange-info/import every 3 days daily 08:00

The prod cadence is what keeps balances and closed orders close to real time; ctlq is deliberately slow to spare the venues and the quota.