Data Structures

This document describes the data types used when interacting with the CLOB system.

Order

Represents an order returned by query functions.
FieldTypeDescription
useraddressWallet address that owns the order
iduint256Unique order identifier
quantityuint256Original order size in base currency units
filleduint256Amount already filled
priceuint256Limit price (scaled)
expiryuint256Expiration timestamp (0 = no expiry)
statusStatusCurrent order status
orderTypeOrderTypeLimit or Market
sideSideBuy or Sell
Useful calculations:
  • Remaining quantity: quantity - filled
  • Is active: status == Open || status == PartiallyFilled

PoolKey

Identifies a trading pair.
FieldTypeDescription
baseCurrencyaddressToken being traded
quoteCurrencyaddressToken used for pricing
Example pools:
BaseQuoteMarket
WETHUSDCETH/USDC
WBTCUSDCBTC/USDC
ARBWETHARB/ETH

TradingRules

Trading parameters for a pool, returned by getTradingRules().
FieldDescription
minTradeAmountSmallest executable trade
minAmountMovementQuantity tick size (orders must be multiples)
minPriceMovementPrice tick size (prices must be multiples)
minOrderSizeMinimum order size
maxOrderSizeMaximum order size (0 = unlimited)

Enums

Side

ValueDescription
Buy (0)Bid side - buying base currency
Sell (1)Ask side - selling base currency

OrderType

ValueDescription
Limit (0)Order with specified price
Market (1)Execute at best available prices

Status

ValueDescription
Open (0)Active, unfilled
PartiallyFilled (1)Active, partially filled
Filled (2)Completely filled
Cancelled (3)Cancelled by user

TimeInForce

ValueDescription
GTC (0)Good Till Cancel
IOC (1)Immediate or Cancel
FOK (2)Fill or Kill
PostOnly (3)Add liquidity only

STPMode

ValueDescription
None (0)Allow self-trades
CancelTaker (1)Cancel incoming order
CancelMaker (2)Cancel resting order
CancelBoth (3)Cancel both orders

QuoteResult

Returned by quote functions to preview trade execution.
FieldTypeDescription
expectedAmountOutuint256Expected output amount
totalQuoteAmountuint256Total quote currency involved
executionPriceuint256Execution price
avgExecutionPriceuint256Average execution price
priceImpactuint256Price impact in basis points
feeuint256Trading fee
executableboolWhether order can execute
messagestringStatus/error message
Usage:
QuoteResult memory quote = router.getQuote(
    baseCurrency,
    quoteCurrency,
    OrderType.Market,
    Side.Buy,
    1 ether,
    0
);

if (quote.executable) {
    uint256 minOut = quote.expectedAmountOut * 99 / 100;
    router.placeMarketOrder(pool, 1 ether, Side.Buy, user, minOut);
}

PriceVolume

Aggregated data at a price level.
FieldTypeDescription
priceuint256Price level
volumeuint256Total volume at this price
Usage:
// Get best bid
PriceVolume memory bestBid = router.getBestPrice(
    baseCurrency,
    quoteCurrency,
    Side.Buy
);

// Get order book depth
PriceVolume[] memory asks = router.getNextBestPrices(
    pool,
    Side.Sell,
    0,
    10
);

BatchOrder

Used for batch order placement.
FieldTypeDescription
poolPoolKeyTrading pair
priceuint256Limit price
quantityuint256Order size
sideSideBuy or Sell
timeInForceTimeInForceOrder duration

BatchOrderResult

Result of batch order operations.
FieldTypeDescription
orderIduint256Assigned order ID (0 if failed)
successboolWhether order succeeded
messagestringError message if failed