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.

Chain Info

  • ETH Mainnet

    • Chain ID: 1

  • Base:

    • Chain ID: 8453

  • Solana:

    • Chain ID: 900

  • Blast:

    • Chain ID: 81457

  • Berachain

    • Chain ID: 80094

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. You can provide:

    • chainId (defaults to 1 for Ethereum mainnet).

    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 (with decimals, e.g. for 1 ETH use "1000000000000000000" and for 1 USDC use "1000000", the decimals can be obtained from the market quote token),

    • leverage (a number between 1.1 and maxLeverage of the market)

    You can also provide:

    • maxSlippage (in BPS, the default is 50 or 0.5%)

    • 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, query the v1/market/order/open endpoint. The required request params are:

    • marketId,

    • side (either LONG or SHORT),

    • downPayment (with decimals, e.g. for 1 ETH use "1000000000000000000" and for 1 USDC use "1000000", the decimals can be obtained from the market quote token)

    • leverage (a number between 1.1 and maxLeverage).

    You can also provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market)

    • payInType (an enum with values NATIVE, TOKEN, and 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) Use the FunctionCallData returned with the order in the previous step and send a transaction with the values provided. (to: address to send, data: the transaction data, value: native gas value to send (should be 0 if not paying with native gas token, ie ETH)

  5. Fetch Positions (GET) Finally, to see the newly opened position, query the v1/market/positions endpoint. The required request params are:

    • address (of the trader).

    You can also provide:

    • offset (defaults to 0)

    • chainId (defaults to 1, but should match the chain from previous steps).

    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} endpoint. You can provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market).

    Returns a CloseQuoteResponseV2 object.

  3. Fetch Close Position Request (POST) To submit the close order onchain, query the v1/market/order/close/{positionId} endpoint. You can provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market)

    • payoutType (an enum with 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) Use the FunctionCallData returned with the order in the previous step and send a transaction with the values provided. (to: address to send, data: the transaction data, value: native gas value to send (should be 0 if not paying with native gas token, ie ETH)

  5. Fetch History (GET) To see the PnL from closing the position, query the user/tradeHistory/{address} endpoint. The required request params are:

    • address (of the trader).

    You can also provide:

    • nextPageToken (defaults to 0)

    • chainId (defaults to 1, should match the chain ID of the market)

    • type (can be either OPEN, CLOSE, or LIQUIDATE, where CLOSE would 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.

Increasing Size of an Existing Position

Following these steps allows you to increase the size of a position and fetch positions

  • Fetch Markets (GET) To get a list of all the markets listed on Wasabi, query the v1/market/markets endpoint. You can provide:

    • chainId (defaults to 1 for Ethereum mainnet).

    Returns a paginated list of Market objects. Note the marketId and maxLeverage 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 (either LONG or SHORT),

    • downPayment (with decimals, e.g. for 1 ETH use "1000000000000000000" and for 1 USDC use "1000000", the decimals can be obtained from the market quote token)

    • leverage (a number between 1.1 and maxLeverage).

    • addToPosition (True), addToPosition defaults to False

      • If not set in the params, it will create a new position

    You can also provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market).

    Returns a PerpQuoteResponseV2 object.

  • Fetch Open Order (POST) To submit the open order onchain, query the v1/market/order/open endpoint. The required request params are:

    • marketId,

    • side (either LONG or SHORT),

    • downPayment (with decimals, e.g. for 1 ETH use "1000000000000000000" and for 1 USDC use "1000000", the decimals can be obtained from the market quote token)

    • leverage (a number between 1.1 and maxLeverage).

    • addToPosition (True), addToPosition defaults to False

      • If not set in the params, it will create a new position

    You can also provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market)

    • speedUp (a boolean, defaults to false)

    • payInType (an enum with values NATIVE, TOKEN, and 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.

  • Submit Order (Onchain) Use the FunctionCallData returned with the order in the previous step and send a transaction with the values provided. (to: address to send, data: the transaction data, value: native gas value to send (should be 0 if not paying with native gas token, ie ETH)

  • Fetch Positions (GET) Finally, to see the newly opened position, query the v1/market/positions endpoint. The required request params are:

    • address (of the trader).

    You can also provide:

    • offset (defaults to 0)

    • chainId (defaults to 1, but should match the chain from previous steps).

    Returns a paginated list of PositionStatus objects, in descending order by positionId.

Decreasing Size of an Existing Position

Following these steps enables you to decrease size of a position 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} endpoint. You can provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market).

    • amount (defaults to 0 Specifies the quantity of the position to close, using collateral in longs and principal in shorts in decimals. If set to 0, the entire position will be closed. For longs, provide the amount of position collateral to close; for shorts, provide the amount of position principal to close.)

    Returns a CloseQuoteResponseV2 object.

  3. Fetch Close Position Request (POST) To submit the close order onchain, query the v1/market/order/close/{positionId} endpoint. You can provide:

    • maxSlippage (in BPS, default is 50 or 0.5%)

    • chainId (defaults to 1, should match the chain ID of the market)

    • amount (defaults to 0 Specifies the quantity of the position to close, using collateral in longs and principal in shorts in decimals. If set to 0, the entire position will be closed. For longs, provide the amount of position collateral to close; for shorts, provide the amount of position principal to close.)

    • payoutType (an enum with 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) Use the FunctionCallData returned with the order in the previous step and send a transaction with the values provided. (to: address to send, data: the transaction data, value: native gas value to send (should be 0 if not paying with native gas token, ie ETH)

  5. Fetch History (GET) To see the PnL from closing the position, query the user/tradeHistory/{address} endpoint. The required request params are:

    • address (of the trader).

    You can also provide:

    • nextPageToken (defaults to 0)

    • chainId (defaults to 1, should match the chain ID of the market)

    • type (can be either OPEN, CLOSE, or LIQUIDATE, where CLOSE would 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