Setting a Stop Loss
Once a position is successfully opened via the solver’s instant trading API, it's worth setting a stop loss to protect that position. This ensures risk is bounded even if the bot goes offline or market conditions change unexpectedly.
High-Level Flow
Authenticate with the Hedger API (SIWE login)
Open an instant market position
Let the temporary quote ID resolve into a permanent
quoteIdCalculate the stop-loss price
Submit a stop-loss request to the solver API
⚠️ A stop loss must reference a permanent
quoteId. You cannot attach SL/TP to a temporary quote.
Authentication (SIWE Login)
Before any protected actions (open, stop loss, cancel, etc.), the bot must authenticate using Sign-In With Ethereum (SIWE).
Fetch a nonce from the hedger
Build a SIWE message scoped to the active trading account
Sign the message with the owner wallet
Exchange the signature for a JWT access token
token = login()The returned access_token is used as a Bearer token for all subsequent requests.
Opening the Position (Instant Open)
The bot opens a position using the solver’s instant_open endpoint.
Key points:
Orders must be market orders (
orderType = 1)The price is derived from the Muon Oracle
Slippage is applied to guarantee execution
Collateral parameters are calculated using
get_locked_params
Returned Values
temp_quote_id: Temporary identifier for the orderopen_price: The raw Muon price used to derive SL/TP levels
Resolving the Temporary Quote ID
Instant trades initially return a temporary quote ID.
Before setting a stop loss, the bot must wait until this temp ID is finalized into a permanent quoteId.
This is done by polling the user’s active quotes:
Why This Is Required
Stop loss and take profit requests are validated against finalized on-chain quotes
Using a temp ID will result in rejection
Calculating the Stop Loss Price
Once the quote is confirmed, derives a stop-loss price relative to the entry price.
In this example:
The bot is LONG
Stop loss is set at 80% of entry price
Notes
Precision should match the symbol’s supported decimals
For SHORT positions, this logic would be inverted
Stop Loss Request Payload
The stop loss is submitted using the stop_loss endpoint.
Payload Structure
Field Explanation
userAddress
Wallet that signed the login message
accountAddress
Trading account (EOA or sub-account)
positionSide
0 = Long, 1 = Short
symbolId
Internal symbol identifier
requestedPrice
Original entry price
quoteId
Permanent quote ID
tpPrice
Leave empty if not setting TP
slPrice
Calculated stop loss price
timestamp
Client-side timestamp (ms)
Sending the Stop Loss Request
On success, the solver will acknowledge the stop loss and register it for on-chain execution when the trigger price is reached.
Complete Execution Flow
A full example implementation can be found in our SYMM SDK.
Last updated
