Skip to main content
A conditional sell sells one position, the leader, and as each leader share sells, Lean sells one share of every other position you name, the followers. Each follower has a floor price it never sells below. Use it to unwind positions that only make sense together, such as both sides of a hedge on two venues, without one side being left open. Conditional sells run on Kalshi, Polymarket, Polymarket US and Hyperliquid, and the legs may be on different venues. A leg naming lighter is refused with 422 and reason NO_EXECUTABLE_VENUE. This example uses a test key, so nothing real moves:
The key needs the trade scope. The answer is 200 with the conditional sell, which reads active while the leader sells or waits, or paused with pause_reason floor when a follower cannot sell at its floor yet.

How it sells

The leader sells first. Each time leader shares fill, Lean sells the same number of shares of every follower at the best bids down to that follower’s floor, and leaves any shares that do not sell at once resting at the floor. Each leg’s filled_quantity and avg_fill_price grow as it sells, and unhedged_quantity is the number of leader shares a follower has not matched yet. For a conditional sell led by a limit leader, Lean pauses it with pause_reason floor while a follower’s book does not hold enough shares at or above its floor to match the leader, or while a follower’s book cannot be read for 30 seconds before the leader is placed. A leader already resting on its venue stays live while a follower’s book cannot be read. It carries on by itself once every follower’s book has held enough at its floor for 5 seconds. A follower’s state is idle before it has anything to sell, selling while a sell works, retrying after a sell failed and another is on its way, below_minimum while the shares it owes are under the venue’s minimum order, failed once it runs out of retries, and done once it has sold every share it owes. A failed follower stays unsold until you retry it in the Lean app or sell it yourself. pause_reason is floor for a follower floor, user when the sell was paused in the Lean app, or one of leader_unconfirmed, leader_ended, leader_account_changed and leader_rejected when the venue did not confirm, ended or refused the leader order. A conditional sell paused for a reason that starts with leader_ waits for you: resume it in the Lean app, or cancel it.

Limits on what can be sold

  • Every leg, the leader included, is a different position the trading account holds. Each must hold quantity shares beyond what the account’s resting sells, stop losses and other conditional sells already cover, or the request is refused with 400 VALIDATION_ERROR.
  • With a live key, a follower whose market has no bid, or whose floor is above its best bid, does not refuse the request. A conditional sell led by a limit leader starts paused with pause_reason floor, and one led by a stop leader starts active. A test key refuses such a follower with 400 VALIDATION_ERROR.
  • A stop leader whose trigger is at or above its best bid, or whose market has no bid, is refused with 400 VALIDATION_ERROR.
  • Every leg’s market must be open, or the request is refused with 400 VALIDATION_ERROR, and it must trade on the venue you name. A leg that cannot be traded on its venue is refused with 422 VALIDATION_ERROR and details.reason: "NO_EXECUTABLE_VENUE", and a venue the trading account does not allow with details.reason: "VENUE_NOT_ALLOWED".
  • A conditional sell counts toward the key’s rolling day as orders at the leader’s lowest price and each follower’s floor would. It only takes risk off, so neither the per order nor the daily limit refuses it.
  • With a live key, a request is refused with 403 FORBIDDEN when the account can’t trade on a leg’s venue: for example, on Kalshi and Polymarket US no API key is connected in the Lean app, or on Polymarket the wallet isn’t set up or its approvals need refreshing in the Lean app.
  • Creating one is refused with 503 FEATURE_DISABLED while trading is paused or, for a live key, while Lean has paused these orders on a leg’s venue, and with 503 UPSTREAM_ERROR when a leg’s book could not be read. See Pause trading.

Track and cancel

GET /v1/conditional-sells lists the conditional sells of the key’s trading account, newest first: every one still active, paused or hedging, and those that ended in the last day. A live key also sees the conditional sells made in the Lean app on that account, as long as every leg is on a venue the API trades. GET /v1/conditional-sells/{id} reads one. Conditional buys and OR orders made in the Lean app are not part of the API: they are not listed, cannot be read and cannot be canceled here. An ended conditional sell can stay in the list past the day until Lean has finished settling it. A conditional sell’s sales are not orders you placed, so they send no order frame on the stream, and their fills are listed in GET /v1/fills with order_id set to null. Each leg’s filled_quantity and avg_fill_price show what it has sold. Cancel one with DELETE /v1/conditional-sells/{id}:
The answer is 200 with the conditional sell reading canceled. Lean cancels the leader’s resting sell and any follower sells still working, and shares already sold stay sold. Canceling works while trading is paused. A conditional sell that has already ended is refused with 409 CONFLICT. Pausing trading does not stop a conditional sell that is already working. Cancel it if you want it gone.

Test keys

A test key’s conditional sell is checked like a live one, against each leg’s market and the test account’s simulated shares, and it can be listed, read and canceled. It never sells, so it stays active until you cancel it, and its shares count as covered until then. See Test mode and live mode.