Skip to content

Order Manager (gRPC)

Every Order Manager operation is served over gRPC as well as HTTP, backed by the same Service wrapping Arc<OrderManagerImpl>.

Address: CLOB_GRPC_ADDR, default 127.0.0.1:50051. Definition: packages/order-manager/proto/order_manager.proto, code generated via build.rs.

RPCRequestResponse
InsertOrderNewOrderRequestOrderResponse
CancelOrderCancelOrderRequestCancelOrdersResponse
CancelOrdersCancelOrdersRequestCancelOrdersResponse
CancelAllCancelAllRequestCancelOrdersResponse
CancelOrdersForMarketCancelOrdersForMarketRequestCancelOrdersResponse
OrderSizeUpdateUpdateOrderSizeOrderSizeUpdateResponse
GetOrderbookOrdersFilterParamsOrderbookOrdersResponse
GetOrdersByValueRangeFilterParamsOrderbookOrdersResponse
GetOrderGetOrderRequestOrderView
GetTradesTradeParamsTradesResponse
GetLastTradeFilterParamsTradeSummary
GetOpenOrdersOpenOrderParamsOpenOrdersResponse
GetOpenOrderOpenOrderParamsOpenOrder
GetOrderBookSummaryGetOrderBookRequestOrderBookSummary
GetMarketsEmptyMarketsResponse
GetTokensEmptyTokensResponse
GetMarketDetailsGetMarketDetailsRequestMarketDetails
GetMarketDetailsByQuestionIdGetMarketDetailsRequestMarketDetails
IsOrderManagerReadyEmptyReadyResponse

Message field semantics match the HTTP shapes.

Each handler runs the synchronous manager call on the tokio runtime via block_in_place.

Rust callers embedding the crate have two direct entry points.

Channel-driven ingestion and the background listeners.

OperationSignature
newEventLoop::new(manager, market_updates_fetch_interval) -> EventLoop
startEventLoop::start() -> bool — idempotent; a second call returns false
send_new_orderEventLoop::send_new_order(NewOrder) -> Receiver<OrderResponse>
managerEventLoop::manager() -> &OrderManagerImpl
shutdownEventLoop::shutdown() — graceful, idempotent

start wires the pending-service callbacks, builds the books from the markets service, spawns three listen threads, and marks the manager ready.

Three background threads, not external endpoints:

  1. New orders — consumes NewOrderTasks, runs InsertOrder, replies on the task’s channel.
  2. Market updates — pulls the catalogue every fetch interval, creating, updating and deleting books.
  3. Game starts — consumes condition ids from the markets service and ejects pre-start orders.

Synchronous, run inline — what the network handlers call.

OperationSignatureResponse
Insertinsert_order(&NewOrder)OrderResponse
Cancelcancel_order(key, order_hash)CancelOrdersResponse
Cancel severalcancel_orders(key, hashes)CancelOrdersResponse
Cancel allcancel_all(key)CancelOrdersResponse
Cancel for marketcancel_orders_for_market(key, params)CancelOrdersResponse
Internal cancelinternal_cancel_orders(hashes)— (no owner check)
Size updateorder_size_update(&UpdateOrderSize)Result<(), ClobError>
Game-start ejectdelete_orders_on_game_start(condition_id)—
OperationResponse
get_orderbook_orders(Option<&FilterParams>)Vec<ProcessedOrder>
get_orders_by_value_range(&FilterParams)Vec<ProcessedOrder>
get_trades(&TradeParams)Result<Vec<TradeSummary>, ClobError>
get_last_trade(&FilterParams)Result<TradeSummary, ClobError>
get_open_orders(&OpenOrderParams)Result<Vec<OpenOrder>, ClobError>
get_open_order(&OpenOrderParams)Result<OpenOrder, ClobError>
get_order(order_id)Result<ProcessedOrder, ClobError> — book only
get_order_book(condition_id)Option<Arc<dyn Book>>
get_order_book_by_token_id(token_id)Option<Arc<dyn Book>>
markets()Vec<String>
sampling_markets()Vec<String>
tokens()Vec<String>
get_market_details(condition_id)Option<MarketDetails>
get_market_details_by_question_id(question_id)Option<MarketDetails>
is_order_manager_ready()bool

packages/ledger/proto/clob.proto. Default http://localhost:5000.

  • CreateOrder, UpdateOrder — validity-gated upserts
  • GetOrder, GetOrderBook, GetOrderBookByAssets
  • GetOpenOrders, GetOpenOrder
  • PostTrade, UpdateTrade
  • GetTrades, GetLastTrade, OrderExists
  • GetMarketsByEpoch, GetRewardEpochSamples

packages/executor/proto/clob.proto. Default http://localhost:6000.

  • Execute — validate → build → sign → send; returns the transaction signature.
ChannelProtocolPurpose
order-manager → ledgergRPCOrder/trade persistence and queries
order-manager → executorgRPCMatch execution (Execute)
executor → ledgergRPCTrade status (UpdateTrade)
executor → order-managergRPCFailure reconciliation (OrderSizeUpdate)
order-manager → markets-apiRESTCatalogue pulls, token → mint
executor → markets-apiREST(market_id, outcome_mint) per trade
ledger → Redisstream XADDThe notifications stream

→ Architecture