Writing a λ program
A λ program has a predicate and program parameters (lr_params). When the predicate is met, the λ program fires, i.e. places its underlying order by sending it to the on-chip matching engine. The program parameters adjust program behavior and may, for example, resize the underlying order. See the REST API reference for a full guide to λ program fields and enums.
Predicate
Section titled “Predicate”index_data
Section titled “index_data”index_data selects which market data events the predicate evaluates; so named because it is used to index into the λ book where λ programs are stored.
match_data
Section titled “match_data”match_data describes the market signal that a λ program responds to.
A market data event triggers the λ program only if every relevant condition is met:
| Condition | Data | Fields | Satisfied when |
|---|---|---|---|
| Event type | index_data |
pred_type |
The event added liquidity (LIQ_ADD) or removed it (LIQ_RMD). |
| Market | index_data |
market_id |
The event is in this market. |
| Side | index_data |
pred_side |
The event is on this side of the book (ASK or BID). |
| Price | match_data |
min_ticksmax_ticksticks_type |
Event price from min_ticks to max_ticks inclusive, as an absolute price (ABS_TICKS) or relative to the top of book (DELTA_GT_BEST_ASK, DELTA_LT_BEST_BID). |
| Quantity | match_data |
min_qtymax_qtyqty_type |
Event quantity from min_qty to max_qty inclusive, as the level’s quantity after the event (LEVEL_QTY) or the event’s change in quantity (DELTA_QTY). |
| Event qualifier | match_data |
pred_qual |
Applies to LIQ_RMD only: a trade (EX), a cancel (CX), a trade whose remainder rests (XA), or any of these (ANY). |
λ programs do not trigger on events caused by orders they placed.
Program parameters
Section titled “Program parameters”Program parameters adjust how the underlying order is placed when the predicate is met. Today, a λ program places its whole order once (ENTIRE), or, with a LIQ_RMD predicate, the quantity each triggering event removed (DELTA_QTY_RMD); the order is placed at its own limit price. More program parameters are planned.
Example
Section titled “Example”Suppose a trader has a resting bid for 0.01 BTC (1,000,000 qty) at 99,990 ticks on BTC-USDC and views a large sell just above that bid as a potential signal the price will keep falling. They place a λ program that cancels the bid if a single taker order removes 0.5 BTC (50,000,000 qty) or more from the bids and its deepest level reached is between 99,995 and 100,000 ticks.
| Part | Field | Value | Meaning |
|---|---|---|---|
| Index data | market_id |
1 | BTC-USDC. |
| Index data | pred_side |
BID |
Watch the bid side. |
| Index data | pred_type |
LIQ_RMD |
Liquidity removed. |
| Match data | pred_qual |
EX |
Trades only. |
| Match data | ticks_type |
ABS_TICKS |
Absolute price. |
| Match data | min_ticksmax_ticks |
99,995 100,000 |
Price range. |
| Match data | qty_type |
DELTA_QTY |
Quantity removed by the event. |
| Match data | min_qtymax_qty |
50,000,000 10,000,000,000 |
0.5 BTC to 100 BTC. |
| Order | market_id |
1 | BTC-USDC. |
| Order | side |
BID |
The resting bid’s side. |
| Order | ticks |
99,990 | The resting bid’s price. |
| Order | qty |
−1,000,000 | Cancel 0.01 BTC. |
| Order | tif |
IOC |
Cancels are IOC. |
| Program parameters | lr_qty_type |
ENTIRE |
Fire once. |
| Program parameters | lr_ticks_type |
TICKS_ABS |
Place at the order’s own price. |
| Request | client_lambda_id |
protect-bid-99990 |
Optional user-supplied id. |
Request JSON
{ "lambda_program": { "predicate": { "index_data": { "market_id": "1", "pred_side": 2, // BID "pred_type": 2 // LIQ_RMD }, "match_data": { "pred_qual": 2, // EX: trades only "ticks_type": 1, // ABS_TICKS "min_ticks": 99995, "max_ticks": 100000, "qty_type": 2, // DELTA_QTY: quantity removed "min_qty": "50000000", // 0.5 BTC "max_qty": "10000000000" // 100 BTC } }, "order": { // Cancel 0.01 BTC of the bid at $99,990 "market_id": "1", "side": 2, // BID "ticks": 99990, "qty": "-1000000", // -0.01 BTC "tif": 1, // IOC "is_leverage": false }, "lr_params": { "lr_qty_type": 1, // ENTIRE: fire once "partial_qty": "0", "lr_ticks_type": 1 // TICKS_ABS } }, "client_lambda_id": "protect-bid-99990"}Regulated services provided by 1Money USA, Inc., a licensed money transmitter, NMLS ID 2628653 · Licenses