partitionQuotes
Split a flat quote list into active positions and resting/pending orders. Run this before groupQuotes — a limit order that has not filled is not part of a position and must not be folded into one.
import { partitionQuotes, groupQuotes, SubAccountIsolationType } from "@symmio/trading-core";
const { positions, pending } = partitionQuotes(quotes);
const groups = groupQuotes(positions, SubAccountIsolationType.MARKET_DIRECTION);isPendingOrder and isActivePosition are exported separately for callers that need the predicate rather than the split, and isActiveQuoteStatus tests a bare on-chain status.
Both classify an anchored row by its on-chain QuoteStatus — PENDING / LOCKED / CANCEL_PENDING is a resting order, OPENED / CLOSE_PENDING / CANCEL_CLOSE_PENDING / LIQUIDATED_PENDING is a position — falling back to lifecycle + order type only for a row that has no status yet. Terminal rows match neither and are dropped.
Do not substitute openQuantity > 0. That field is quantity − closedAmount, so a quote that never opened still
reports its full size: splitting on it files every resting LOCKED limit order under positions, where the only
action offered is a Close the protocol will reject. The state table on
QuoteStatus has what each row can actually do.
Parameters
The flat quote list.
Returns
PartitionedQuotes{ positions, pending }, each preserving input order.
isActiveQuoteStatus
Whether an on-chain QuoteStatus is an active position: OPENED, CLOSE_PENDING, CANCEL_CLOSE_PENDING or LIQUIDATED_PENDING — the same set isActivePosition uses for an anchored row. These are the only statuses whose pending funding is meaningful.
Unlike isActivePosition, it takes a known status and has no lifecycle fallback, so it never counts an optimistic or just-anchored row (quoteStatus still undefined) as a position. Use it to pick the quotes to pass to getQuotePendingFunding, whose view does not check status and returns a meaningless amount for a quote that was locked but never opened.
import { getQuotePendingFunding, isActiveQuoteStatus } from "@symmio/trading-core";
const quoteIds = quotes.flatMap((quote) =>
quote.quoteId !== undefined && quote.quoteStatus !== undefined && isActiveQuoteStatus(quote.quoteStatus)
? [quote.quoteId]
: [],
);
const rows = await getQuotePendingFunding(config, { quoteIds });Parameters
The quote’s on-chain status.
Returns
booleantrue for an active-position status, false for a resting order or a terminal status.