Pit Officer blog
Engineering articles about pre-trade risk, trading systems, and order controls.
- Latest
Articles
- 10 min read
API order rejected for insufficient balance but you have enough
What a bot can spend is derived, not read: the free amount of the asset the order debits, in the wallet it debits, after venue holds and fees, from a snapshot that reflects the last balance change the bot knows of. When a field is missing or the snapshot may be older, the answer is unknown, not a number.
- 8 min read
Stop loss not covering your position after a partial fill
After a partial entry, a canceled remainder, a rejected child or a partial exit, the position can have no working stop, or one too large, and no venue message says so. After every event, compare armed stop quantity with the open position, and check separately that no exit can open the opposite position.
- Release10 min read
Pit Officer 0.2.1 and 0.3.0: live IBKR, Binance and eToro, open P&L limits
Pit Officer 0.2.1 adds Interactive Brokers, Binance and eToro trading connections, live trading on every venue, a mode for trading from zero, and P&L bounds that count open positions; 0.3.0 adds live-account steps per venue. A breached bound rejects the next order and blocks new orders, exits included.
- Release9 min read
OpenPit SDK 0.9.0 and 0.11.0: position ceilings and open P&L bounds
Per-order caps and a realized-loss limit never see what the account holds. OpenPit SDK 0.9.0 adds a Spot Funds position limit per account and asset that counts working orders, in every SDK; 0.11.0 adds unrealized and total P&L bounds, set from Rust, C and Go, that block the account no later than its next order.
- 10 min read
Multiple trading bots on one account: sharing buying power
Two bots that check a shared balance and then send both pass when each check reads a balance that does not yet show the other's order. Check and reserve atomically at one admission point, persist the reservation before sending, and release it only on a terminal report, never on a cancel acknowledgment or a timeout.
- Release10 min read
Pit Officer 0.1.0: pre-trade risk checks outside your trading bot
Pit Officer 0.1.0, the first beta, is a self-hosted service where the OpenPit engine checks every order before Officer sends it to Alpaca, whether it came from the web panel, trading software over REST or an AI agent over MCP. A rejected order sends nothing, and an agent cannot loosen the limits it trades under.
- 10 min read
What happens if my trading bot crashes with a position open?
A kill switch inside the bot dies with the bot; its orders and position stay at the venue. A venue timer can cancel the protective stop with the entries, and a closing order can be throttled while cancels pass. Persist a halt that blocks new risk across restarts, allow only verified exits, and drill a crash on paper.
- 10 min read
How to handle stale market data in a trading bot's loss limits
A loss limit is only as current as the oldest price in it. Measure each required price's age from its source time at decision time, tell a quiet market from a dead feed with heartbeats and sequence numbers, and while any price is stale treat P&L as unknown: no new exposure, verified risk-reducing orders only.
- 9 min read
Trading bot duplicate orders after a timeout: did it fill?
A timeout after the send, an unknown-status error, an HTTP server error or an empty body leaves the outcome unknown. Keep its full size reserved until the order stream or a lookup by its ID finds it, or a person confirms it is absent. Never resend blindly: Binance accepts the same client order ID again after a fill.
- Release7 min read
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.
- 10 min read
API order rejected for insufficient balance but you have enough
What a bot can spend is derived, not read: the free amount of the asset the order debits, in the wallet it debits, after venue holds and fees, from a snapshot that reflects the last balance change the bot knows of. When a field is missing or the snapshot may be older, the answer is unknown, not a number.
- 8 min read
Stop loss not covering your position after a partial fill
After a partial entry, a canceled remainder, a rejected child or a partial exit, the position can have no working stop, or one too large, and no venue message says so. After every event, compare armed stop quantity with the open position, and check separately that no exit can open the opposite position.
- Release10 min read
Pit Officer 0.2.1 and 0.3.0: live IBKR, Binance and eToro, open P&L limits
Pit Officer 0.2.1 adds Interactive Brokers, Binance and eToro trading connections, live trading on every venue, a mode for trading from zero, and P&L bounds that count open positions; 0.3.0 adds live-account steps per venue. A breached bound rejects the next order and blocks new orders, exits included.
- Release9 min read
OpenPit SDK 0.9.0 and 0.11.0: position ceilings and open P&L bounds
Per-order caps and a realized-loss limit never see what the account holds. OpenPit SDK 0.9.0 adds a Spot Funds position limit per account and asset that counts working orders, in every SDK; 0.11.0 adds unrealized and total P&L bounds, set from Rust, C and Go, that block the account no later than its next order.
- 10 min read
Multiple trading bots on one account: sharing buying power
Two bots that check a shared balance and then send both pass when each check reads a balance that does not yet show the other's order. Check and reserve atomically at one admission point, persist the reservation before sending, and release it only on a terminal report, never on a cancel acknowledgment or a timeout.
- Release10 min read
Pit Officer 0.1.0: pre-trade risk checks outside your trading bot
Pit Officer 0.1.0, the first beta, is a self-hosted service where the OpenPit engine checks every order before Officer sends it to Alpaca, whether it came from the web panel, trading software over REST or an AI agent over MCP. A rejected order sends nothing, and an agent cannot loosen the limits it trades under.
- 10 min read
What happens if my trading bot crashes with a position open?
A kill switch inside the bot dies with the bot; its orders and position stay at the venue. A venue timer can cancel the protective stop with the entries, and a closing order can be throttled while cancels pass. Persist a halt that blocks new risk across restarts, allow only verified exits, and drill a crash on paper.
- 10 min read
How to handle stale market data in a trading bot's loss limits
A loss limit is only as current as the oldest price in it. Measure each required price's age from its source time at decision time, tell a quiet market from a dead feed with heartbeats and sequence numbers, and while any price is stale treat P&L as unknown: no new exposure, verified risk-reducing orders only.
- 9 min read
Trading bot duplicate orders after a timeout: did it fill?
A timeout after the send, an unknown-status error, an HTTP server error or an empty body leaves the outcome unknown. Keep its full size reserved until the order stream or a lookup by its ID finds it, or a person confirms it is absent. Never resend blindly: Binance accepts the same client order ID again after a fill.
- Release7 min read
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.
- 10 min read
Why your trading bot's position drifts from the broker's
A trading bot's position is the confirmed filled quantity plus the open quantity of every order without a final outcome. Track cumulative fills per order, rebuild after a reconnect by buffering the stream before the snapshot, and check new orders against the worst side of that range.