planGroupClose
Allocate an exact close quantity across a grouped position’s children.
Closing “2.8 of a 5-unit merged position” is not one call — it is a set of per-quote closes that must sum to the target exactly, while every partially closed child keeps at least the symbol’s dust floor. This planner produces that allocation or fails without closing anything; there is no partial-success middle ground, because a half-applied close leaves the trader with a position they did not ask for.
Largest child first, so the fewest quotes are touched.
import { toGroupCloseCandidates, planGroupClose } from "@symmio/trading-core";
const plan = planGroupClose(
toGroupCloseCandidates(group.quotes, market.minAcceptableQuoteValue),
parseUnits("2.8", 18),
);
if (!plan.feasible) return plan.reason; // "exceeds-open" | "nothing-to-close" | "dust-locked"Parameters
candidatesreadonly GroupCloseCandidate[]requiredFrom toGroupCloseCandidates.
targetQuantitybigintrequiredExact total to close across the group, wei.
Returns
PlanGroupCloseResult{ feasible: true, allocations } when the plan sums to the target exactly,
otherwise { feasible: false, reason, totalOpen, closeableQuantity } — where
closeableQuantity is the largest amount the group could close, for a UI cap.
Failure reasons
exceeds-openPlanGroupCloseFailureReasonThe target exceeds the group’s total open quantity.
nothing-to-closePlanGroupCloseFailureReasonNo candidate has open size, or the target is not positive.
dust-lockedPlanGroupCloseFailureReasonEvery remaining child sits at its dust cap — the exact target is unreachable.
Related
useCloseQuoteGroup— executes the plan in one bulk request with per-child progress.