Multiple trading bots on one account: sharing buying power
Multiple trading bots on one account can both pass the same buying power check. Reserve before sending, and hold through fills, replaces and restarts.
Contents
- How do two bots both pass the same balance check?
- Why the broker’s buying power is not enough
- What one reservation looks like, from decision to release
- What is still reserved after a partial fill, a replace or a lost cancel?
- How to recover reservations after a restart
- Is the venue’s hold counted twice?
- When do separate accounts beat a shared one?
- What should you check before bots share an account?
- What does each venue document?
- Where is the ledger as pseudocode?
- What else do people ask?
- Where to go next
Two bots on one account read the same free balance, each finds room for a 6,000 USD buy, and both send it.
- Both bots read the account. Nothing spent, no open orders: 10,000 USD of room under your rule.
- Bot A sends a buy for 6,000 USD. 6,000 fits under 10,000.
- Bot B sends a buy for 6,000 USD. A’s order is in flight, B’s snapshot does not include it yet, and 6,000 fits again.
- The venue acknowledges A. It now counts 6,000 USD.
- The venue acknowledges B. It now counts 12,000 USD, against the 10,000 you allowed.
- Check-then-send races. Two processes that read a balance and then send both pass whenever each reads a snapshot that does not yet include the other’s order.
- Check and reserve in one step. One admission point checks and reserves atomically for the account, and persists the reservation before the order leaves.
- Only a terminal report releases. A fill moves its part of the reservation into spending; what is left is released on filled, canceled, rejected or expired, never on an accepted cancel request or a timeout.
- A replace can leave two orders to account for. On Binance, a cancel-replace that allows the cancel to fail can place the new order while the cancel fails, and the old order’s state is then unknown; reserve both until each has a final state.
- Count the venue’s hold once. The venue’s buying power already includes the orders reflected in it; subtract only your reservations for orders it does not reflect yet.
Terms this article uses
A reservation is the amount an order may still spend, recorded before the
order is sent and counted against the limit until the order is final. Free
capacity is the limit minus what has been spent minus every open
reservation. A terminal report is the venue’s report that an order can no
longer fill: filled, canceled, rejected or expired, and at Alpaca replaced
for the old record of a replace.
How do two bots both pass the same balance check?
Each bot checks against a number that does not yet include the other bot’s order.
At the moment B checks, A’s order is in flight: sent, not acknowledged, and the snapshot B reads does not include it. Nothing bounds how long that stays true: a bot that caches its balance, or a venue balance that updates after the acknowledgment, keeps the window open after A is accepted. Two strategies that trade the same market can react to the same tick, and then their signals land in that window together.
The numbers behind the timeline, and what the venue does with them
Account: 25,000 USD in cash. Your rule: the two bots together deploy at most 10,000 USD. Each bot reads its open orders and spending from the venue, adds the new order, and compares with 10,000. Both orders are buys of 60 @ 100. Timings are illustrative.
Both orders pass the venue’s buying-power check, assuming 25,000 USD of usable buying power and otherwise valid orders. With 10,000 USD, B fails that check once A’s 6,000 USD order counts against buying power, and B’s strategy, which sized everything else on that fill, learns it late.
The race does not need two processes
NautilusTrader’s issue #5119 reported that its risk engine “admits buys that together exceed a cash account’s free balance”; the fix in PR #5184, merged 2026-10-12, keeps each order’s charge against free balance “until the account reflects the order or it closes”. Its example: two 600 USD buys from one callback on a 1,000 USD account; the second is now refused against 400 free.
Why the broker’s buying power is not enough
The broker’s number arrives late and enforces the broker’s limit, not yours.
- It sees only orders that arrived. At Alpaca, open orders that open or add to a long or short position reduce buying power, and orders that close one do not replenish it until they execute. An order in flight is in neither.
- It enforces the account, not the strategy. A split such as “momentum gets 6,000, mean reversion gets 4,000”, or a total below what the account holds, exists only on your side.
- Reading it is not reserving it. Two bots can read the same number at the same moment; nothing stops both from spending it.
What one reservation looks like, from decision to release
Every bot asks one admission point, which checks and reserves for the account in one atomic step, persists the reservation, and only then lets the order go.
With the same numbers, A reserves 6,000 at the moment it decides; B’s request a moment later sees 4,000 free and is refused, or resized, before anything leaves.
- One process owns the ledger. Bots call it over a local socket or HTTP before every order. The cost is an extra hop on every order, and when that process is down no bot trades, which is the safe way for it to fail.
- A shared database. One conditional update checks and reserves in one statement, so two concurrent reservations cannot both fit into the same headroom. The cost is a database round trip per order, and every order for the account queues behind that row.
Three rules carry the ledger:
- The reservation is written before the order is sent. A crash after the venue accepts the order and before a later record is durable leaves a working order nobody counts.
- A fill frees only what it did not cost. It releases its part of the hold and books its actual cost.
- A terminal report can arrive before its last fill. What it says has filled stays reserved until those fills arrive.
The cost: capacity sits idle while orders are working, and a strategy with many resting orders gets refused even though most of them will never fill.
The shared-database version in PostgreSQL
Under PostgreSQL’s default Read Committed isolation, a second updater of the
same row waits for the first to commit and then re-evaluates its WHERE
clause against the updated row
(PostgreSQL 17, section 13.2.1),
so two concurrent reservations cannot both fit into the same headroom.
-- Pseudocode in PostgreSQL syntax: one row per account, run in the
-- transaction that also inserts the order's reservation row.
UPDATE account_budget
SET reserved = reserved + :cost
WHERE account_id = :account_id
AND spent + reserved + :cost <= budget_limit;
-- 1 row updated: reserved. 0 rows: refused, send nothing.The three rules in detail
- Before the send. A process that crashes after sending leaves a record with the client order ID to look up, so generate one that is never reused; add the venue’s order ID once the acknowledgment brings it.
- What a fill frees. It releases its part of the hold, at the limit price and the reserved fee rate, and adds its actual cost to what has been spent; only a better price than the limit or a lower fee than reserved gives capacity back.
- A terminal report before its fills. Venues that publish order state and executions separately can report “canceled, cumulative 70” while the execution stream has delivered 40. The ledger keeps the 30 reserved until those executions arrive. This is the same ordering problem a bot’s position tracking has.
The whole ledger is in the pseudocode.
With the OpenPit SDK 0.10.0 and Pit Officer 0.1.0
In the OpenPit SDK 0.10.0, strategies that submit through one engine with Spot Funds registered reserve from the same holdings for each account and asset. Pit Officer 0.1.0 runs that engine as a self-hosted service: separate bots send through it, and it checks each order before sending it to an Alpaca paper account.
What is still reserved after a partial fill, a replace or a lost cancel?
A request ends nothing: an order holds its reservation until the venue reports it final, and a cancel-replace that can leave both orders live holds for both until each is.
- A fill. Releases its part of the hold and books its actual cost.
- A terminal report. Filled, canceled, rejected or expired: releases the unfilled remainder, and holds for fills still owed until they are booked.
- An accepted cancel request. Releases nothing: the order can still fill until the cancel lands.
- A timeout or an error that leaves the outcome unknown. Releases nothing: look the order up.
- The replace trap. A replace request releases nothing: the old order may fill, or keep working, beside the new one.
Two orders through all of it, at Binance spot, with a 10,000 USD limit for both bots and fees at zero to keep the arithmetic visible:
- t1: A reserves #1, buy 50 @ 100, and sends it. #1 holds 5,000. Free: 5,000.
- t2: #1 fills 20 @ 100. #1 holds 3,000, spent 2,000. Free: 5,000.
- t3: A reserves #2, buy 40 @ 101, and sends a cancel-replace on #1 that allows the cancel to fail. #2 holds 4,040; #1 keeps 3,000. Free: 960.
- t4: The answer: cancel failed, new order placed. Nothing changes. Free: 960.
- t5: B asks to reserve 2,000. Refused: 960 free.
- t6: A report arrives: #1 filled 30 more @ 100 before the cancel reached Binance. #1 holds 0, spent 5,000. Free: 960.
- t7: A cancels #2, and the request times out. #2 keeps 4,040. Free: 960.
- t8: A lookup by the venue’s order ID finds #2 canceled, 10 filled @ 101. #2 holds 0, spent 6,010. Free: 3,990.
A ledger that released #1 at t3, because the request was meant to replace it, would show 3,960 free and admit B at t5. When #1 then fills, the bots have committed 5,000 + 4,040 + 2,000 = 11,040 USD against 10,000.
On Binance the replacement is an order of its own with its own reservation, and one answer covers both splits: cancel failed and new order placed, or the reverse. A cancel fails, for example, when the order has already filled, as at t6; until you look the old order up, it may have filled or may still be working. The cost: a replace needs headroom for both orders at once, and one that does not fit is refused, even when the old order is about to be canceled.
The two replace modes on Binance
In the mode that lets the cancel fail, as at t3, the new order is attempted even when the cancel fails. In the other mode, the new order is never placed after a failed cancel. Until the response arrives, or when it is lost, you do not know which branch ran; holding both reservations until then is a conservative rule of yours, not a venue rule. The modes, the error code and the fields to read are in the Binance note.
A replace at Alpaca and in FIX changes one order
A replace there changes one order instead of placing a second, and it is still not final until the venue says so.
- At Alpaca, while an order is being replaced, buying power is reduced by the larger of the two orders, and a success answer does not guarantee that the open order has been replaced; if it fills before the replacement reaches the venue, the replacement is rejected. The old and the replacement are one working order with two records. Hold the larger of the old and the new open amount while the replace is unresolved; once the old record reports replaced or the replacement is rejected, hold for the record that survives and book any fills on either.
- In FIX, the replacement’s quantity is the order’s new total, fills included: an order for 10,000 fills 1,000, a replace to 12,000 is requested, and 100 more fill while the replace is pending; once it is accepted, 10,900 are left open. The reservation after the replace is the new total minus the cumulative quantity, not the new total.
Sources are in the venue notes.
A cancel ends nothing; the terminal report does
- In FIX, an order for 10,000 has filled 5,000 when the cancel is acknowledged as pending, and 1,000 more fill before the cancel is confirmed. The 1,000 come out of the reservation; the remaining 4,000 are released only on the confirmation.
- In another FIX scenario the order fills completely while the cancel is pending. The last fill report still shows the cancel pending, with nothing left open: the order can no longer fill, and that fill consumes the rest of the hold. The cancel reject that follows, too late to cancel, reporting the order filled, has nothing left to release.
- At Alpaca, an accepted cancel request is acceptance of the request, not of the cancel: the order may report a pending cancel first, and it is settled by the cancel or by a fill that completes it.
The scenarios and codes are in the venue notes.
A lost answer to a cancel
A lost response is an unknown outcome. Binance says a server error must not be treated as a failure: the status could have been a success. Keep the whole reservation and look the order up by the venue’s order ID. A client order ID can change under you: on Binance a successful cancel replaces the order’s client order ID with the cancel’s own, so persist the venue’s order ID and the client ID you give each cancel, and reconcile with both; duplicate orders after a timeout covers that lookup.
Market orders
A market order has no limit price, so its reservation is an estimate. Alpaca’s archived order guide valued a market buy at 2.5% to 4% above the current market price, but a market order can still fill above any estimate. Where the limit must hold, send a limit order.
Fees in the quote asset
Fees in the quote asset make a buy cost more than price times quantity. Reserve with every fee component that can apply, at its highest rate. Binance instead takes a buy’s fee from the base asset received, or in BNB, and lists a symbol’s standard, tax and special rates; see the Binance note.
Sells
A sell adds its proceeds to free capacity only when it fills, never when it is sent; Alpaca’s buying power follows the same rule for sells that close a position. Two bots can also sell the same holding: a sell reserves its base quantity against the position at the same admission point, released on the same terminal rule.
How to recover reservations after a restart
Rebuild the ledger from your own records first, and settle each order against the venue before any bot may reserve again.
Releasing a reservation because the order is not in the open-orders list releases too early: the order may have filled, or may still be in flight.
- Look up every order not yet settled, by the venue’s order ID, or by its client IDs when it has none. An order already marked final locally but with fills still owed counts as not settled.
- Book the fills you missed, and release what a final state leaves.
- Treat a miss as no answer. The order keeps its reservation; look again, and after repeated misses a person decides.
- Count any open order you cannot match, stop new orders and reconcile.
Why a miss is not proof
A lookup that finds nothing does not show that the order never arrived: the lookup and the order can cross, and an ID can have changed. Release a reservation only on positive evidence: a definitive rejection, or a final state and its fills in the venue’s order and trade history. Until then the order stays reserved, and a person decides.
Why locally final is not settled
An order the ledger already marked “canceled, cumulative 70” with 40 booked still owes 30 of fills; a restart that skips final orders leaves their cost unbooked and their hold stranded.
Why an unmatched open order stops trading
An open order the ledger cannot match is unmatched, not necessarily foreign: another sender, a record lost before it was persisted and an ID that changed all look the same. It consumes buying power either way, so count it, stop new orders and reconcile.
Is the venue’s hold counted twice?
The venue’s buying power already includes every order reflected in it, so subtract only your reservations for orders it does not reflect yet.
After a restart the tempting formula is the venue’s buying power minus your reservations, and it subtracts the reflected orders twice. In a cash account with 10,000 USD and A’s 5,000 USD order reflected in the snapshot, Alpaca reports 5,000 of buying power and your ledger holds 5,000; the naive formula gives 0, and B is refused with 5,000 actually free.
An order counts as reflected only if this balance snapshot includes it; an acknowledgment that arrived before you read the balance is not enough. When you cannot tell, count the order as not reflected: that double counts it, which refuses good orders but never admits a bad one.
The formula, and the dangerous opposite error
Free capacity is the smaller of your own headroom and the venue’s, net of the orders it does not show yet:
# Pseudocode.
free = min(limit - spent - reserved,
venue_buying_power - sum(held(o) for o not reflected in this snapshot))When the venue’s term can be the tighter one, the reservation is refused when the order’s hold exceeds that free capacity, not only when the order breaks your limit.
The balance can update after the acknowledgment. Counting an order as reflected when it is not is the dangerous error, and it is easy to make: NautilusTrader’s PR #5184 notes that live cash and margin accounts take balances from venue reports, so a short window can remain after acceptance in which the order is not counted.
On Binance the venue’s number is the asset’s free balance; see the Binance note.
When do separate accounts beat a shared one?
Separate accounts win when isolation matters more than capital efficiency; a shared account with one admission point wins when it does not.
- Separate accounts. The venue enforces the split: one bot cannot spend the other’s cash, and account-level limits apply to each account on its own. Controls set above the account, at the firm level, still see both. No shared component sits on the order path. The cost is idle capital in each account, transfers to rebalance, and a total across the accounts that still exists only on your side.
- One shared account. Unused capacity flows to whichever strategy signals. The cost is the admission point: it is on every order’s path, it must stay up, and a bug in it reaches every bot.
- The better default. Separate accounts, when the strategies belong to different people, when their risk tolerances differ, or when one strategy’s loss must not be able to stop the other.
What should you check before bots share an account?
- Every bot that can trade the account goes through one admission point.
- Check and reserve are one atomic step, under one lock or one conditional database write.
- The reservation is persisted with the client order ID before the send; the venue’s order ID and each cancel’s client ID are added as they appear.
- A fill books its actual cost; capacity grows only by what it cost less than its hold, or by a terminal report.
- Nothing is released on an accepted cancel request, or on a timeout or an error that leaves the outcome unknown.
- A replace reserves the new order before sending and keeps the old order’s hold until its terminal report; at Alpaca, the larger of the two until the replace resolves.
- Market orders reserve a cautious estimate, or go out as limit orders where the limit must hold; buys with fees in the quote asset reserve the fee too.
- On restart, every unsettled order, fills still owed included, is looked up before any bot reserves; a miss releases nothing, and an unmatched open order stops new orders.
- Free capacity subtracts the venue’s hold once.
What does each venue document?
The codes, fields and sources behind everything above, venue by venue.
Binance Spot
- Cancel-replace. Binance added
POST /api/v3/order/cancelReplaceon 2022-06-15: it cancels an existing order and places a new one on the same symbol. In the REST specification (as of 2023-07-18),STOP_ON_FAILUREskips the new order when the cancel fails, andALLOW_FAILUREattempts it anyway. A cancel failure with a successful new order comes back as code-2021, “Order cancel-replace partially failed”, and the general section assigns HTTP409to a partial success; the same code also covers a successful cancel with a failed new order, so decide bycancelResultandnewOrderResultin the body. In the example above, t4 is-2021with cancelFAILUREand new orderSUCCESS. - Unknown outcome. The REST specification says an HTTP
5XXmust not be treated as a failure: “the execution status is UNKNOWN and could have been a success”. - Client order ID after a cancel. A successful cancel replaces the order’s
clientOrderIdwith the cancel’snewClientOrderId(WebSocket API, as of 2023-07-18). Look an order up byorderIdalone: Binance answers-2039when the IDs in one query disagree (changelog, 2025-04-08). - Order and trade history.
GET /api/v3/allOrdersandGET /api/v3/myTrades(REST API). - Balances.
GET /api/v3/accountreportsfreeandlockedper asset, and the spot glossary (as of 2023-07-18) defineslockedas the amount locked in open orders and other services. Usefreeas the venue’s number in the free-capacity formula. - Fees. A buy’s fee comes from the base asset received, or in BNB, and
GET /api/v3/account/commissionlists a symbol’s standard, tax and special rates (commission FAQ).
Alpaca
- Buying power and open orders. The order guide (archived 2025-04-11) says available buying power is reduced by open buy long and sell short orders, while sell long and buy to cover orders do not replenish it until they execute. It valued a market buy at 2.5% to 4% above the current market price.
- Replace. The
Broker API order reference
(archived 2025-04-11): while an order is being replaced, buying power is
reduced by the larger of the two orders. A success return code does not
guarantee that the open order has been replaced; if it fills before the
replacement reaches the venue, the replacement is rejected. Once a replace
succeeds, the old record reports
replaced. - Cancel. An accepted cancel request is answered with HTTP 204; the order
may report
pending_cancelfirst, and it is settled bycanceledor by a fill that completes it.
FIX
From FIX Order State Changes:
- C.1.b, a fill before a replace is accepted. An order for 10,000 fills 1,000, a replace to 12,000 is requested, and 100 more fill while the replace is pending; once it is accepted, LeavesQty is 10,900.
- B.1.b, fills while a cancel is pending. An order for 10,000 has filled 5,000 when the cancel is acknowledged as Pending Cancel, and 1,000 more fill before Canceled arrives.
- B.1.c, filled before the cancel is accepted. The last Trade report still shows Pending Cancel, with CumQty 10,000 and LeavesQty 0; the cancel reject that follows, too late to cancel, carries OrdStatus Filled.
Where is the ledger as pseudocode?
The ledger, recovery and free capacity, as pseudocode
The ledger for buys with the fee charged in the quote asset. Every event goes through one function that recomputes what the order still holds.
# Pseudocode. One ledger per account. "atomically" is one lock in one
# process, or one database transaction; persist() is durable when it returns.
held(o): # what one order still holds
left = (o.final_cum if o.final else o.qty) - o.filled
return max(left, 0) * o.limit_price * (1 + o.fee_rate)
change(o, edit): # every event goes through here
atomically:
before = held(o)
edit(o)
account.reserved += held(o) - before
persist(account, o)
reserve(client_id, qty, limit_price, fee_rate): # before the order leaves
o = Order(client_id, qty, limit_price, fee_rate,
filled = 0, final = false, state = RESERVED, exec_ids = {})
atomically:
if account.spent + account.reserved + held(o) > account.limit:
return REFUSED
account.reserved += held(o)
persist(account, o)
return o
after_send(o, outcome):
REJECTED: change(o, final = true, final_cum = 0) # a definitive refusal
ACCEPTED: change(o, state = WORKING,
venue_order_id = outcome.order_id)
otherwise: change(o, state = UNKNOWN) # timeout, 5XX: hold it all
on_fill(o, exec_id, qty, price, fee):
change(o, if exec_id not in o.exec_ids: # a repeat counts once
o.exec_ids += exec_id
o.filled += qty
account.spent += qty * price + fee)
on_terminal(o, cum_qty): # filled, canceled, rejected, expired
change(o, final = true, final_cum = cum_qty)Recovery runs before any bot may reserve on the account:
# Pseudocode. Runs before any bot may reserve on this account.
recover(account):
for o in persisted orders
where not o.final or o.filled < o.final_cum: # fills still owed
# orderId alone: Binance answers -2039 when the IDs in one query disagree
r = venue.order(o.venue_order_id) if o.venue_order_id
else first found of venue.order(c) # one ID per lookup
for c in [o.client_id] + o.cancel_client_ids
if r.found:
for f in fills of r not yet in o.exec_ids:
on_fill(o, f.exec_id, f.qty, f.price, f.fee)
if r.terminal:
on_terminal(o, r.cum_qty)
else:
look again later # o keeps its reservation
after repeated misses: alert a person
for v in venue.open_orders():
if v matches no ledger order by any of its IDs:
count v against the limit; stop new orders; alert a personThe free-capacity formula is in the section on the venue’s hold.
What else do people ask?
Can you run multiple trading bots on one account?
Yes, if every order goes through one place that checks and reserves for the account in one step before the order is sent. Without that, any two bots whose checks read balances that miss each other’s orders can both spend the same capacity, and the venue’s buying-power check rejects the second only when the account’s own buying power runs out, not when your limit does.
Do open orders count against buying power?
At the venue, it depends on the venue and the side. At Alpaca, open buy long and sell short orders reduce buying power while they are open, and sell long and buy to cover orders return it only when they execute. An order still in flight counts nowhere at the venue, which is why the reservation has to be yours.
Should each strategy get a fixed budget or share one pot?
Both fit one ledger: give each strategy its own limit and keep a total for the account, and reserve against both in the same atomic step. Fixed budgets leave capital idle; a shared pot lets one strategy take capacity the other needed. Per-strategy limits under a total cap are a common middle.
What happens to buying power after a cancel/replace?
Until the venue reports the outcome, both the old and the new order may be
live. Binance cancelReplace with ALLOW_FAILURE can place the new order
while the old one may still be working; reserve for both until each has a
final state. Alpaca reduces buying power by the larger of the two while a
replace is pending; hold the larger until the replace resolves, then the
amount of the order that survives.
Where to go next
- Duplicate orders after a timeout: what to do when an order or a cancel has an unknown outcome.
- Why your trading bot’s position drifts from the broker’s: tracking the position the fills produce, and rebuilding it after a reconnect.
- Pit Officer 0.1.0: pre-trade risk checks outside your trading bot: one admission point for several bots, as a self-hosted service.
- FIX Order State Changes: scenarios B.1.b (fills while a cancel is pending), B.1.c (filled before the cancel is accepted), C.1.b (a fill before a replace is accepted).
- OpenPit SDK: Spot Funds, Pre-trade Pipeline.