anchor-demo / options trader bot / epics
Epics and use cases
What the options trader bot does, written as two epics, each made of use cases told step by step: who acts, what they see, what can go wrong at each step and where that leads. Every requirement is carried by steps, and only the steps name code. The tests listed under a step were run under a tracer, and the code a step names is the code those tests ran.
OB-1 a requirementconnect() code, opens the line on GitHubUC-1.2 a step that carries it
EPIC-1 · epic
Trade one day of SPY 0DTE opening-range breakouts
- Actor
- Trader
- Trigger
- the trader starts the bot before or during a trading day
- Before
- TWS or IB Gateway runs with the API on PORT; the account has live SPY and US options data
- Succeeds when
- each breakout of the day is traded within the trader's limits, its exits held at IB, and logged as one row
- At worst
- no order or position of the bot's is left behind, and every trade it made is in the log
- Why
- the original script's purpose: the 15-minute opening range breakout on SPY 0DTE options, sized to a small balance
How the trader acts: runs python zdt_autopilot.py, with --live for a live account, and presses Ctrl+C to stop
How they see the result: the console's tagged lines ([SIGNAL], [FILLED], [TRADE CLOSED]) and trade_execution_log.csv
Steps, each a use case below
- The trader starts the bot, and it connects to the right kind of account. UC-1: Start the bot on the right account
- The bot reads the opening range and prints the two triggers. UC-2: Read the opening range
- The bot watches SPY until it breaks out past a trigger. UC-3: Watch SPY for a breakout
- The bot buys today's out-of-the-money option, sized to the balance. UC-4: Enter a trade on the signal
- IB holds the stop and the target until one fills, or the bot flattens before the close. UC-5: Exit the trade
- The bot logs the trade and decides whether to take another. UC-6: Log the trade and decide whether to go on
- The bot stops and leaves nothing of its own working or held. UC-7: Stop and leave nothing behind
Alternate paths
- 1a When the exit rules are not set: The bot runs SIGNALS ONLY: steps 2 to 4 print the order it would send, and no order is sent. Ends: nothing is left behind (the minimal guarantee).
- 2a When IB lists today as closed: The bot says so and stops. Ends: nothing is left behind (the minimal guarantee).
UC-1 · use case · EPIC-1 step 1
Start the bot on the right account
- Actor
- Trader
- Trigger
- python zdt_autopilot.py, or with --live
- Before
- TWS or IB Gateway is running with the API on PORT
- Succeeds when
- connected; the banner says PAPER or LIVE with the account ID, and [ACCOUNT] shows the balance
- At worst
- on any refusal nothing is sent to IB and the bot exits
- Why
- a bot that can trade real money has to know which account it is on before anything else
How the trader acts: runs the script, adding --live only for a live account
How they see the result: the banner's PAPER or LIVE and account ID, the [ACCOUNT] line, or a [REFUSED] line
Steps
- The bot checks the exit rules are possible before anything else.
- It refuses a live port unless --live was given.
- It connects and reads the account IDs; an account that is not a paper account needs --live.
- It prints PAPER or LIVE with the account ID.
- It reads the account's USD TotalCashBalance and its own budget, STARTING_BUDGET_USD before its first trade or the log's last EndingBalance after; [ACCOUNT] and [BUDGET].
Alternate paths
- 1a When the stop is not between 0 and 1, or the target is not above 0: [REFUSED] names both limits; nothing connects. Ends: nothing is left behind (the minimal guarantee).
- 2a When PORT is 7496 or 4001 and --live was not given: [REFUSED] Port 7496 is a live port. Ends: nothing is left behind (the minimal guarantee).
- 3a When TWS cannot be reached: [CONNECTION ERROR] names the port and the error. Ends: nothing is left behind (the minimal guarantee).
- 3b When the account is not a paper account and --live was not given: [REFUSED] names the account; the bot disconnects. Ends: nothing is left behind (the minimal guarantee).
- 5a When IB reports no USD TotalCashBalance: [ERROR] says so, and the bot stops instead of using $100. Ends: nothing is left behind (the minimal guarantee).
- 5b When the log's last row says UNREPORTED: [ERROR] says the budget is not known, and the bot stops. Ends: nothing is left behind (the minimal guarantee).
UC-2 · use case · EPIC-1 step 2
Read the opening range
- Actor
- Trader
- Trigger
- the bot has connected and read the balance
- Before
- the account is connected
- Succeeds when
- [ORB ESTABLISHED] shows today's first bar's high and low, and [ORB TRIGGERS] the two prices that signal
- At worst
- no trigger is printed unless it came from today's first bar
- Why
- the whole strategy is measured from this one bar
How the trader acts: starts the bot any time before the close; nothing else to do
How they see the result: [WAIT], then [ORB ESTABLISHED] and [ORB TRIGGERS]
Steps
- The bot reads today's session hours from IB's liquid hours for SPY.
- It waits, printing [WAIT], until the session's first 15-minute bar has closed.
- It asks IB for the last two days of 15-minute bars, with UTC times.
- It takes the bar that starts at the session's open, and prints the range and the two triggers.
Alternate paths
- 1a When IB lists today as CLOSED: [CLOSED] says so, and the bot does nothing. Ends: nothing is left behind (the minimal guarantee).
- 1b When the hours are in a form the bot cannot read: It stops with an error that quotes them. Ends: nothing is left behind (the minimal guarantee).
- 2a When the bot starts after the first bar closed: It does not wait, and still reads the first bar. Back to step 3.
- 4a When IB has no bar at the session's open: [ERROR] says so, and the bot stops. Ends: nothing is left behind (the minimal guarantee).
UC-3 · use case · EPIC-1 step 3
Watch SPY for a breakout
- Actor
- Trader
- Trigger
- the triggers are printed
- Before
- the opening range is known
- Succeeds when
- [SIGNAL] CALL or PUT with SPY's price
- At worst
- nothing is traded on a price that is not live
- Why
- a breakout past the range is the strategy's entry
How the trader acts: nothing: the bot watches by itself
How they see the result: a status line every second, then [SIGNAL]
Steps
- The bot asks for live data and waits for SPY's first live price.
- Each second it reads SPY's last price and prints a status line.
- It compares the price with the two triggers.
- SPY trades strictly above the CALL trigger or below the PUT trigger, and it prints [SIGNAL].
Alternate paths
- 1a When no live price arrives within PRICE_TIMEOUT_S, or the data is delayed: [ERROR] names the data type, and the bot stops. Ends: nothing is left behind (the minimal guarantee).
- 2a When the flatten time arrives: [DONE] no new trades today. Ends: its goal is met.
- 2b When no tick comes for PRICE_TIMEOUT_S, or the data stops being live: [ERROR] says which, and the bot stops. Ends: nothing is left behind (the minimal guarantee).
- 3a When a trade was taken since SPY was last between the triggers: No signal until SPY trades back between them; then [REARMED]. Back to step 2.
UC-4 · use case · EPIC-1 step 4
Enter a trade on the signal
- Actor
- Trader
- Trigger
- [SIGNAL]
- Before
- a signal and the balance
- Succeeds when
- [FILLED] with the contracts held and their price
- At worst
- no order is sent for a contract IB does not know, at no live price, or beyond the balance
- Why
- the entry is where the money goes in
How the trader acts: nothing: the bot enters by itself
How they see the result: [CONTRACT], [ORDER] and [FILLED], or the [NO TRADE] or [NO FILL] reason
Steps
- The bot finds today's expiry in IB's option chain.
- It picks the listed out-of-the-money strike nearest spot plus or minus 1.50 rounded to the dollar, a tie going to the nearer, and checks IB knows it; [CONTRACT].
- It reads the option's live bid and ask.
- It sizes the order with the tier table from its budget, never from more than the account's cash; [ORDER].
- It buys with a limit at the ask and waits for the fill; [FILLED].
Alternate paths
- 1a When today's expiry is not listed: [NO TRADE] says so; no later expiry is used, and the day ends. Ends: nothing is left behind (the minimal guarantee).
- 2a When no out-of-the-money strike within $5 of the target is listed: [NO TRADE] says so, and the day ends. Ends: nothing is left behind (the minimal guarantee).
- 3a When the option has no live bid and ask: [NO TRADE] says so; this signal is skipped. Ends: nothing is left behind (the minimal guarantee).
- 4a When one contract costs more than the budget, or than the cash: [NO TRADE] gives the price and what there is to size from, and the day ends. Ends: nothing is left behind (the minimal guarantee).
- 4b When the exit rules are not set: [SIGNALS ONLY] No order sent. Ends: nothing is left behind (the minimal guarantee).
- 5a When nothing fills within ENTRY_FILL_TIMEOUT_S: The order is cancelled; [NO FILL]. Ends: nothing is left behind (the minimal guarantee).
- 5b When part of the order fills within ENTRY_FILL_TIMEOUT_S: The rest is cancelled, and only what filled goes on. Ends: its goal is met.
UC-5 · use case · EPIC-1 step 5
Exit the trade
- Actor
- Trader
- Trigger
- [FILLED]
- Before
- the bot holds the option
- Succeeds when
- the bot holds none of the option; the stop, the target or the flatten sold it
- At worst
- whatever happens, the stop and the target work at IB until the close
- Why
- the exit decides the trade, and a 0DTE option expires the same day
How the trader acts: nothing, or Ctrl+C to stop
How they see the result: [EXITS AT IB], a status line with the bid, then [TRADE CLOSED] with the reason
Steps
- The bot places the stop and the target at IB as one OCA pair, priced from the entry fill; [EXITS AT IB].
- Each second while it holds the option it checks the connection and the clock, and prints the bid.
- The stop or the target fills, and IB shrinks or cancels the other.
Alternate paths
- 2a When the flatten time arrives: Both exits are cancelled. What the bot holds is sold at market. Ends: its goal is met.
- 2b When the trader presses Ctrl+C: Both exits are cancelled. What the bot holds is sold at market. The trade is logged, then the bot stops. Ends: nothing is left behind (the minimal guarantee).
- 2c When the connection to TWS drops: [CONNECTION LOST]; [STILL OPEN] says what the bot holds, and the exits keep working at IB. Ends: nothing is left behind (the minimal guarantee).
- 1a When the stop rounds to under one cent: The bot sells at market at once. Ends: its goal is met.
UC-6 · use case · EPIC-1 step 6
Log the trade and decide whether to go on
- Actor
- Trader
- Trigger
- the bot holds none of the option
- Before
- the trade's fills
- Succeeds when
- one row with IB's net, and the bot is watching SPY again or stopped for the day
- At worst
- a closed trade always gets its row
- Why
- the log is the trader's record, and the breaker is the original's limit on a bad day
How the trader acts: nothing: the bot logs by itself
How they see the result: [TRADE CLOSED] with the net and the balance, the CSV row, then [REARMED] or [CIRCUIT BREAKER]
Steps
- The bot waits for IB's commission report on every fill.
- It writes one row: time, direction, contracts, entry, exit, the net after IB's commissions, the ending balance.
- It counts the losses in a row.
- It watches SPY again once SPY is back between the triggers.
Alternate paths
- 1a When a report never arrives: The row's NetPL and EndingBalance say UNREPORTED. The bot stops for the day. Ends: nothing is left behind (the minimal guarantee).
- 1b When the trader presses Ctrl+C while it waits: The row is still written, marked UNREPORTED, then the bot stops. Ends: nothing is left behind (the minimal guarantee).
- 3a When that makes MAX_CONSECUTIVE_LOSSES in a row: [CIRCUIT BREAKER], and no more trades today. Ends: its goal is met.
UC-7 · use case · EPIC-1 step 7
Stop and leave nothing behind
- Actor
- Trader
- Trigger
- the flatten time, the breaker, an error, or Ctrl+C
- Before
- the orders this run placed
- Succeeds when
- no order of the bot's working, none of its options held, and the bot disconnected
- At worst
- the bot says what it could not close
- Why
- an unattended 0DTE position can expire, and anything else in the account is the trader's
How the trader acts: Ctrl+C, or nothing
How they see the result: [CLEANUP] lines, or none; [STILL OPEN] if something could not be closed
Steps
- On Ctrl+C, or when the day is done, the bot cancels each order it placed that is still working.
- It sells at market what its own fills say it still holds.
- It disconnects from TWS.
- It says what is still open, if anything is.
Alternate paths
- 1a When the connection is already lost: Nothing can be cancelled; it goes straight to saying what is open. Back to step 4.
- 2a When an order will not cancel or a sale will not fill: It stops with that error, still disconnects, and says what is open. Ends: nothing is left behind (the minimal guarantee).
EPIC-2 · epic
Get the bot ready to trade real money
- Actor
- Trader
- Trigger
- the trader has the bot and wants it trading
- Before
- the bot as shipped: signals only
- Succeeds when
- the bot trades the trader's own exit rules on the live account, after a clean check and a paper run
- At worst
- no real order is sent before the trader adds --live
- Why
- the original arrived without its exits, and the bot cannot be run against a broker here
How the trader acts: edits STOP_LOSS_PCT and TAKE_PROFIT_PCT, runs on paper, adds --live
How they see the result: the test results, the light loop's report, the paper day's console and CSV
Steps, each a use case below
- The developer checks the bot without a broker. UC-8: Check the bot without a broker
- The trader sets the exit rules. UC-9: Set the exit rules
- The trader runs a day on the paper account and reads the log. UC-10: Run a day on the paper account
- The trader goes live. UC-11: Go live
Alternate paths
- 2a When the trader has not chosen the exit rules: The paper day runs signals only. Back to step 3.
UC-8 · use case · EPIC-2 step 1
Check the bot without a broker
- Actor
- Developer
- Trigger
- the developer has changed the bot
- Before
- Python 3.10 or newer and pytest; ib_async's source for the API check
- Succeeds when
- every test passes, every planted defect is caught, and the light loop proves no fault
- At worst
- nothing reaches TWS or an account
- Why
- a trading bot's mistakes cost money, and the bot cannot be run against IB here
How the developer acts: runs py -m pytest tests, py tests/plant_check.py and the light loop
How they see the result: the pytest summary, the plant table, spec_check/REPORT.md
Steps
- The developer runs the tests: whole simulated trading days against an in-memory TWS; all pass.
- The API check reads ib_async's own source and finds every call, keyword and field the bot uses.
- The plant run breaks one guarded behaviour at a time in a copy, and a test fails each time.
- The light loop runs every repro against SPEC.md, and proves no fault.
Alternate paths
- 2a When ib_async's source is not on the machine: The API check is skipped, and says why. Back to step 3.
- 3a When a plant is not caught: A test is written that catches it, and the run goes again. Back to step 3.
- 4a When a repro proves a fault: The fault is fixed, a test is added for it, and the loop runs again. Back to step 4.
UC-9 · use case · EPIC-2 step 2
Set the exit rules
- Actor
- Trader
- Trigger
- the trader has decided a stop and a target
- Before
- the bot runs signals only
- Succeeds when
- the banner no longer says SIGNALS ONLY, and signals become orders
- At worst
- an impossible value stops the bot before it connects
- Why
- the original's exit rules were never received, and only the trader can choose them
How the trader acts: sets STOP_LOSS_PCT and TAKE_PROFIT_PCT near the top of the file
How they see the result: the banner without [SIGNALS ONLY], or [REFUSED]
Steps
- The trader sets STOP_LOSS_PCT and TAKE_PROFIT_PCT; TIME_STOP_PCT still does nothing.
- The bot checks both values when it starts.
- The banner drops SIGNALS ONLY, and a signal now sends an order.
Alternate paths
- 2a When a value is impossible: [REFUSED] names both limits. Ends: nothing is left behind (the minimal guarantee).
UC-10 · use case · EPIC-2 step 3
Run a day on the paper account
- Actor
- Trader
- Trigger
- the trader wants to see the bot trade before any money is at stake
- Before
- TWS logged in to the paper account
- Succeeds when
- a day's console and trade_execution_log.csv, from IB's own fills and commissions
- At worst
- nothing touches a live account
- Why
- the tests cannot show how IB itself fills, prices and reports; a paper day is that check
How the trader acts: logs TWS in to paper on port 7497 and runs python zdt_autopilot.py
How they see the result: the console and the CSV
Steps
- The trader logs TWS in to the paper account with the API on port 7497.OB-1done by a person or by IB
- The trader runs the bot without --live; the banner says PAPER.
- The bot trades the day as in EPIC-1.
- The trader reads the console and trade_execution_log.csv.
Alternate paths
- 2a When the account is not a paper account: [REFUSED] names the account. Ends: nothing is left behind (the minimal guarantee).
- 3a When the paper account holds far more than the budget: The bot still sizes from its own budget, never from the paper account's whole cash. Back to step 4.
UC-11 · use case · EPIC-2 step 4
Go live
- Actor
- Trader
- Trigger
- a clean paper day
- Before
- the exit rules set, TWS logged in to the live account
- Succeeds when
- the banner says LIVE with the account ID, and the bot trades the day
- At worst
- without --live, nothing is sent
- Why
- real money is the point, and only the trader can choose it
How the trader acts: logs TWS in to the live account and runs python zdt_autopilot.py --live
How they see the result: the banner's LIVE and account ID
Steps
- The trader logs TWS in to the live account, API on port 7496.OB-1done by a person or by IB
- The trader runs python zdt_autopilot.py --live.
- The banner says LIVE with the account ID, and the bot trades the day.
Alternate paths
- 2a When --live is left off: [REFUSED] Port 7496 is a live port. Ends: nothing is left behind (the minimal guarantee).
Requirements
Each one is carried by the steps listed under it; none names code. The steps name the code.
From the sources
OB-1 Port 7496 is a live port; 7497 and 4002 are paper ports.
the original script as it arrived, 2026-11-08, its PORT setting:
7497 = TWS Paper, 7496 = TWS Live, 4002 = IB Gateway Paper
Checked by: test_live_port_is_refused_without_live_flag; light loop repros S4 and S5
OB-2 The opening range is the high and the low of the first 15-minute bar of today's regular session.
the original script, its opening range and trigger lines:
1. Establish 15-Minute Opening Range ... [ORB TRIGGERS] CALL Breakout > ${orb_high + ORB_BUFFER:.2f} | PUT Breakdown < ${orb_low - ORB_BUFFER:.2f}
Checked by: test_early_start_waits_for_the_opening_bar_to_close, test_late_start_still_reads_the_0930_bar; repro S7
OB-3 A CALL signal is SPY's last price strictly above the range's high plus ORB_BUFFER; a PUT signal is strictly below its low minus ORB_BUFFER.
the original script, its opening range and trigger lines:
1. Establish 15-Minute Opening Range ... [ORB TRIGGERS] CALL Breakout > ${orb_high + ORB_BUFFER:.2f} | PUT Breakdown < ${orb_low - ORB_BUFFER:.2f}
the owner's answer, relayed 2026-11-08:
start it with $100 and trade 0DTE within that budget; read the market's trend and buy cheap lotto calls when it is going up, cheap lotto puts when it is going down
Checked by: test_call_breakout_reaches_target, test_put_breakdown_stops_out; repro S8 (a price exactly at a trigger is no signal)
OB-4 The option bought expires today and is slightly out of the money, at the listed strike nearest spot plus or minus 1.50 rounded to the dollar.
the original script, get_0dte_contract:
Finds today's expiring SPY 0DTE option matching ~0.20 Delta / slightly OTM. ... target_strike = round(current_spot + 1.5, 0) ... # Find closest available strike
Checked by: test_unlisted_nearest_strike_takes_the_next_nearest_listed, test_never_buys_an_in_the_money_option, test_no_strike_within_5_dollars_means_no_trade
OB-5 The number of contracts follows the original's tier table, trimmed to what the balance covers at price x 100 + 2 x IBKR_FEE_PER_LEG a contract.
the original script, get_safe_tier_contracts:
contracts by balance: under 110 one, 250 two, 500 three, 1000 four, 2500 six, 5000 eight, else MAX_ACTIVE_CONTRACTS; cost a contract = price x 100 + 2 x IBKR_FEE_PER_LEG
Checked by: test_original_tier_table (10 cases)
OB-6 The balance is the account's USD TotalCashBalance as IB reports it.
the original script, its balance read:
if item.tag == 'TotalCashBalance' and item.currency == 'USD':
Checked by: test_call_breakout_reaches_target: [ACCOUNT] shows the fake account's $1,000.00
Carried byUC-1.5OB-7 After MAX_CONSECUTIVE_LOSSES losing trades in a row the bot takes no more trades that day.
the original script, its circuit breaker:
[CIRCUIT BREAKER] Max daily consecutive losses ({MAX_CONSECUTIVE_LOSSES}) reached. Stopping live execution for today.
Checked by: test_two_losses_in_a_row_stop_the_day; repro S14
OB-8 Each trade is one row of trade_execution_log.csv in the original's seven columns.
the original script, initialize_csv_log:
Timestamp, PlayDirection, Contracts, EntryPrice, ExitPrice, NetPL, EndingBalance
Checked by: test_call_breakout_reaches_target (the header and the row), test_ctrl_c_during_the_commission_wait_still_logs_the_trade
OB-9 Ctrl+C stops the bot.
the original script, its monitoring line:
Scanning real-time SPY price tick stream. Press Ctrl+C to stop.
Checked by: test_ctrl_c_mid_trade_sells_logs_and_stops
OB-10 No value stands in for one IB did not give: no $100 for a balance, no later expiry for today's, no fee estimate for a commission, no guessed bar.
the owner's standing rules for this work:
every value is read or proven absent, never stood in for; every feature has a test; a check is proven by a defect planted for it to catch
Checked by: test_no_usd_cash_balance_stops_instead_of_using_100, test_no_0dte_expiry_means_no_trade_today, test_unreported_commission_is_logged_as_unreported_and_stops, test_unreadable_session_hours_fail_loudly
OB-11 Every wait uses IB.sleep, never time.sleep.
ib_async 2.1.0, ib.py, the IB class docstring:
For introducing a delay, never use time.sleep() but use :meth:`.sleep` instead.
Checked by: light loop repro S11
OB-12 A contract counts as known only when IB qualified it.
ib_async 2.1.0, ib.py, qualifyContractsAsync:
If a contract cannot be qualified (bad values, ambiguous), the return value for the contract position in the result is None.
Checked by: light loop repro S12; test_unlisted_nearest_strike_takes_the_next_nearest_listed
Carried byUC-4.2OB-13 Bar times are asked for in UTC and compared with the session's open as instants.
ib_async 2.1.0, ib.py, reqHistoricalData:
formatDate: For an intraday request setting to 2 will cause the returned date fields to be timezone-aware datetime.datetime with UTC timezone
Checked by: light loop repro S13; test_early_start_waits_for_the_opening_bar_to_close checks formatDate=2
Carried byUC-2.3OB-15 The bot trades within its own budget, STARTING_BUDGET_USD ($100) to start, and never sizes from more than that budget or than the account's USD cash.
the owner's answer, relayed 2026-11-08:
start it with $100 and trade 0DTE within that budget; read the market's trend and buy cheap lotto calls when it is going up, cheap lotto puts when it is going down
Checked by: test_the_budget_starts_at_100_and_sizes_one_contract, test_the_cash_caps_the_budget
OB-14 When TWS cannot be reached the bot says so and exits.
the original script, its connection error:
[CONNECTION ERROR] Could not connect to TWS on Port {PORT}: {e}
Checked by: test_unreachable_tws_says_so_and_exits
Carried byUC-1.3aDV-1 Every step of the trading use cases has a test that runs it against a simulated TWS, with no TWS, network or account.
the owner's standing rules for this work:
every value is read or proven absent, never stood in for; every feature has a test; a check is proven by a defect planted for it to catch
Checked by: step_tests.yaml names tests for every step; step_trace.json shows each step's code ran under them
DV-3 The light loop proves no fault against SPEC.md.
the owner's request, 2026-11-08:
finish the trading script, run the light loop on it, test it, and publish it with its epics
Checked by: spec_check/REPORT.md: 0 PROVEN
DV-4 A defect planted in any guarded behaviour fails a test.
the owner's standing rules for this work:
every value is read or proven absent, never stood in for; every feature has a test; a check is proven by a defect planted for it to catch
Checked by: tests/plant_check.py: every plant caught
Open questions for the owner
Nobody wrote these down: finishing the bot needed them. Each is the bot's current answer, waiting for the owner's yes or a different one.
IR-1 Without --live the bot refuses a live port, and an account whose ID does not start with D (IBKR's paper accounts do).
Why it was added: the original connected to whatever port it was given; a bot that can trade real money must not do it by accident
Checked by: test_live_port_is_refused_without_live_flag, test_live_account_is_refused_without_live_flag, test_live_account_trades_with_live_flag
IR-2 Until STOP_LOSS_PCT and TAKE_PROFIT_PCT are set the bot sends no order, and prints each order it would send.
Why it was added: the original stops before its exit rules, and no exit may be guessed for someone else's money
Checked by: test_signals_only_until_the_exit_rules_are_set
IR-3 Right after the entry fills, the stop and the target go to IB as one OCA pair of DAY orders (type 2: a fill shrinks the other).
Why it was added: orders held at IB keep working if the PC or the script dies
Checked by: test_exits_are_an_oca_pair_held_at_ib
IR-4 Ten minutes before IB's listed close the bot sells at market whatever it holds, and takes no new trade.
Why it was added: a 0DTE option expires at the close; the ten minutes are a margin nobody has set
Checked by: test_flatten_ten_minutes_before_the_close, test_half_day_flattens_before_the_early_close
IR-5 The session's hours come from IB's liquid hours for SPY; a day IB lists as CLOSED is not traded.
Why it was added: holidays and early closes, which a fixed 9:30 to 16:00 gets wrong
Checked by: test_closed_day_does_nothing, test_half_day_flattens_before_the_early_close, test_unreadable_session_hours_fail_loudly
IR-6 After a signal the bot takes the next only once SPY has traded back between the two triggers.
Why it was added: otherwise it buys again the second its exit fills while SPY is still past the trigger
Checked by: test_no_new_trade_until_spy_comes_back_inside; repro S16
IR-7 An entry not filled within ENTRY_FILL_TIMEOUT_S seconds is cancelled, and only what filled is traded.
Why it was added: a working entry the bot lost track of could fill later with no exits
Checked by: test_unfilled_entry_is_cancelled, test_partial_fill_trades_only_what_filled
IR-8 No live SPY price within PRICE_TIMEOUT_S seconds, data that is not live, or no tick for that long, stops the bot.
Why it was added: it would otherwise trade on stale or delayed prices
Checked by: test_no_live_price_stops, test_delayed_data_stops; repro S15
IR-9 A commission IB never reports is logged as UNREPORTED, and the bot stops for the day.
Why it was added: the balance is then unknown, and the fee estimate is not IB's figure
Checked by: test_unreported_commission_is_logged_as_unreported_and_stops; repro S10
IR-10 When it stops, the bot cancels the orders it placed and sells what its own fills say it holds; it touches nothing it did not place.
Why it was added: an unattended 0DTE position can expire, and other positions are the trader's
Checked by: every whole-day test ends flat (assert_flat); test_ctrl_c_mid_trade_sells_logs_and_stops
IR-11 When one contract costs more than the budget, or than the cash, there is no trade that day.
Why it was added: the original's own loop trims the count to the balance, then max(1, cts) bought one it could not cover; the trim is read as the intent
Checked by: test_one_contract_it_cannot_afford_is_zero_not_one, test_cannot_afford_one_contract_means_no_trade; repro S9
IR-12 When the connection drops, or the cleanup fails, the bot says what it still holds.
Why it was added: the exits keep working at IB, and the trader has to know what is open
Checked by: test_connection_lost_while_holding_says_what_is_open
IR-13 A tie between two listed strikes goes to the one nearer spot plus or minus 1.50 before rounding.
Why it was added: the light loop proved the list order picked the farther one (S1)
Checked by: test_a_tie_goes_to_the_strike_nearer_spot_plus_1_50; repro S1
Carried byUC-4.2IR-14 An option with no live bid and ask is not traded on that signal.
Why it was added: there is no price to size or buy at
Checked by: test_an_option_with_no_quote_is_not_traded
IR-15 STOP_LOSS_PCT must lie between 0 and 1 and TAKE_PROFIT_PCT above 0, or the bot refuses to start.
Why it was added: an impossible stop or target would never fill or fill at once
Checked by: test_impossible_exit_rules_are_refused (4 cases)
IR-16 The budget carries from one day to the next: the bot starts from the last EndingBalance in its log, and stops when that row says UNREPORTED.
Why it was added: the owner starts it at $100, and the tier table's steps above $110 only make sense if the budget grows with the bot's own trades
Checked by: test_the_budget_carries_over_from_the_log, test_an_unreported_last_row_stops_the_bot
IR-17 TIME_STOP_PCT has no effect until its rule is known.
Why it was added: the original sets it and uses it after the point where the file ends
Checked by: zdt_autopilot.py reads TIME_STOP_PCT nowhere (a search of the file)
Carried byUC-9.1IR-18 The strike is a fixed 1.50 from spot, not picked by delta.
Why it was added: the original's comment aims at about 0.20 delta with a fixed offset; picking by IB's delta is the owner's call
Checked by: get_0dte_contract reads no greeks (read in the code)
Carried byUC-4.2DV-2 Every ib_async call, keyword and field the bot uses exists in ib_async 2.1.0's own source.
Why it was added: the bot cannot be run against a broker here; the library's source is the nearest check
Checked by: tests/test_api_contract.py, skipped (and saying so) without the source