setQuoteTpSl
Submit a TP and/or SL order to the handler. Accepts one or both sides in a single call. Internally: resolves the handler URL + signing spec, rounds trigger prices and derives slippage-shifted fill prices via priceSlippageCalculation, builds a TpSlConditionalOrderMessage with non-null legs only, signs it with the session-key wallet client, and POSTs { typedData, signature, signer }.
The handler returns 200 on accept, but the order is only “confirmed” once the WebSocket reports state: "new" and successful: true. Callers should subscribe via watchTpSlNotifications and reconcile — the React layer does this automatically.
import { setQuoteTpSl } from "@symmio/trading-core";
const { cohQuoteId } = await setQuoteTpSl(config, {
from: sessionKey,
quoteId: 42n,
virtualAccount,
subAccount,
symbolId: 7n,
positionType: PositionType.LONG,
quantity: "100",
pricePrecision: 4,
tp: { triggerPrice: "150", priceType: "markPrice" },
sl: { triggerPrice: "80", priceType: "markPrice" },
});Parameters
quoteIdbigintrequiredOn-chain quote id (or a negative tempQuoteId for a pre-chain instant open).
virtualAccountAddressrequiredPartyA (the VA address) that owns the quote.
subAccountAddressrequiredSubAccount that owns the VA.
symbolIdbigintrequiredSolver market id.
positionTypePositionTyperequiredQuote direction (LONG / SHORT).
quantitystringrequiredQuote quantity (decimal string).
pricePrecisionnumberrequiredMarket price precision (rounds prices to N decimals).
Take-profit side. Omit to skip TP.
Stop-loss side. Omit to skip SL.
affiliateAddressoptionalAffiliate to bind to the order. Defaults to chainConfig.addresses.affiliatesAddress.
slippagenumberoptionalSlippage percent applied when deriving each leg’s fill price. Defaults to DEFAULT_TPSL_SLIPPAGE_LOWCAPS (90).
fromAddressoptionalSession-key signer the wallet client resolves for. Defaults to the connected wallet in the React layer.
chainIdnumberoptionalTarget chain id. Defaults to the config’s defaultChainId.
At least one of tp or sl must be provided.
Returns
SetQuoteTpSlReturnTypesuccesstrueAlways true on a resolved call (failures throw).
cohQuoteIdstringoptionalHandler-issued conditional-order id, when reported on the response.
Throws
SymmErrorwhen the chain has notpslconfig, bothtpandslare omitted, or signing fails.SymmApiErrorwhen the handler request fails.
Mutation options
import { setQuoteTpSlMutationOptions } from "@symmio/trading-core";
import { useMutation } from "@tanstack/react-query";
useMutation(setQuoteTpSlMutationOptions(config));setQuoteTpSlMutationOptions returns { mutationKey, mutationFn }; the mutationFn takes the same parameters object as the action.
Related
SetTpSlSide— the per-side input shape.watchTpSlNotifications— the confirmation stream.useSetQuoteTpSl/useInstantOpenWithTpSl— React bindings.