Pit Officer 0.1.0: pre-trade risk checks outside your trading bot

A limit kept in your bot or an AI agent's prompt can fail when they do. Pit Officer 0.1.0 checks every order in a separate service before it reaches Alpaca.

Contents

Your bot caps every order at 100 shares, and the cap lives in the bot: a bug sends 500 anyway, and an AI agent given the cap in its prompt can be talked into 10,000.

  1. You put the rule in the prompt. “Never more than 100 shares.”
  2. The agent is talked round. It decides to buy 10,000 shares of AAPL.
  3. It sends the order to the broker. Nothing between the agent and the broker knows the rule.
  4. The order goes out. 1.9 million USD, a hundred times the cap.

Pit Officer 0.1.0, the first beta, moves that decision out: a separate service on your own machine where the OpenPit engine checks every order before Officer sends it to your broker. An order over the cap comes back rejected, and nothing is sent.

  • The decision leaves the bot. Orders reach the broker through Officer, and the OpenPit engine checks each one before it is sent. A rejected order is never sent.
  • Four kinds of limit at this release: order rate, order size by quantity or notional, Spot Funds P&L bounds, and a block on an account or an account group.
  • An agent gets only the tools you enable. Every MCP tool that changes state ships disabled, and Officer refuses any MCP call that would loosen risk state - lift a block, raise a cap, grant trading access - whatever the agent was told.
  • The limits bind only if the bot has no other road to the broker. Officer holds the Alpaca keys; the bot holds an Officer token.
  • 0.1.0 is a beta: one connection type (Alpaca), orders sent to paper accounts, and no database migration between versions.

What does Pit Officer 0.1.0 do?

It sits between whatever sends your orders and your Alpaca account, and lets an order through only after the OpenPit engine has accepted it.

Officer runs on your own computer from one Docker command, which publishes it on that computer’s loopback address. It has three ways in, each with its own credential when you choose token access in the first-run setup:

  • You, in the web panel. A panel password, then a session.
  • Trading software, over REST. An API token.
  • An AI agent, over MCP. An agent token. It works on the agent’s own surface only, so an agent cannot reach the REST routes its MCP tools do not expose.

The checks are the OpenPit engine’s own policies; Officer 0.1.0 is built on OpenPit 0.10.0 (go.mod at v0.1.0).

Terms this post uses

A pre-trade check is a decision, made before an order leaves for the venue, on whether it may go out at all. A trading connection is Officer’s link to one broker account: the provider, the mode (only paper at this release), and the credentials, which Officer accepts on write and never returns (API notes, Trading).

The address, the three surfaces and their credentials

The Docker command publishes Officer on the loopback address http://127.0.0.1:8787, so it answers this computer and not the network; on Linux, Docker Engine older than 28.0.0, or older than 28.3.3 with firewalld, can still let other machines on the local network reach it (README, quickstart).

The same address serves all three surfaces (quickstart, API notes, Mount points):

  • Web panel at /: the panel password, then a session cookie.
  • REST at /api/v1, with its reference at /docs: the API token, Authorization: Bearer pit_api_....
  • MCP over HTTP at /mcp: the agent token, Authorization: Bearer pit_mcp_....

The agent token sent to /api/v1 is refused with 403 wrong_token. The binary also runs as a local stdio MCP server, pit-officer mcp, for MCP clients that launch their servers themselves (configuration reference).

Where does a rejected order stop?

At one of three checks before Alpaca, or at the send itself; from any caller, only an order the engine accepts reaches the send.

A rejection at any of the three checks sends nothing to Alpaca. At the send, Officer reports the order refused, which is final, or unknown: the order may exist at Alpaca, or a refusal is not settled yet, so read it by its ID before you send anything that replaces it. A blind resend can create a second order, which is its own subject: duplicate orders after a timeout.

What each check stops, and what the REST call answers

The REST call that sends an order, POST /api/v1/orders/send-paper, walks the gates in this order (OpenAPI at v0.1.0, sendPaperOrder and VenueSend):

  • Request. Stops the order when the body breaks the schema, the account has no grant on the connection, the instrument is not mapped, or the connection is disabled. You get an HTTP error; no order is held; nothing reaches Alpaca.
  • Alpaca rules. Stops it, for example, when the asset is inactive or not tradable, the order is not sized in quantity, timeInForce is missing or not allowed, a fractional equity order is not day, or an equity limit price has more than 2 decimal places (4 below 1 USD). You get 422 with the venue’s reason, or 502 if Alpaca cannot be read; no order is held; nothing reaches Alpaca.
  • Engine. Stops it when a policy rejects it or the account is blocked. You get 201 with verdict: "reject" and reasons, and no venueSend; nothing reaches Alpaca.
  • Send. Alpaca refuses it, Officer provably did not hand it over, or the outcome cannot be established. You get 201 with venueSend.status refused or unknown; at Alpaca the order was refused or never received, or its fate is unknown.

Every order, from a bot, an AI agent or the panel, passes a request check, an Alpaca rules pre-check and the OpenPit engine before Officer sends it; each gate rejects with nothing sent, and only the send step can leave the outcome unknown.

The Alpaca rules gate reads the venue’s own asset data: US equities and crypto only, timeInForce one of day, gtc, opg, cls, ioc, fok, and for crypto only gtc or ioc (alpaca.go at v0.1.0). Catching these before the engine reserves anything means an order Alpaca would refuse anyway does not hold buying power on the way.

Refused, unknown, and why you send your own ID

refused is definitive: either Alpaca refused the order or Officer provably did not hand it over, and either way the order is recorded canceled with nothing left open and its reservation released. unknown is not a refusal: the call could not establish or record the outcome, so the order may exist at Alpaca, or Alpaca refused it but the cancellation is not recorded yet or could not be confirmed. Read GET /api/v1/orders/{id}, which the API notes name as authoritative, before you send anything that replaces it; Officer’s runtime keeps reconciling every order that reached the send step (API notes, Trading).

That lookup needs the order’s id, and a caller that lost the whole response never saw a server-generated one, so send your own id and record it before the call, as the first order below does; a reused id is refused with 409.

Which limits can you set in 0.1.0?

Four kinds, kept by Officer; the engine applies each one you configure to a new order that reaches its check.

  • Order rate. At most so many order attempts in a time window, per account exactly; broker-wide or per settlement asset up to twice as many can pass at a window boundary. Rejected attempts that reach the rate check count too, so a bot that retries fast keeps its window full. It caps a runaway loop.
  • Order size. A cap on quantity per underlying asset or on notional per settlement asset, broker-wide or per account. It stops a quantity bug or a fat-fingered order.
  • Spot Funds P&L bounds. A lower bound, an upper bound or both on an account’s realized P&L, globally, per account group or per account. When the P&L is outside a bound you set, or its calculation has halted, the engine rejects the account’s new orders; a fill that gets it there blocks the account.
  • Block. An account or a group you block: the engine rejects every new order from it before any policy runs.

The block is the piece the crashed-bot article asked for: a halt that does not live in the bot’s process. Officer stores it in its own database, so a bot that crashes and restarts comes back to an account still blocked until you unblock it. The block gates new orders only: nothing in the 0.1.0 documentation says Officer cancels working orders or closes positions when your bot dies, so the venue timers and the second-process watchdog from that article still apply.

The four limits in the API
  • Order rate (PUT /limits/rate): passes at most maxOrders order attempts per windowMs milliseconds; every attempt that reaches the rate check counts, rejected ones included. Broker-wide and per settlement asset it counts in an approximate fixed window that can let up to twice maxOrders through at a window boundary; per account, and per account and settlement asset, in a precise sliding one (OpenPit rate-limit policy at v0.10.0). A request refused before the engine check, at the request or Alpaca rules gate, is not counted.
  • Order size (PUT /limits/order-size): maxQuantity keyed on the underlying asset, maxNotional keyed on the settlement asset, broker-wide or per account. An order over the quantity cap alone is rejected by OrderSizeLimitPolicy with reason “order quantity exceeded”, which Officer reports as code order_qty_exceeds_limit (OpenPit wiki, Policies, 2026-10-27, Officer reject codes at v0.1.0).
  • Spot Funds P&L bounds (PUT /limits/spot-funds-pnl-bounds): a lowerBound, an upperBound or both in one currency, globally, per account group or per account, on the account’s realized P&L, which the engine builds from reconciled fills and fees. Its policy name in the API is spot_funds_pnl_bounds_kill_switch (OpenPit wiki, Spot Funds, 2026-10-27, Account Blocking, 2026-10-27).
  • Block (POST /accounts/{code}/block with a reason, and the same on a group): a blocked account, or any member of a blocked group, is rejected before any policy runs. The account’s blocked field reports whether the account or its group is blocked; an unblocked account can still fail on a missing grant, funds or a limit.

Officer stores the block with the account on the pit-officer-data volume (schema at v0.1.0), and clearing it is an explicit unblock.

How do you send a first order through Officer?

Start it, finish the setup, describe what you trade, fund the account, set one limit, and send one order over REST.

  1. Start Officer with the README’s Docker command, pinned to the 0.1.0 image: the README’s own tag follows the newest stable release.
  2. Finish the first-run setup in the panel. Choose multi-account mode: on a fresh Officer, single-account mode acts only on one account it creates and refuses to create another. Choose token access to get an API token for your bot.
  3. Describe what you trade. A fresh Officer has nothing set up. Create the assets AAPL and USD first, because Officer will not map an instrument whose asset it does not know; then an account named desk in USD, an Alpaca connection in paper mode with your paper keys, an enabled AAPL mapping, and access for desk to the connection.
  4. Fund the account in Officer. The engine checks a buy against the USD balance Officer records, not Alpaca’s, and rejects an unfunded one: record no more than the venue cash you are willing to deploy.
  5. Set the limit: at most 100 AAPL per order on desk.
  6. Send the order: buy 10 AAPL at a limit of 190 USD, under an ID you recorded before the call, so you can look the order up even if the response never arrives.
  7. Read the decision. An order the engine accepts and Alpaca acknowledges comes back with both answers. The same order for 500 shares is a successful call too, rejected, with nothing sent to Alpaca; the panel shows the recorded rejection and its reason.

In the panel, the 500-share order's pre-trade rejection: the order-size policy reports order quantity exceeded, requested 500 against a maximum of 100.

Branch on the verdict, not on the HTTP status: a risk reject is a decision, not an error. To test a limit without sending anything, Officer’s order check takes the same order economics and answers whether they would pass and, if not, why; it records and reserves nothing.

The commands, request bodies and responses, step by step
  1. Start Officer with the README command, pinned to the release: the README’s latest tag follows the newest stable release, 0.1.0 stays on this one.

    docker run -d --name pit-officer --restart unless-stopped -p 127.0.0.1:8787:8787 -v pit-officer-data:/data ghcr.io/openpitkit/officer:0.1.0

    docker ps --filter name=pit-officer shows (healthy) when the panel answers; that says nothing about whether anything is set up yet.

  2. Finish the first-run setup at http://127.0.0.1:8787/setup: welcome, accounts, encryption, approval signing, access, connecting your AI agent, done. Until it is finished, /api/v1 and /mcp answer 503 setup_required. Single-account mode acts only on the account it creates, default (API notes, Single-account mode).

  3. Describe what you trade: the assets AAPL and USD, the account desk with currency USD, the Alpaca connection in paper mode, the AAPL mapping and the access grant. Officer refuses an instrument mapping whose asset it does not know, and never creates one itself (quickstart, What comes next).

  4. Fund the account. An unfunded buy is rejected with insufficient_funds (engine test at v0.1.0). The size and rate limits run first, and the funds check only for an order that passes them (OpenPit wiki, Policies, 2026-10-27), so the deposit is what lets the 10-share order through. Officer 0.1.0 does not read the Alpaca balance: each buy is checked against the USD balance this deposit seeds, not against Alpaca’s. 100,000 USD covers the 1,900 USD first order. Record it with POST /api/v1/accounts/desk/adjustments?missingAccount=reject, in the body shape the tag’s integration test uses:

    {
      "type": "deposit",
      "asset": "USD",
      "averageEntryPrice": "1",
      "realizedPnl": "0",
      "balance": {"mode": "absolute", "value": "100000"}
    }
  5. Set the limit with PUT /api/v1/limits/order-size?missingAccount=reject and this body:

    {
      "scope": "account_underlying_asset",
      "account": "desk",
      "asset": "AAPL",
      "maxQuantity": "100",
      "maxNotional": ""
    }
  6. Send the order. With one enabled paper connection available to desk, destination needs only the Alpaca route; quantities and prices are exact decimal strings, not floats. price makes it a limit order; without it the order is a market order, which the funds check prices off a live mark quote and rejects when Officer has none. The id is yours.

    # Body shape as in TestTradingSendPaperEndToEnd at v0.1.0, which sends it
    # over REST to a stub Alpaca.
    curl -s http://127.0.0.1:8787/api/v1/orders/send-paper \
      -H "Authorization: Bearer $PIT_API_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "id": "desk-0001",
        "account": "desk",
        "baseAsset": "AAPL",
        "quoteAsset": "USD",
        "side": "buy",
        "amountKind": "quantity",
        "amountValue": "10",
        "price": "190",
        "destination": {"route": {"timeInForce": "day"}}
      }'
  7. Read the decision. When the engine accepts the order and Alpaca acknowledges it, the response carries both answers (angle brackets mark values your call returns):

    {
      "id": "desk-0001",
      "verdict": "accept",
      "signedApproval": "<unsigned envelope>",
      "keyId": "",
      "venueSend": {
        "status": "acknowledged",
        "venueOrder": {
          "connection": "<connection id>",
          "venueAccount": "<venue account>",
          "route": {"timeInForce": "day"},
          "clientOrderId": "<client order id>",
          "venueOrderId": "<Alpaca order id>",
          "sendAttempted": true,
          "createdAt": "<time>"
        }
      }
    }

    The same order for 500 shares, sent with "id": "desk-0002", is a successful call too, 201, but with no venueSend: nothing went to Alpaca.

    {
      "id": "desk-0002",
      "verdict": "reject",
      "signedApproval": "<unsigned envelope>",
      "keyId": "",
      "reasons": [
        {
          "code": "order_qty_exceeds_limit",
          "scope": "order",
          "policy": "OrderSizeLimitPolicy",
          "reason": "order quantity exceeded",
          "details": "requested 500, max allowed: 100"
        }
      ]
    }

    Officer maps the engine’s reject code and scope to its own names, and the policy, reason and details come from the OpenPit order-size policy (Officer mapping at v0.1.0, OpenPit order-size policy at v0.10.0). Branch on verdict; the response fields are the SignedApproval and VenueSend schemas. Approval signing is off on a fresh Officer, so unless you turned it on in setup, keyId is empty and the envelope is unsigned; with signing on, signedApproval is an Ed25519-signed envelope of the decision (quickstart, approval code at v0.1.0).

The order check is POST /api/v1/orders/check: it takes the same order economics, without id or destination, and answers with check.passed and the engine’s rejects.

What can an AI agent do through MCP?

Only what you enable, and never loosen its own limits.

  • Every tool that changes state ships disabled. Read-only tools are on; the others stay off until you enable each by name in the panel, and a call to a disabled tool is refused, not run. An agent that trades on paper needs one tool enabled: the one that sends a paper order.
  • Loosening is refused over MCP. A call that would lift a block, drop or weaken a limit, or reset a rate window changes nothing; a replacement limit is stored only if it is at least as strict. Granting trading access and creating, enabling or re-keying a connection are always refused through MCP. The panel and REST are not affected.
  • Every order records where it came from: the panel, REST, MCP or the system. For control-plane actions, the source comes from the surface that served the request, never from a header or body the client sends.

The panel's MCP access list on a fresh Officer: list_groups and check_order are enabled, while set_limit, create_account and update_account are disabled and return a "disabled in panel" notice to the agent.

Unlike a limit in the prompt, this holds. An agent that reaches Officer only through MCP and has been persuaded to buy 10,000 shares can still submit that order to Officer. Once past the request and Alpaca checks, the engine rejects it on the 100-share cap, and no MCP tool raises the cap. Within the tools you enabled the agent can still send orders up to the limits; what it cannot do through MCP is move them. An agent that can also run commands on the machine is outside this guarantee, as the next section says.

The MCP tools and refusals by name

The rules are in the API notes, MCP tools.

  • For an agent that trades on paper, enabling send_paper_order is enough; list_orders, get_limits and the other reads are already on. In the panel’s list, reads such as check_order are ticked and set_limit and the other commands that change state are not.
  • A call that would loosen risk state answers loosening_refused and changes nothing. set_limit stores a replacement barrier only if it is at least as strict as the one it replaces.
  • The order sources are panel, api, mcp and system (Audit source).

What does it cost, and what does 0.1.0 not do?

The costs come with the design, and the gaps come with a first beta.

  • The bot must give up the broker keys. If it keeps its own Alpaca key, it can send around Officer, and none of the limits apply to those orders.
  • Officer becomes the only road out. When it is down, the bot cannot send: the safe failure, but a failure. Orders already at Alpaca stay there.
  • No cancel or replace through Officer. A working order is canceled at Alpaca, from its dashboard or with keys held apart from the bot; prefer immediate-or-cancel or day orders while this holds.
  • Two more requests per order. Officer looks the asset up at Alpaca twice before each send, which also spends your Alpaca rate limit; measure the latency yourself.
  • Loopback by default. A bot on another host needs a wider bind, only with token access on, and the address it uses for Officer on Officer’s allowed list.
  • Tokens are not a boundary against your own machine. Software that runs commands as you, or controls Docker, gets past them.
  • Credentials are stored in plain text without a master key. With one, a sealed database whose key is lost never opens again.
  • Alpaca paper trading only. And no database migration between versions.
The details behind each cost
  • Keys. Move the Alpaca keys into the trading connection and give the bot an Officer API token instead.
  • No cancel or replace. At 0.1.0 Officer’s cancel route refuses a venue-linked order with 409 venue_order_managed (API notes, Trading). Cancel at Alpaca from its dashboard or with keys held apart from the bot; prefer ioc or day orders.
  • Only road out. Watch the health check and decide in advance who restarts Officer.
  • More hops. A local HTTP call and an engine check sit in front of every send, and Officer calls GET /v2/assets/{symbol} at Alpaca twice, in the pre-check and again just before each POST /v2/orders: two more remote round trips, and two more requests against your Alpaca rate limit, per order (alpaca.go and runtime.go at v0.1.0). This release publishes no latency figure; measure it before you put a latency-sensitive strategy behind it.
  • Loopback. The panel, REST and MCP are reachable from the computer that runs Officer. A wider bind is what the configuration reference calls a deliberate operator decision; widen it only in token mode, because open mode asks no surface for credentials. A bot that reaches Officer by another name - another host’s address, a container service name, or host.docker.internal from its own container - needs that name in PIT_OFFICER_ALLOWED_HOSTS (configuration reference, Allowed hosts).
  • Tokens. Software that can run commands as you, or control Docker, gets past the token and the panel password, and the stdio MCP server asks for no credentials at all (quickstart, configuration reference).
  • Master key. Trading credentials, the access tokens and a signing key are sealed only when you supply a key through PIT_OFFICER_MASTER_KEY or PIT_OFFICER_MASTER_KEY_FILE; that key is not recoverable, and a sealed database without it never opens again (Master key).
  • Paper only. Alpaca is the one trading connection, for US equities and crypto, sized in quantity. The API sends to paper, and creating a live connection is refused with live_trading_unavailable (OpenAPI at v0.1.0, connection code at v0.1.0).
  • No migration. The configuration reference says so directly. Keep your accounts, limits and mappings reproducible rather than treating the beta’s database as permanent.

Checklist

  • The bot holds no broker key; Officer’s trading connection does.
  • A person can cancel a working order at Alpaca without the bot.
  • Officer runs on the bot’s machine, or its bind and allowed hosts are a decision you wrote down.
  • Each account the bot trades has an order-size cap and a rate limit.
  • Your code branches on the verdict and on the send status, and treats an unknown outcome as “read the order”, never as “resend”.
  • An agent has the paper-order tool and nothing else that changes state, and never the API token.
  • You have blocked the account from the panel, watched the bot’s next order come back rejected, and unblocked it.
  • Your bot sends its own ID with every order and records it before the call.
  • You have stopped Officer and seen what your bot does when it cannot send.
  • A master key is set and stored somewhere other than the machine, or you accepted plain-text credentials knowingly.

What else do people ask?

Does Officer replace the limits in my bot?

It replaces the ones that must hold when the bot is wrong: size, rate, a block, and a kill switch on realized P&L. An open position’s loss is not bounded by Officer at 0.1.0, so stops stay in the bot or at the venue. Checks that need the strategy’s own state, such as not re-entering after a stop, stay in the bot. Officer sees each order, not the reason the bot sent it.

Can an AI agent change its own limits through MCP?

It can tighten them if you enable the tool, never loosen them. Officer refuses any MCP call that would lift a block, weaken a barrier or reset a rate window with loosening_refused, and it refuses trading-access grants and connection changes through MCP outright. Those changes go through the panel or REST.

What happens to my orders if Officer stops?

Orders Alpaca already accepted stay at Alpaca and can still fill; Officer 0.1.0 cannot cancel them, running or not, so cancel them at Alpaca. New orders cannot be sent until it is back, because the bot no longer holds a broker key. When it is back, GET /orders/{id} with the id you recorded before the send is the answer for any order whose outcome you did not see.

Which brokers does Pit Officer 0.1.0 support?

Alpaca, for US equities and crypto, and paper trading only: creating a live connection is refused with live_trading_unavailable at this version.

Where to go next

Was this article useful?