PerpsHub TP/SL Implementation
Overview
The stop-loss/take-profit (SL/TP) system allows users to automatically close positions when the market price reaches specified trigger levels. The system continuously monitors mark prices and executes closes when conditions are met.
Base URL Pattern: /v1/:symmId/:multiaccount
All endpoints require the following path parameters:
symmId: Network/chain identifier (e.g., '56a', '5000a', '42161a', '8453a', etc.)multiaccount: Ethereum address of the multi-account contract
Endpoints
1. Create Stop Loss / Take Profit
Create or update a stop-loss and/or take-profit order for a specific position.
Endpoint:
POST /v1/:symmId/:multiaccount/stop_lossPOST /v1/:symmId/:multiaccount/stop-loss(kebab-case alternative)
Authentication: Required (Bearer token)
Request Body:
{
userAddress: string // Ethereum address of the user (0x...)
accountAddress: string // Ethereum address of the account/partyA (0x...)
positionSide: 0 | 1 // 0 = LONG, 1 = SHORT
symbolId: number // Numeric symbol identifier
requestedPrice: string // Requested open price (decimal string)
quoteId: number // Quote ID (positive for filled trades, negative for pending instant opens)
tpPrice: string // Take profit trigger price (decimal string, can be empty)
slPrice: string // Stop loss trigger price (decimal string, can be empty)
timestamp: number // Request timestamp in milliseconds
}Validation Rules:
At least one of
tpPriceorslPricemust be provided (non-empty)tpPriceandslPricecannot be equalFor LONG positions:
tpPricemust be ABOVE the current/estimated mark priceslPricemust be BELOW the current/estimated mark price
For SHORT positions:
tpPricemust be BELOW the current/estimated mark priceslPricemust be ABOVE the current/estimated mark price
Success Response (200 OK):
Error Responses:
400 Bad Request:
404 Not Found:
Notes:
If a stop-loss already exists for the trade in PENDING status, the request will be rejected
The system validates prices against the current mark price (for opened positions) or estimated fill price (for pending instant opens)
Prices are validated with slippage considerations
Example:
2. List Stop Losses / Take Profits
Retrieve stop-loss/take-profit orders for multiple quote IDs.
Endpoint:
POST /v1/:symmId/:multiaccount/list_slPOST /v1/:symmId/:multiaccount/list-sl-tp(kebab-case alternative)
Authentication: Not required
Request Body:
Success Response (200 OK):
Response Fields:
symmId: Network identifierquoteId: Quote/trade identifieruserAddress: User's addressaffiliate: Affiliate/multiaccount addresspartyA: Account address (partyA)tpPrice: Take profit trigger price (null if not set)slPrice: Stop loss trigger price (null if not set)timestamp: Creation timestampstatus: Order status ("pending","processing","executed","cancelled")positionSide: 0 = LONG, 1 = SHORTlastCheckedAt: Last time the order was checked by the systemsymbolName: Trading symbol (e.g., "BTCUSDT")
Error Response (400 Bad Request):
Example:
3. Cancel Stop Loss / Take Profit
Cancel the stop-loss and/or take-profit for a specific quote.
Endpoint:
POST /v1/:symmId/:multiaccount/cancel_slPOST /v1/:symmId/:multiaccount/cancel-sl-tp(kebab-case alternative)
Authentication: Required (Bearer token)
Request Body:
Validation Rules:
At least one of
cancelSlorcancelTpmust betrueThe stop-loss order must exist for the given quote
The stop-loss order must be in
PENDINGstatus (cannot cancel processing/executed orders)
Success Response (200 OK):
When canceling both:
When canceling only stop loss:
When canceling only take profit:
Error Responses:
400 Bad Request:
404 Not Found:
Notes:
If both
cancelSlandcancelTpare true (or if canceling the only remaining one), the entire stop-loss document is removedIf only one is canceled and the other remains, the document is updated with the remaining value
Partial cancellation is supported: you can cancel just SL or just TP while keeping the other active
Example:
Cancel both SL and TP:
Cancel only stop loss:
Stop Loss States
PENDING
Order is active and being monitored
PROCESSING
Trigger conditions met, execution in progress
EXECUTED
Order successfully executed
CANCELLED
Order cancelled by user
Authentication
Endpoints marked as requiring authentication must include a Bearer token in the Authorization header:
To obtain an access token, use the login endpoints:
POST /v1/:symmId/:multiaccount/login(for EVM wallets)POST /v1/:symmId/:multiaccount/tac-login(for TON wallets)
Common Error Codes
400
Invalid symmId
The symmId path parameter is not valid
400
Validation error
Request body validation failed
401
Invalid or missing credentials
Authentication token is missing or invalid
404
Trade not found
The specified quote ID does not exist
404
Stop loss not found
No stop-loss order exists for the quote
500
Internal server error
Unexpected server error
Last updated
