WebSocket API

Page explains how to use Liquorice RFQ WebSocket API

1. Connecting to the Liquorice WebSocket API

Production: wss://api.liquorice.tech/v1/solver/ws

Provide the following headers in the WebSocket request

  • solver - name of the Solver

  • authorization - authorization token

WebSocket server sends Ping message every 30 seconds.

2. Sending RFQ

Whenever the solver needs a quote from Liquorice, it sends an RFQ to the system using the following message

{
  "messageType": "rfq";
  "message": {
    /// Chain ID, e.g for ArbitrumOne chainId = 42161
    chainId: number;
    /// UUID of the RFQ (Must be generated by caller to be able to match incoming RFQQuote message)
    rfqId: string;
    /// RFQ expiry UNIX timestamp (seconds)
    expiry: number,
    /// 0x-prefixed base token address
    baseToken: string;
    /// 0x-prefixed quote token address
    quoteToken: string;
    /// 0x-prefixed address of the account receiving quoteToken   
    trader: string;
    /// 0x-prefixed address of the account performing trade
    effectiveTrader: string;
    // (Exactly one of the following two fields will be present.)
    /// Number with up to 18 decimal places, e.g. 100000000 (1 WBTC)
    baseTokenAmount?: string;
    /// Number with up to 18 decimal places
    quoteTokenAmount?: string;
  };
}

Exactly one of the baseTokenAmount or quoteTokenAmount fields must be present. Having baseTokenAmount present equals to asking "How much ETH would I get if I pay 1000 USDC?" and having quoteTokenAmount equals to asking "How much USDC do I need to pay to get 1 ETH?"

3. Receiving Quote

The quote message will be sent within the same WebSocket connection that received the RFQ, using following format:

{
  "messageType": "rfqQuote",
  "message": {
    /// UUID of the RFQ
    rfqId: string;
    /// Quote expiry UNIX timestamp (seconds)
    quoteExpiry: number;
    /// 0x-prefixed address of the Liquorice market 
    market: string,
    /// Array of 0x-prefixed calldata strings 
    /// for the functions within Liquorice `market` contract
    interactions: string[];
    /// 0x-prefixed base token address
    baseToken: string;
    /// 0x-prefixed quote token address
    quoteToken: string;
    /// Number with up to 18 decimal places, e.g. 100000000 (1 WBTC)
    baseTokenAmount: string;
    /// Number with up to 18 decimal places
    quoteTokenAmount: string;
  }
}

4. Error handling

Errors will be sent within the same WebSocket connection using following format:

{
  "messageType": "error",
  "message": {
    /// Type of the error
    errorType: string;
    /// Error message
    message: string;
  }
}

Last updated