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

  1. Fetch Markets (GET) To get a list of all the markets listed on Wasabi, query the v1/market/markets endpoint. This endpoint takes an optional chainId request parameter, which defaults to 1 for Ethereum mainnet, and returns a paginated list of Market objects. Note the marketId and maxLeverage of the desired market to use later.

  2. 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 (either LONG or SHORT), downPayment (in wei), and leverage (a number between 1.1 and maxLeverage). You can also provide a maxSlippage (in BPS, default is 50 or 0.5%) and a chainId (defaults to 1, should match the chain ID of the market). Returns a PerpQuoteResponseV2 object.

  3. 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 the v1/market/order/open endpoint with a PerpQuoteRequestV2 in the request body and an optional chainId. The quote request object consists of the marketId, side, downPayment, leverage, and optional properties maxSlippage, speedUp (a boolean, defaults to false), and payInType. PayInType is an enum, with values NATIVE, TOKENand VAULT, where NATIVE means paying in ETH (for pairs quoted in ETH only), TOKEN means paying in either WETH or USDC/USDB (depending on the market), and VAULT is for paying with vault deposits for the given quote token. Returns a PerpOrder object containing the OpenPositionRequest, Signature and FunctionCallData, where the latter contains the to address, wei value and encoded data for submitting the order onchain.

  4. 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.

  5. Fetch Positions (GET) Finally, to see the newly opened position, query the v1/market/positions endpoint with the request params address (of the trader), offset (optional, defaults to 0) and chainId (optional, defaults to 1, but should match the chain from previous steps). This returns a paginated list of PositionStatus objects, in descending order by positionId.

Closing a Position

Following these steps enables you to close positions and fetch position history

  1. Fetch Positions (GET) Same as fetching positions in the open process.

  2. Fetch Close Quote (GET) To get a close quote, query the v1/market/quote/close/{positionId}, with optional request params maxSlippage and chainId. Returns a CloseQuoteResponseV2 object.

  3. Fetch Close Position Request (POST) To submit the close order onchain, you will need a ClosePositionRequest and a signature. To get these, post to the v1/market/order/close/{positionId} with the optional request params maxSlippage, chainId and payoutType. PayoutType is an enum with the values WRAPPED, UNWRAPPED and VAULT_DEPOSIT, where the first two options only apply to ETH quote pairs, and the default is VAULT_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 a PerpOrder object containing the ClosePositionRequest, Signature and FunctionCallData.

  4. 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.

  5. Fetch History (GET) To see the PnL from closing the position, query the user/tradeHistory/{address} endpoint with the optional request params nextPageToken (defaults to 0), chainId and type, where type can be either OPEN, CLOSE or LIQUIDATE (CLOSEwould be appropriate). Returns a paginated list of PositionTradeHistoryResponse 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