applyNotificationToQuotes
Apply a single notification to a list of UnifiedQuotes, returning a new list (pure — inputs are never mutated). This is the per-notification step reconcileQuotes runs internally over its notifications, exposed for consumers that fold notifications in themselves.
The notification is matched to a row by on-chain quote id, falling back to the pre-chain temp id — which is how an optimistic row gets linked to its on-chain quote (temp:<id> → onchain:<id>). On the matched row it:
- links
tempQuoteId↔quoteIdand rekeys the row once the on-chain id appears; - fills
openedPriceand advances toPRICE_FILLEDonInstantRFQsuccess; - advances to
WRITE_ONCHAINon an open-anchor (SendQuoteTransaction) success while the on-chain read has not caught up; - advances the close stage on a row already in the closing flow (or an off-chain row): the request →
CLOSE_PRICE_FILLED, the fill →WRITE_ONCHAIN_CLOSE, monotonically. A settled close (polled back toONCHAIN) is no longer in a closing stage, so replayed close notifications match nothing to advance and never re-stick it; - advances to
FAILEDonly for an anchored-but-unread row whose anchor reverted (origin === "onchain",raw.onchainabsent). A failed close on a confirmed position stays put (defers to the poll), and a failed open’s optimistic row just vanishes when the hedger drops it — failure is an event, not a durable state.
import { applyNotificationToQuotes } from "@symmio/trading-core";
const next = applyNotificationToQuotes(quotes, notification);Parameters
quotesUnifiedQuote[]requiredThe current unified rows.
nNotificationrequiredThe normalized notification to apply.
Returns
A new list with the matched row updated; the same list (by content) when nothing matched. Notifications are replayed every reconcile tick, so this is idempotent — applying the same notification twice never regresses a row.
Related
- reconcileQuotes — applies this over its
notificationsafter the source merge. - Notification — the input frame shape.
- QuoteLifecycle — the stages this advances through.
- classifyQuoteNotificationAction — classifies which flow a notification belongs to.