# OpenPit 0.8: trades made outside the bot now reach its limits

OpenPit SDK 0.8.0 adds drop copy in every SDK: an order executed outside the bot runs through the same policies with ordinary rejects ignored, and its fills follow as execution reports, so funds and loss limits count it. P&L bounds now carry a currency, and seven API changes need code edits.

Canonical: <https://pitofficer.com/blog/openpit-0-8-0/>
Author: Anna Palchukovsky <https://www.linkedin.com/in/anna-palchukovsky/>
Description: A trade made outside your bot reaches its limits only once the bot records it. OpenPit SDK 0.8.0 adds drop copy for that: how it works, its gaps, what to edit.
Published: 2026-09-06T21:47:08+03:00
Updated: 2026-09-06T21:47:08+03:00
Tags: openpit, reconciliation, risk-controls

You sell BTC by hand at a loss, and your bot's next buy still passes its loss
limit. OpenPit SDK 0.8.0 adds drop copy, which records that order; once its
fill is reported too, the next check counts the loss.

:::stat
**-1,800 USDT**

The loss a manual sale realized, past a -1,500 USDT limit. Without drop copy,
the bot's next check sees no loss at all. Illustrative prices, no fees.
:::

:::timeline

1. **The account holds 1.0 BTC and 10,000 USDT.** The BTC was bought at an
   average 64,000 USDT; the loss limit is -1,500 USDT of realized P&L.
2. **You sell 0.6 BTC by hand at 61,000.** The sale realizes -1,800 USDT,
   past the limit.
3. **The bot learns of the fill.** Until it records the order and its fill,
   the engine inside the bot still sees 1.0 BTC, 10,000 USDT and no loss.
4. **The bot checks a buy of 0.1 BTC, and it passes.** The bot may send a
   6,110 USDT buy that, once filled, adds exposure to an account already
   300 USDT past its loss limit.

:::

:::cards

- **A limit sees only what reaches it.** A manual trade, or an order from a
  second system on the same account, moves the position and the money without
  passing the bot's pre-trade check.
- **Drop copy records an executed order.** It runs the order through the same
  policies as a live one with ordinary rejects ignored, and its policy
  bookkeeping, apart from blocks and spent rate limit, is committed or rolled
  back as one unit; the order's fills then
  arrive as ordinary execution reports.
- **A breached limit blocks the account.** When the recorded fill pushes
  realized P&L past a bound, the account is blocked and the bot's next order is
  rejected.
- **Bounds carry a currency.** A P&L bound set in a currency other than the
  account's blocks that account or is skipped, instead of comparing unlike
  numbers.
- **Upgrading takes edits.** Seven changes break code written for 0.7.0.

:::

## Why does a limit inside the bot miss trades made outside it?

**OpenPit runs inside your process, so its risk state changes only through
calls your code makes; a trade made anywhere else reaches it only once your
code records it.**

When the bot checks its buy, only the engine that recorded the sale sees the
real account:

| Who | Holds | Realized P&L | The bot's buy |
| --- | --- | --- | --- |
| Actual account after the sale | 0.4 BTC, 46,600 USDT | -1,800 USDT | - |
| Engine without drop copy | 1.0 BTC, 10,000 USDT | None, counted as 0 | Passes |
| Engine after drop copy and the fill report | 0.4 BTC, 46,600 USDT | -1,800 USDT, account blocked | Rejected |

The stale state is wrong in both directions. The engine would pass a bot sell
of 1.0 BTC the account no longer holds, leaving a spot exchange that lends
nothing to refuse it, and it refuses any buy above 10,000 USDT although the
account holds 46,600. Until the trade is recorded, the rule from
[Why your trading bot's position drifts from the broker's](/blog/trading-bot-position-out-of-sync-with-broker/)
holds: a difference with the venue that nobody has explained is a break, and
the bot opens no new risk on top of it.

:::more[Terms this article uses]
The **pre-trade check** is the call your bot makes before it sends an order:
the engine runs its policies and either rejects the order or reserves what it
needs. The engine's **risk state** is what those policies keep per account:
available and held balances, the average entry price of each holding, realized
P&L, and whether the account is blocked.
:::

:::more[The scenario, step by step]
A Spot Funds policy guards account `99224416`, account currency USDT, with a
loss limit of -1,500 USDT on realized P&L. Fees are left out; prices are
illustrative.

- **t0.** The engine and the exchange agree: 1.0 BTC bought at an average
  64,000 USDT, 10,000 USDT, no realized P&L yet (the engine stores none and
  evaluates it as 0).
- **t1.** You sell 0.6 BTC at 61,000 in the exchange's app. The exchange now
  holds 0.4 BTC and 46,600 USDT, and the sale realized
  (61,000 - 64,000) x 0.6 = -1,800 USDT: past the limit.
- **t2.** The bot learns of the fill from its fill feed; with drop copy it
  records the order and its fill.
- **t3.** The bot checks a buy of 0.1 BTC at 61,100, which needs 6,110 USDT.

Without drop copy the engine still sees 1.0 BTC, 10,000 USDT and no realized
P&L at t3, so the buy passes. With drop copy the engine books the 1,800 USDT
loss at t2, blocks the account, and rejects the buy at t3. Between t1 and t2
both engines see the old state: drop copy is as fast as your fill feed.
:::

## How does drop copy record a trade the bot did not send?

**Drop copy runs the outside order through the same policies as a live order,
with ordinary rejects ignored, and you commit or roll back what it recorded as
one unit, except blocks and spent rate limit, which stay; the order's fills
then arrive as ordinary execution reports.**

Three roads lead into an account's risk state - its balances, entry prices,
realized P&L and block - and the next pre-trade check reads it:

:::outcomes

- **The bot's own order.** Through the pre-trade check: a reject stops the
  order.
- **Fills of either order, from the venue.** Through execution reports your
  code builds with the order's stored lock.
- **An order executed elsewhere, by hand or by a second system.** Through drop
  copy, new in 0.8.0: the same policies, ordinary risk and compliance rejects
  ignored.

:::

OpenPit fetches nothing: your code passes it the trade it learned of. Drop
copy in OpenPit is not the venue's drop copy session of the same name; that
session is one of the feeds that can tell your bot about the trade. Drop copy
is for an order the engine never admitted: a missed fill of an order the bot
sent through the pre-trade check is an execution report with that order's
stored lock, and a drop copy of it would reserve the order a second time.

:::more[What the Pre-trade Pipeline page specifies]
By the
[Pre-trade Pipeline page](https://github.com/openpitkit/pit/wiki/Pre-trade-Pipeline/d29ae403fb886c0904683fdcb6809cfcd841436f)
as of 2026-09-06, drop copy:

- runs the order through the same start-stage and main-stage policies, in the
  same order, as a live order;
- keeps every policy's bookkeeping and does not enforce ordinary risk and
  compliance rejects: the order already happened;
- ignores existing account and account-group blocks, so a blocked account still
  records it;
- returns a drop-copy operation whose policy bookkeeping you commit or roll
  back as one unit, like a reservation; account blocks it requested and
  rate-limit budget it spent stay either way;
- fails the whole call when the order has no readable account ID, or when a
  policy cannot evaluate it (no price, missing reference data, arithmetic
  overflow); the engine then undoes what the earlier policies did.

Order validation and order-size limits do nothing here: they are admission
checks, inert for an order that already executed
([Policies](https://github.com/openpitkit/pit/wiki/Policies/d29ae403fb886c0904683fdcb6809cfcd841436f)).
:::

:::more[What Spot Funds does with a drop copy]
Drop copy records the order, not its fills. For Spot Funds it reserves the
order's legs as a live order would, with the funds check switched off, and
returns the pre-trade lock with the order's price. The fills then arrive as
execution reports carrying that lock: a sell's fill consumes the held BTC,
credits the USDT proceeds to available and clears them from incoming, and books
realized P&L
([Spot Funds](https://github.com/openpitkit/pit/wiki/Spot-Funds/d29ae403fb886c0904683fdcb6809cfcd841436f)).
Execution reports are not part of that unit: each one applies on its own.
:::

:::more[Drop copy in each SDK]
Drop copy is in every SDK: `apply_drop_copy` in Rust and Python,
`ApplyDropCopy` in Go and C++, `applyDropCopy` in JavaScript,
`openpit_engine_apply_drop_copy` in C, by the source at the
[v0.8.0 tag](https://github.com/openpitkit/pit/releases/tag/v0.8.0). OpenPit
SDK 0.8.0 was released 2026-09-06; the full notes are on the
[v0.8.0 release page](https://github.com/openpitkit/pit/releases/tag/v0.8.0).
:::

## What does drop copy leave to your code?

**Drop copy applies what you pass, when you pass it: it does not deduplicate,
does not refund the rate limit and does not close the gap before the bot hears
of the trade, and Spot Funds records the order even when available funds go
negative.** Each case below comes from the
[Pre-trade Pipeline](https://github.com/openpitkit/pit/wiki/Pre-trade-Pipeline/d29ae403fb886c0904683fdcb6809cfcd841436f),
[Spot Funds](https://github.com/openpitkit/pit/wiki/Spot-Funds/d29ae403fb886c0904683fdcb6809cfcd841436f)
and [Policies](https://github.com/openpitkit/pit/wiki/Policies/d29ae403fb886c0904683fdcb6809cfcd841436f)
pages at the 0.8.0 release.

:::more[A replayed trade can be booked again]
The order carries no trade or execution ID, so the engine cannot tell a
replayed trade from a new one. Deduplicate by the venue's execution ID before
you call it: a replayed order is reserved again, and a replayed fill moves
holdings again and can book more P&L.
:::

:::more[Spot Funds needs a market order's executed price, and every order needs an account]
Spot Funds rejects a drop-copied order without a price of its own
(`MissingRequiredField`) rather than price a past trade at the current mark,
and the whole call fails. Give a manual market order its executed price; each
execution report still carries its own fill price. An order without a readable
account is rejected before any policy runs, and nothing is recorded.
:::

:::more[The funds check is off, so a balance can go negative]
Spot Funds always records a drop copy in track-only mode: an order that takes
`available` negative is recorded, not refused. Treat a negative balance as a
reconciliation signal: check open holds, the seed and missed events.
:::

:::more[A backlog replay spends the bot's rate limit]
Drop copy counts against the rate-limit budget like a live order, and neither
a failure nor a rollback refunds it. Replaying a backlog of 30 missed orders
after a restart can leave the bot's own orders rate-limited for the rest of
the window.
:::

:::more[A block outlives a rollback]
Account blocks a policy requests during drop copy are applied before the call
returns and stay applied whichever way you finalize the operation.
:::

:::more[A live check can interleave with an open drop copy]
With a fully synchronized engine, a drop copy and a live check on the same
account may interleave until you finalize the operation; serialize per account
when that matters.
:::

:::more[The gap before the bot hears of the trade stays]
Drop copy is as fast as the feed that tells the bot about outside trades;
between the trade and its recording, the engine checks against the old state.
:::

## What does a P&L bound in another currency do now?

**In 0.8.0 every Spot Funds P&L bound names a currency, and bounds are never
converted: the account's currency decides what a bound does.**

:::outcomes

- **The account has no currency.** None on the account, its group or the
  default group: the first bound in account, group, global order applies, as
  before.
- **An account bound in another currency.** The account is blocked: a
  mistyped currency stops trading instead of guarding nothing.
- **A group or global bound in another currency.** It is skipped for that
  account. An account with no account bound and no group or global bound in
  its own currency has no P&L control at all, while its P&L is still computed
  and published.

:::

A policy has one global bound. A desk with USDT and USD accounts under a
global USD bound leaves the USDT accounts unguarded: give them a group or
account bound in USDT
([Spot Funds](https://github.com/openpitkit/pit/wiki/Spot-Funds/d29ae403fb886c0904683fdcb6809cfcd841436f)).

:::more[How 0.7.0 compared bounds, and when the block lands]
In 0.7.0 a Spot Funds P&L bound was two bare numbers, compared with the
account's P&L in whatever currency that account used: a global -1,500 written
for USDT accounts meant -1,500 BTC for an account kept in BTC
([v0.7.0 source](https://github.com/openpitkit/pit/blob/v0.7.0/crates/openpit/src/pretrade/policies/spot_funds/pnl.rs)).

In 0.8.0 an account bound in another currency blocks the account with
`PnlKillSwitchTriggered` when the bound is evaluated: at its next check, or
already when the bound is set or a group change selects it
([Spot Funds](https://github.com/openpitkit/pit/wiki/Spot-Funds/d29ae403fb886c0904683fdcb6809cfcd841436f)).
:::

## What breaks when you upgrade from 0.7?

**Seven changes break code written for 0.7.0.** A field of the execution
report and one of the order-size limit are renamed, P&L bounds require a
currency, the market-data patch calls are gone, ordinary decimal string
parsing rejects excess precision, the C++ SDK is redesigned, and the Go engine's driver interface has
three new methods.

:::more[The seven changes, with the names to edit]
Each item below breaks code written for 0.7.0, by the source at
[v0.8.0](https://github.com/openpitkit/pit/tree/v0.8.0):

- **Execution reports**: `leaves_quantity` is renamed
  `remaining_reserved_quantity`. It is the remainder of your own reservation
  that a final report releases, not the venue's FIX `LeavesQty`.
- **Spot Funds P&L bounds**: `SpotFundsPnlBoundsBarrier` requires a
  `currency`.
- **Order-size limits**: the barrier's `settlement_asset` field is now `asset`,
  matched as the underlying for the quantity cap and as the settlement asset
  for the notional cap, and both caps are optional.
- **Market data**: `push_patch`, `push_for_patch` and
  `push_by_instrument_patch` are gone. `push`, `push_for` and
  `push_by_instrument` take the quote's source age, the time from its
  observation to publication, which counts toward its time to live
  ([Market Data](https://github.com/openpitkit/pit/wiki/Market-Data/d29ae403fb886c0904683fdcb6809cfcd841436f)).
- **Decimals from strings**: parsing no longer rounds; a string with more
  digits than the decimal type holds is an `InvalidFormat` error in Rust
  `from_str`. Round explicitly first, for example with `from_str_rounded`.
- **C++**: the SDK is redesigned; port 0.7 code to the new API.
- **Go**: the `asyncengine.Driver` interface adds `ExecutePreTradeDryRun`,
  `ApplyDropCopy` and `Configure`; a custom driver or mock must implement them.

:::

## What should you check before you rely on drop copy?

- Every way the account trades outside the bot is listed: manual trades, other
  systems.
- Each of those has a feed the bot reads: the venue's user-data stream, a
  fill-history query, or a venue drop copy session.
- Every outside order is recorded once with drop copy and its executed price;
  its fills, and missed fills of the bot's own orders, go in as execution
  reports with the order's lock, deduplicated by the venue's execution ID.
- The lock from each drop-copy operation is read before commit, stored, and
  sent on every execution report of that order.
- A backlog replay after a restart is paced to leave the bot's live orders room
  in the rate-limit window.
- Every Spot Funds account under a P&L bound has an account currency, and a
  bound in that currency.
- The seven breaking changes are handled before upgrading.

## Where is the runnable code?

:::more[The manual sell and the bot's next buy, in Python]
The scenario in Python, with OpenPit SDK 0.8.0 (`pip install openpit==0.8.0`).
The drop-copy and commit pattern is the wiki's "Apply a Historical Order with
Drop Copy" example as of 2026-09-06; the seeding and the execution report
follow the
[Spot Funds example](https://github.com/openpitkit/pit/blob/v0.8.0/examples/python/spot_funds/main.py)
at v0.8.0. Run with openpit 0.8.0 on CPython 3.13.

```python
# OpenPit SDK 0.8.0 (Python): a manual sell recorded by drop copy, then the
# bot's next buy.
import openpit
from openpit.pretrade import policies

P = openpit.param
account = P.AccountId.from_int(99224416)
btc_usdt = openpit.Instrument(P.Asset("BTC"), P.Asset("USDT"))

engine = (
    openpit.Engine.builder()
    .no_sync()
    .builtin(policies.build_order_validation())
    .builtin(policies.build_spot_funds())
    .build()
)
engine.accounts().set_currency(account, "USDT")
engine.configure().spot_funds_pnl_bounds_killswitch(
    policies.SpotFundsBuilder.NAME,
    account_barriers=[
        policies.SpotFundsPnlBoundsAccountBarrier(
            account_id=account,
            barrier=policies.SpotFundsPnlBoundsBarrier(
                currency=P.Asset("USDT"),
                lower_bound=P.Pnl("-1500"),
            ),
        )
    ],
)


def balance(asset: str, amount: str, entry: str | None = None):
    return openpit.AccountAdjustment(
        operation=openpit.AccountAdjustmentBalanceOperation(
            asset=P.Asset(asset),
            average_entry_price=P.Price(entry) if entry else None,
        ),
        amount=openpit.AccountAdjustmentAmount(
            balance=P.AdjustmentAmount.absolute(P.PositionSize(amount)),
        ),
    )


# t0: 1.0 BTC at an average 64,000, and 10,000 USDT.
seeded = engine.apply_account_adjustment(
    account_id=account,
    adjustments=[balance("USDT", "10000"), balance("BTC", "1.0", "64000")],
)
assert seeded.ok


def order(side, qty: str, price: str) -> openpit.Order:
    return openpit.Order(
        operation=openpit.OrderOperation(
            instrument=btc_usdt,
            account_id=account,
            side=side,
            trade_amount=P.TradeAmount.quantity(qty),
            price=P.Price(price),
        )
    )


# t2: the bot learns of the manual sell, 0.6 BTC at 61,000, and records it.
manual_sell = order(P.Side.SELL, "0.6", "61000")
journal = []  # stands in for your own order store
result = engine.apply_drop_copy(order=manual_sell)
if not result:
    raise RuntimeError([r.code for r in result.rejects])
operation = result.operation
lock = operation.lock  # read before commit: the accessors close after it
try:
    journal.append((manual_sell, lock))
except Exception:
    operation.rollback()
    raise
operation.commit()

# Its fill, as an ordinary execution report carrying the lock.
fill = engine.apply_execution_report(
    report=openpit.ExecutionReport(
        operation=openpit.ExecutionReportOperation(
            instrument=btc_usdt, account_id=account, side=P.Side.SELL
        ),
        fill=openpit.ExecutionReportFillDetails(
            last_trade=P.Trade(price=P.Price("61000"), quantity=P.Quantity("0.6")),
            remaining_reserved_quantity=P.Quantity("0"),
            lock=lock,
            is_final=True,
        ),
    )
)
print(len(fill.account_blocks))  # 1: realized P&L -1,800 is below -1,500

# t3: the bot's next buy.
check = engine.execute_pre_trade(order=order(P.Side.BUY, "0.1", "61100"))
print(bool(check), check.rejects[0].code)  # False PnlKillSwitchTriggered
```

Remove the drop copy and the execution report, and the same buy passes with a
reservation of 6,110 USDT. The reject carries the cause the block was recorded
with, `PnlKillSwitchTriggered` from the Spot Funds policy.
`engine.accounts().unblock(account)` clears the stored block
([Account Blocking](https://github.com/openpitkit/pit/wiki/Account-Blocking/d29ae403fb886c0904683fdcb6809cfcd841436f)),
but while realized P&L stays at -1,800 against a -1,500 bound, Spot Funds
rejects the next order again: widen the bound or correct the P&L first.
:::

## What else do people ask?

:::more[Does OpenPit read trades from the exchange?]
No. OpenPit is a library inside your process; it records what your code
passes it. Your code reads the outside trade from the venue, through a
user-data stream, a fill-history endpoint or a venue drop copy session, and
calls drop copy with it.
:::

:::more[Can drop copy reject a trade?]
It cannot refuse it on risk grounds: limits, funds and blocks do not stop it.
It fails as a whole only when the order has no readable account ID or a policy
cannot evaluate it, such as an order with no price, and then nothing is
recorded.
:::

:::more[What happens when the recorded trade breaches a P&L bound?]
The trade is still recorded, and the account is blocked at the execution
report that books the loss, as in the scenario above, or at the drop copy when
a policy asks for a block there. The bot's next order is rejected until the
block is lifted and the P&L is back inside the bound.
:::

:::more[Why is drop copy different from an account adjustment?]
An account adjustment sets or moves balances and runs no order policy. Drop
copy runs the order through the policies, so a rate limit counts it and the
fills that follow book realized P&L against the right reservation.
:::

## Where should I read next?

- [Why your trading bot's position drifts from the broker's](/blog/trading-bot-position-out-of-sync-with-broker/):
  why manual trades and missed fills open a break, and how to find them.
- OpenPit SDK as of 0.8.0:
  [Pre-trade Pipeline](https://github.com/openpitkit/pit/wiki/Pre-trade-Pipeline/d29ae403fb886c0904683fdcb6809cfcd841436f),
  [Spot Funds](https://github.com/openpitkit/pit/wiki/Spot-Funds/d29ae403fb886c0904683fdcb6809cfcd841436f),
  [Account Blocking](https://github.com/openpitkit/pit/wiki/Account-Blocking/d29ae403fb886c0904683fdcb6809cfcd841436f),
  [release page](https://github.com/openpitkit/pit/releases/tag/v0.8.0).
