API Integration
Access the API endpoints for seamless integration into Wasabi’s trading protocols.
API Endpoint Details: https://api.wasabi.xyz/swagger-ui/index.html
Note: All endpoints require an API key. To obtain a key, include X-API-KEY
in your request headers and contact us to request access.
Opening a Position
Following these steps allows you to open and fetch positions
Fetch Markets (GET) To get a list of all the markets listed on Wasabi, query the
v1/market/markets
endpoint. This endpoint takes an optionalchainId
request parameter, which defaults to1
for Ethereum mainnet, and returns a paginated list ofMarket
objects. Note themarketId
andmaxLeverage
of the desired market to use later.Fetch Open Quote (GET) To get a quote for opening the position, query the
v1/market/quote/open
endpoint. The required request params are:marketId
,side
(eitherLONG
orSHORT
),downPayment
(in wei), andleverage
(a number between1.1
andmaxLeverage
). You can also provide amaxSlippage
(in BPS, default is50
or0.5%
) and achainId
(defaults to1
, should match the chain ID of the market). Returns aPerpQuoteResponseV2
object.Fetch Open Order (POST) To submit the open order onchain, you will need an
OpenPositionRequest
and a signature from our order signer. To get these, post to thev1/market/order/open
endpoint with aPerpQuoteRequestV2
in the request body and an optionalchainId
. The quote request object consists of themarketId
,side
,downPayment
,leverage
, and optional propertiesmaxSlippage
,speedUp
(a boolean, defaults tofalse
), andpayInType
.PayInType
is an enum, with valuesNATIVE
,TOKEN
andVAULT
, whereNATIVE
means paying in ETH (for pairs quoted in ETH only),TOKEN
means paying in eitherWETH
orUSDC/USDB
(depending on the market), andVAULT
is for paying with vault deposits for the given quote token. Returns aPerpOrder
object containing theOpenPositionRequest
,Signature
andFunctionCallData
, where the latter contains theto
address,wei
value and encoded data for submitting the order onchain.Submit Order (Onchain) With the
FunctionCallData
returned with the order in the previous step, you can now send a transaction to either the long or short pool contract on the appropriate chain.Fetch Positions (GET) Finally, to see the newly opened position, query the
v1/market/positions
endpoint with the request paramsaddress
(of the trader),offset
(optional, defaults to0
) andchainId
(optional, defaults to1
, but should match the chain from previous steps). This returns a paginated list ofPositionStatus
objects, in descending order bypositionId
.
Closing a Position
Following these steps enables you to close positions and fetch position history
Fetch Positions (GET) Same as fetching positions in the open process.
Fetch Close Quote (GET) To get a close quote, query the
v1/market/quote/close/{positionId}
, with optional request paramsmaxSlippage
andchainId
. Returns aCloseQuoteResponseV2
object.Fetch Close Position Request (POST) To submit the close order onchain, you will need a
ClosePositionRequest
and a signature. To get these, post to thev1/market/order/close/{positionId}
with the optional request paramsmaxSlippage
,chainId
andpayoutType
.PayoutType
is an enum with the valuesWRAPPED
,UNWRAPPED
andVAULT_DEPOSIT
, where the first two options only apply to ETH quote pairs, and the default isVAULT_DEPOSIT
, meaning the trader’s payout is deposited into the vault corresponding to the quote token on their behalf, earning the trader LP points and yield. Returns aPerpOrder
object containing theClosePositionRequest
,Signature
andFunctionCallData
.Submit Order (Onchain) With the
FunctionCallData
returned with the order in the previous step, you can now send a transaction to either the long or short pool contract, depending on the position side, on the appropriate chain.Fetch History (GET) To see the PnL from closing the position, query the
user/tradeHistory/{address}
endpoint with the optional request paramsnextPageToken
(defaults to0
),chainId
andtype
, wheretype
can be eitherOPEN
,CLOSE
orLIQUIDATE
(CLOSE
would be appropriate). Returns a paginated list ofPositionTradeHistoryResponse
objects, which contain data from the event emitted by the contract, e.g.PositionClosed
. PnL in wei is:response.position.downPaymentRaw - response.data.payout
.
Last updated