OpenPit SDK 0.9.0 and 0.11.0: position ceilings and open P&L bounds
Orders under a per-order cap add up to a position nobody chose, and open losses slip past a realized-loss limit: what OpenPit SDK 0.9.0 and 0.11.0 add.
Contents
- What is new in 0.9.0 and 0.11.0?
- How do orders under a per-order cap add up to a position nobody chose?
- How does the position limit stop it?
- How can an open position lose more than the daily loss limit?
- How do the unrealized and total bounds stop it?
- When does the total bound fire before either part?
- Who exits a blocked account, and how?
- What do the open-P&L bounds need, and where do they fall short?
- What changes when you upgrade from 0.8?
- What should you verify in your own setup?
- What does each SDK expose?
- Where is the code?
- What else do people ask?
- Where should I read next?
Your bot caps each BTC order at 0.5 and stops at a daily realized loss of 1,000 USDT, yet it can hold 1.2 BTC nobody chose and sit on a 2,300 USDT open loss.
- The bot holds 1.0 BTC bought at 61,000 USDT. It has sold nothing and paid no fees, so realized P&L is 0; its only loss limit stops it at -1,000 realized.
- The mark falls to 60,200. The open loss is 800 USDT, and every limit passes.
- The mark falls to 59,400. The open loss is 1,600 USDT; nothing is realized, so the loss limit stays green.
- The mark falls to 58,700. The open loss is 2,300 USDT, and realized P&L still reads 0.
- The bot sells 0.5 BTC to cut the loss. The order passes; the loss limit sees a loss only after the fill: -1,150 if the half fills at 58,700 with no fee.
- A position ceiling counts working orders. The Spot Funds position limit refuses an order that would take the account’s worst-case position in an asset past its limit, counting the orders still working, in every SDK.
- Open losses can stop an account. Unrealized and total P&L bounds value open positions at the current mark; a breach blocks the account no later than its next order, while realized P&L may still be 0.
- The block stops exits too. Every order is refused until someone lifts the block, the sell that would close the position included.
- Language coverage differs. The position limit is set from Rust, Python, Go, JavaScript, C and C++; at 0.11.0 the open-P&L bounds are set from Rust, C and Go only.
What is new in 0.9.0 and 0.11.0?
Two limits on what an account holds, and a way to retire an account from a live engine.
- 0.9.0: Spot Funds position limit, per account and asset, set and changed at runtime in every SDK.
- 0.9.0: account retirement in Rust, the C ABI and Go: remove an account’s runtime state from a live engine without rebuilding it.
- 0.11.0: unrealized and total P&L bounds in Spot Funds, set from Rust, C and Go only.
Upgrading from 0.8 takes code changes: what to change.
The release pages, and when retirement refuses
OpenPit SDK 0.9.0 was released on 2026-10-05 and 0.11.0 on 2026-11-01. The list above is from the v0.9.0 and v0.11.0 release pages, checked against the source at both tags.
Retirement refuses while the account still has non-zero positions or P&L, account-specific settings, or operations in flight (Account Retirement).
How do orders under a per-order cap add up to a position nobody chose?
Each order passes its cap and the funds check, and neither check is a ceiling on how much of an asset the account ends up holding.
A grid that keeps adding, two strategies buying the same coin, or a retry loop that resends after a timeout all produce orders that each pass. With illustrative numbers: the account holds 0.2 BTC and 100,000 USDT, BTC trades at 61,000 USDT, and the per-order cap is 0.5 BTC. Four limit buys at 61,000 of 0.4, 0.3, 0.2 and 0.1 BTC are each under the cap and together cost 61,000 USDT, well inside the funds. The account would hold 1.2 BTC.
What a per-order cap and a funds check bound
A per-order cap (OpenPit’s order-size limit, or your own check) bounds one order. A funds check bounds what the account can pay for. Neither bounds how much of an asset the account ends up holding.
How does the position limit stop it?
It refuses the buy that would take the account’s worst-case position in the asset past its ceiling, counting every buy still working.

With a ceiling of 1 BTC, the third buy would take the projection to 1.1 BTC and is refused; the fourth reaches exactly 1.0 and passes. Only that order is refused: the account is not blocked, and the bot’s other orders are checked on their own.
The ceiling, step by step
In the scenario the account is 7001. A position limit in OpenPit is a
ceiling L per account and asset. The projected position it checks for a
buy is the worst case: what the account owns (available + held), plus what
its working buys will bring in (incoming), plus the new order. With L = 1
BTC:
- t0. Holds 0.2 BTC: projected 0.2.
- t1. Buy 0.4 is accepted and works at the venue: projected 0.6.
- t2. Buy 0.3 is accepted: projected 0.9. Neither buy has filled; both
count through
incoming. - t3. Buy 0.2 would project 1.1, past 1.0: refused with
PositionLimitExceeded. If the t1 buy fills in between, nothing changes, because a fill moves 0.4 fromincomingtoavailableand the projection stays 0.9. - t4. Buy 0.1 projects exactly 1.0. The bound is inclusive, so it passes.
The reject is at order scope. How each SDK sets the limit is in What does each SDK expose?, and the code in Where is the code?
Where the ceiling does not reach, from the Spot Funds position limit page and the source at v0.9.0:
A working sell frees no room for a buy
The long-side projection counts what the account owns, coins held for its working sells included. Selling 0.3 BTC does not let the bot buy 0.3 more until the sell fills.
The limit is per asset, not per pair
BTC bought against USDT and against USDC lands in one BTC slot and one ceiling. A limit on the quote asset applies to its leg as well.
The limit never refuses trades booked outside the engine
Only orders checked by the engine are gated. Drop copy, account adjustments
and execution reports are never refused by the limit. A trade made by hand and
booked as a drop copy (OpenPit 0.8.0) can take the
position past L; the next buy is then refused, and nothing is unwound.
Lowering the limit does not cut the position
A change applies from the next order and does not re-evaluate open orders. An account above its new ceiling cannot buy, and can sell while the sell’s projection stays within the limit.
A working market order counts at its reserved amount
A later quote does not revalue it.
On each asset, funds are checked before the position
Per asset: an order that fails both on one asset reports InsufficientFunds.
Bots share a ceiling only through one engine
Bots that share an account share the limit only when their orders go through the same engine; see Multiple trading bots on one account. A ceiling also does not make a resend after a timeout safe: it bounds the damage of a duplicate, and Trading bot duplicate orders after a timeout covers how to avoid one.
How can an open position lose more than the daily loss limit?
By staying open: from trading, realized P&L changes only when a position is reduced or closed, or a fee is booked.
Unrealized P&L is what closing the owned position at the current mark would add to realized P&L; total P&L is the two together. A loss limit on realized P&L does its job and still lets an open position lose without limit.
How do the unrealized and total bounds stop it?
They value open positions at the mark, and a breach blocks the account no later than its next order.
The account keeps its realized bound of -1,000 USDT, and 0.11.0 adds two more on it: unrealized at -2,000 and total at -2,200.

At 58,700 the open loss is past both new bounds, and nothing happens yet: a new quote is not a check point. The bot’s next order, the sell of 0.5 BTC, is rejected, and the account is blocked.
The mark falls, step by step
Account 7001 holds 1.0 BTC at an average entry of 61,000 USDT, has sold nothing and paid no fees, so realized P&L is 0.
- t1, mark 60,200. Unrealized -800. Every limit passes.
- t2, mark 59,400. Unrealized -1,600. Every limit passes.
- t3, mark 58,700. Unrealized -2,300, past both new bounds. Nothing happens yet: publishing a quote is not a check point.
- t4. The bot sends its next order, a sell of 0.5 BTC to cut the loss. It
is rejected with
PnlKillSwitchTriggered, and the account is blocked.
What checks the bounds, and in which order
The check points are a pre-trade request, a dry run (which reports without blocking), a drop copy, an execution report carrying a trade or a non-zero fee, an account-P&L force-set, and a retune that changes the bound. The realized bound is checked first, then account unrealized, account total, and the two position axes; the first breach wins, so the t4 reject names account unrealized P&L.
When does the total bound fire before either part?
When realized and open losses are each inside their own bound and their sum is not.
Say the bot closed an ETH trade earlier in the day at -700 USDT, and the same 1.0 BTC is marked at 59,400:
| P&L | Value, USDT | Bound, USDT | Result |
|---|---|---|---|
| Realized | -700 | -1,000 | inside |
| Unrealized | -1,600 | -2,000 | inside |
| Total | -2,300 | -2,200 | breached |
The breach rejects the next order and blocks the account. The total bound adds realized P&L since you last reset it to the open P&L; the engine has no daily reset, so a daily limit means forcing realized P&L to 0 each day with an account-P&L force-set. The realized and unrealized bounds catch one side growing alone.
Who exits a blocked account, and how?
Decide before you set the bound, because the block refuses the exit too. A bound is a halt, not a stop-loss: it never closes the position.
- Through the engine. Lift the block, widen or clear every bound the account breaches, then sell; once the sell fills, the realized loss can block the account again.
- At the venue. Close the position there and book the trade in the engine as a drop copy with its price; skip it and the bound keeps valuing a position you no longer hold.
The block lives in the engine’s memory: if the process that runs the engine restarts, persist the block and restore it with its original cause. Why the halt has to survive the restart is in What happens if my trading bot crashes with a position open?
Both routes, and the restart, in detail
- Through the engine. Lift the block (
Unblockin Go, Account Blocking) and widen or clear every bound the account breaches, then send the sell. An unblock alone is not enough: while the value is still past the bound, the next order is rejected and blocks again. Once the sell fills, the loss is realized: closing 1.0 BTC at 58,700 books -2,300, past the -1,000 realized bound, and that fill blocks the account again. That block is the daily stop doing its job, after the exit. - At the venue. Close the position there and book the trade in the engine as a drop copy with its price. A block does not gate drop copy, so the engine’s position follows the account.
- After a restart. Restore the persisted block with its original cause
(
BlockWithCausein Go).
What do the open-P&L bounds need, and where do they fall short?
They need an account currency, a mark for every open asset outside it and a cost basis; they value at the mark, not the fill, and accept an expired quote.
From the Spot Funds page and the source at v0.11.0:
With a bound set, a missing mark blocks the account at the next check
Valuation needs the account’s currency and a mark for each open asset in it,
from the market-data service attached to Spot Funds; an asset already in the
account currency counts at one. A missing mark halts the value with
MissingFx, and a halted value with a bound set rejects the next order and
blocks the account, the same as a breach.
A seeded position without an average entry price is skipped
A position seeded by account adjustment needs its average entry price; without one, and unless its realized P&L is halted, the bounds skip it, and its loss is never counted.
An expired quote still counts
Valuation accepts an expired mark, so a dead feed values the position at the last mark it has instead of stopping the bound. Keep your own staleness check: How to handle stale market data in a trading bot’s loss limits.
The value uses the mark, not the fill
There is no bid/ask or slippage in it, so the realized loss on the way out can be worse than the bound implied.
The engine does not publish the value
At 0.11.0 the engine neither stores nor publishes unrealized or total P&L. To show it on a dashboard, compute it yourself; to ask whether the next order would be blocked, use a dry run.
Position axes use one bound for every asset
Position unrealized and position total compare each position separately with the same bound; there is no per-asset bound.
Moving an account between groups does not re-check open P&L
Moving an account into or out of an account group re-evaluates realized bounds only; the next order catches an open-P&L breach.
Full sync can record a block that was never earned
A fill writes position and account state in steps; under FullSync an
evaluation on another thread can read a state in between and record a block
that was never earned, which stays until an admin unblock. AccountSync has
no such window.
What changes when you upgrade from 0.8?
0.9.0 has breaking changes in Python, Go, C, C++ and Rust, and 0.10.0, on the way, has more in Go and C++.
Breaking changes in 0.9.0, by language
Each line names what to change. From the v0.9.0 release page, checked against the tag:
- Python:
from_decimal_roundedraises on aDecimalwith more than 28 fractional digits or a mantissa wider than 96 bits instead of rounding it. Quantize first. - Go and C++: an unset account group ID is rejected. Go
Accounts.ClearGroupCurrency,marketdata.Service.SetAccountGroupTTLandClearAccountGroupTTLreturn an error; C++AccountGroupIdhas no default constructor. Name the default group asDefaultAccountGroup. - C and Go: reject and account-block
user_datais an integer token (size_t,uintptr), not a pointer. Pass a handle or an index. - Go:
AccountGroupResolutionError.Unwrapreturns[]error; match witherrors.Isorerrors.As. - Rust:
PreTradeContext::newtakes the order as its second argument, andNoBarriersConfiguredis gone from the rate-limit and order-size policy errors.
Crossing 0.10.0
Upgrading across 0.10.0 also changes the threading contract of the Go and C++ async engines and the signatures of some Go fill-lock calls; see the v0.10.0 release page before you move.
What should you verify in your own setup?
- Every asset a bot accumulates has a position limit per account, sized for the worst case with every working buy filled.
- Bots that trade one account send their orders through one engine, so the ceiling and the bounds see all of them.
- Trades made outside the engine are booked as drop copies, so the position the limit and the bounds read is the real one.
- Every account under an open-P&L bound has a currency, a fresh mark for each open asset, and an average entry price for each seeded position.
- A total bound sits alongside the realized one, and realized P&L is reset each day if the limits are daily.
- You know who exits a blocked account and by which route, before you arm the bound.
- A persisted block is restored after a restart.
What does each SDK expose?
The position limit is set from every SDK; the unrealized and total P&L bounds from Rust, C and Go only.
| SDK | Position limit (0.9.0) | Unrealized and total P&L bounds (0.11.0) |
|---|---|---|
| Rust1 | Yes | Yes |
| C2 | Yes | Yes |
| Go3 | Yes | Yes |
| Python4 | Yes | No |
| JavaScript | Yes | No |
| C++ | Yes | No |
Notes and sources
- The open-P&L bounds:
set_pnl_axis_account_barriersinsideengine.configure().spot_funds(...); both limits can also be set onSpotFundsSettingsbefore the policy is built. - The open-P&L bounds:
openpit_engine_configure_spot_funds_pnl_bounds_axis. engine.Configure().SpotFundsPositionLimitandengine.Configure().SpotFundsPnlBoundsAxis(Dynamic Policy Reconfiguration, Unrealized and Total PnL Bounds).- The position limit is a
SpotFundsPositionLimitEntryin the Spot Funds retune,engine.configure().spot_funds(...).
Where is the code?
Setting the position limit in Go and Python (0.9.0)
There is no builder option for the limit in any binding; you set it on a
running engine through the configurator, or in Rust on SpotFundsSettings
before the policy is built
(Dynamic Policy Reconfiguration).
In Go, with the reject handling from the binding’s own tests:
// OpenPit SDK 0.9.0, Go: run against go.openpit.dev/openpit v0.9.0. A fragment:
// engine is built with policies.BuildSpotFunds(), order is the t3 buy and send
// is your venue call. The configurator call is from the wiki's Dynamic Policy
// Reconfiguration page (revision 7ee40b1).
account := param.NewAccountIDFromUint64(7001)
btc, err := param.NewAsset("BTC")
if err != nil {
return err
}
ceiling, err := param.NewQuantityFromString("1")
if err != nil {
return err
}
if err := engine.Configure().SpotFundsPositionLimit(
policies.SpotFundsPolicyName, account, btc, optional.Some(ceiling),
); err != nil {
return err
}
reservation, rejects, err := engine.ExecutePreTrade(order)
switch {
case err != nil:
return err
case reservation != nil:
// Accepted: the reservation must be resolved exactly once.
if err := send(order); err != nil {
reservation.RollbackAndClose()
return err
}
reservation.CommitAndClose()
case rejects[0].Code == reject.CodePositionLimitExceeded:
// Details name the asset, the side, the projected position and the limit.
log.Printf("refused: %s", rejects[0].Details)
}In Python the same limit is one entry of the Spot Funds retune (run with
openpit 0.9.0):
import openpit
from openpit.pretrade.policies import SpotFundsBuilder, SpotFundsPositionLimitEntry
engine.configure().spot_funds(
SpotFundsBuilder.NAME,
position_limits=[
SpotFundsPositionLimitEntry(
account_id=openpit.param.AccountId.from_int(7001),
asset=openpit.param.Asset("BTC"),
limit=openpit.param.Quantity.from_string("1"), # None clears it
),
],
)Setting the unrealized and total bounds in Go (0.11.0)
Like the position limit, the bounds have no builder option; you retune them on
the running engine, or in Rust set them on SpotFundsSettings before the
policy is built
(Unrealized and Total PnL Bounds):
// OpenPit SDK 0.11.0, Go: run against go.openpit.dev/openpit v0.11.0. A
// fragment, adapted from the wiki's Spot Funds example (revision 7ee40b1) from
// the global tier to the account tier. Spot Funds is
// built with policies.BuildSpotFunds().WithMarketOrders(marketData, 0), the
// account's currency is USDT (engine.Accounts().SetCurrency), and marketData
// carries a BTC/USDT mark: without the attached service, valuation halts.
usdt, err := param.NewAsset("USDT")
if err != nil {
return err
}
setFloor := func(axis policies.SpotFundsPnlBoundsAxis, lower string) error {
floor, err := param.NewPnlFromString(lower)
if err != nil {
return err
}
retune, err := engine.Configure().SpotFundsPnlBoundsAxis(
policies.SpotFundsPolicyName,
axis,
optional.None[*policies.SpotFundsPnlBoundsBarrier](), // global tier unchanged
nil, // account-group tier unchanged
// A non-nil slice replaces this axis's whole account tier: list every account.
[]policies.SpotFundsPnlBoundsAccountBarrier{{
AccountID: account,
Barrier: policies.SpotFundsPnlBoundsBarrier{
Currency: usdt,
LowerBound: optional.Some(floor),
},
}},
)
if err != nil {
return err
}
// Arming checks the account at once and lists only blocks this call records:
// an account the first call already blocked is not listed by the second.
for _, outcome := range retune.AccountBlocks {
log.Printf("blocked on arming: %s", outcome.Block.Details)
}
return nil
}
if err := setFloor(policies.SpotFundsPnlBoundsAxisAccountUnrealized, "-2000"); err != nil {
return err
}
if err := setFloor(policies.SpotFundsPnlBoundsAxisAccountTotal, "-2200"); err != nil {
return err
}Rust and C use the calls in the SDK notes.
What else do people ask?
Does the position limit cap money or units?
Units of one asset per account: 1 BTC is 1 BTC at 40,000 or at 90,000. The money an order may commit stays with the funds check, and its size with the per-order cap; set all three.
Can I set unrealized or total P&L bounds from Python?
Not at 0.11.0. Rust, C and Go set them; Python, JavaScript and C++ do not expose them yet. The position limit and the realized bounds are available in every SDK.
Does a falling price block the account at once?
No. A quote is not a check point; the next order, a drop copy, an execution report with a trade or a fee, a force-set of account P&L or a retune of the bound is. A dry run reports the breach without blocking.
Does the P&L bound close my position?
No. It rejects the next order and blocks the account; the position stays open at the venue until someone closes it.
Where should I read next?
- OpenPit 0.8.0: drop copy, which books trades made outside the engine into the state both limits read.
- Multiple trading bots on one account: one admission point for every bot on the account.
- What happens if my trading bot crashes with a position open?: a halt outside the bot that survives a restart.
- How to handle stale market data in a trading bot’s loss limits: a P&L value is only as current as its oldest price.
- OpenPit wiki at the revision this post describes: Spot Funds, Dynamic Policy Reconfiguration, Account Blocking.