Publishing Price Levels
Publishing Price Levels
To receive RFQs, the Market Maker must publish Price Levels (or indicative quotes) to the API. These updates should be sent every second for each supported pair.
The published levels must include both the BUY and SELL sides within the same message. All prices are specified to the same market (e.g., ETH/USDC) for both directions.
Event: message
message
The message
event with messageType
"priceLevels"
is used to communicate pricing levels for a specific market pair. This event provides details about the buy and sell orders available on the market.
priceLevels
Message Schema
priceLevels
Message SchemaThe priceLevels
message schema ensures that the data structure sent through the WebSocket adheres to the required format. Below is the detailed schema and description for the priceLevels
message.
The priceLevels
message contains the following fields:
Buy and Sell Levels Requirements
Buy Level: Indicates that the market maker is buying the baseToken, and the trader is selling it.
Sell Level: Indicates that the market maker is selling the baseToken, and the trader is buying it.
Levels are presented as an ordered list, showing the quantities available at specific prices, incrementally. The first level also represents the smallest quantity the market maker is willing to trade. If the market maker can accept arbitrarily small orders, the first level should have a quantity of 0 and the price of the next level.
To send price levels for all sources, set the source field to null or omit it entirely (this field is optional).
Submitting only one level will be rejected by the API.
Sending an empty list of levels for either BUY or SELL signifies that no trades are available in that direction. This approach is also recommended for gracefully disconnecting from the WebSocket.
Let's look at the following example for a ETH/USDC
pair on Ethereum:
Suppose the trader wanted to swap 1.2 ETH
for USDC
. In this case, the maker would be selling 0.1 ETH
at 1600.00
, another 1 ETH
at 1600.00
, and up to another 0.5 ETH
at 1599.00
. If the trader were to make an RFQ, they would get 0.1 * 1600.00 + 1 * 1600.00 + 0.1 * 1599.00
, which is 1919.9 USDC
If the trader wanted to swap 0.05 ETH
instead, the maker would not be able to honor the quote, as 0.1
is the minimum amount (first level).
On the other hand, the trader wanted to swap 2000 USDC for ETH
. We know the market maker is selling 1 ETH
for 1601.00
, and up to another 1 ETH
for 1602.00
. The trader would spend 1601 USDC
at the 1601.00
price point to get 1 ETH
, and then another 399 USDC
at the 1602.00
price to get 0.24906367041 ETH
. Therefore, the RFQ would yield 1.24906367041 ETH.
In the case of swapping USDC
for ETH
, the trader could swap any small amount (e.g. 0.1 USDC
), because the first level has a quantity of 0
Example: Connecting to the Socket and Publishing Price Levels
The code snippet below demonstrates how to connect to the socket server and publish price levels. You can adjust each price level according to your specific needs, such as the asset pair, price, and quantity.
The vaultAddress
parameter is used for integrating with the X Vault. If you do not wish to use the X Vault, you can omit or skip this parameter.
Last updated