ADR 0028: Say when a close that took a minute ended¶
- Status: Accepted
- Date: 2026-11-12
Context¶
A close the broker has not filled a minute after the first request prints one red line, once (ADR 0022):
Still closing: the broker lists 1 open XAUUSD position 60 seconds after the first close request; later signals wait until it closes, check it in TradeLocker
ADR 0022 listed what came next under "What this does not cover": nothing
said when such a close ended. The next lines were the order or
Normal: Unlocked, with no time.
Step 6o made that gap worse. The Still closing: line now reaches the
operator's phone
(ADR 0027), while Normal:
Unlocked and Order placed do not. The chat was told that later signals
wait, and was never told that they no longer do. An operator who acted on
the first message, closing the position by hand for example, had to open
the log to see whether that worked.
Decision¶
-
One line when the broker lists no position, in a close that logged
Still closing::Closed: the broker lists no open XAUUSD position 138 seconds after the first close request
- Only after the warning. A close that fills within the minute, which is nearly every one, prints nothing new. Every signal that replaces a position closes one, and a line for each would bury the one that matters, in the log and in the chat.
- Worded as the
Still closing:line it answers. The same start for the seconds, the first close request, and the line names it: a bare "Closed after 138 seconds" could be read as counted from the alert or from theStill closing:message, and the chat may show it late, with a lateness note of its own. One word before the colon, since the notifier names a message it could not send by those words, cut at 40 characters; "Closed after 138 seconds from the first close request" would be named mid-word. - The seconds run to the count that lists none. The clock is read at
that count, and only for a close that warned, not taken from the poll
before it. They are whole, cut like those of
Still closing:. - Green, and handed to Telegram too. It asks nothing of the operator,
so it is not red. It still goes to the chat: the chat holds the
Still closing:message it answers. It goes through the samenotifyas the red lines, so the log's wording and the chat's cannot drift. - No word on what comes next. For a
closesignal the lock is free right after. For anopensignal, the order still follows, inside the lock, and it can end inOrder rejected:orBroker failed:. A line that said "later signals no longer wait" would be false there. The line says only what the bot knows at that moment. - No line when a call fails after the warning. The broker never
listed none.
Broker failed:already says the signal stopped there and names the symbol to check (ADR 0027). - One port method,
OperatorConsole.closed(symbol, seconds). The use case decides when; the console decides the words, as forstill_closing. - Its green line leaves in one
print, reset included, likeprint_red: both now go through one helper. The notifier's thread prints too, and a line printed between a colour and its reset would take the colour (ADR 0026).order_placedkeeps its two legacy prints. - A green line that Telegram did not take is still reported in red. The line asks nothing of the operator, but a chat that cannot be reached does: the next message may be one that does.
flowchart TD
REQ["close requests sent;<br/>first_request = now()"] --> COUNT["open_position_count"]
COUNT -- "Err" --> FAIL["return the BrokerFailure;<br/>the handler prints Broker failed:"]
COUNT -- "Ok(0)" --> WARNED{"Still closing:<br/>printed?"}
WARNED -- "no: filled within the minute" --> DONE["Ok: the order,<br/>or Normal: Unlocked"]
WARNED -- "yes" --> CLOSED["closed(symbol, now() - first_request)<br/>green line, also to Telegram"]
CLOSED --> DONE
COUNT -- "Ok(n > 0)" --> MINUTE{"a minute since<br/>the first request,<br/>not yet warned?"}
MINUTE -- "yes" --> STILL["still_closing(symbol, n, seconds)<br/>red line, also to Telegram"]
MINUTE -- "no" --> PACE
STILL --> PACE{"10 s since<br/>the last requests?"}
PACE -- "yes" --> AGAIN["request_close, n times"] --> COUNT
PACE -- "no" --> SLEEP["sleep(1)"] --> COUNT
What changes¶
| Before | After | |
|---|---|---|
| A close that fills within the minute | Closing: lines, then the order or Normal: Unlocked |
the same |
A close that logged Still closing:, then fills |
more Closing: lines, then the order or Normal: Unlocked |
the same, with one green Closed: ... line before them |
| The same, with Telegram on | the chat gets Still closing: only |
the chat gets Still closing:, then Closed: ... |
A broker failure after Still closing: |
Broker failed:, then the traceback |
the same, with no Closed: line |
| The startup line with Telegram on | Telegram: on; the account line and every red line also go to the chat |
Telegram: on; the account line, every red line and each Closed line also go to the chat |
Tests¶
tests/unit/application/test_closed_line.pyruns the use case on in-memory ports that share one journal:- a close and an open that logged
Still closing:journal oneclosedentry, right after the count that lists none, with the seconds read at that count, and thenunlocked, or the order andunlocked; - closes that fill at once, in half a minute, or at the first count a minute in, journal none;
- a count or a close request that fails after the warning journals none.
- a close and an open that logged
tests/unit/adapters/test_printing_console.pypins the line's exact bytes, in green, and the text handed tonotify, without colours.tests/unit/adapters/test_ascii_alerts.pypins thatprint_redandprint_greeneach print a line and its reset in one call. The bytes alone cannot show that: two calls print the same ones.tests/characterization/test_call_sequences.pygains the line in the row of aclosethat takes eight requests, and a new row for anopenthat does, with the order after the line.tests/characterization/test_startup_telegram.pypins the new startup line.tests/unit/adapters/test_notifier.pypins that a report of the console'sClosed:text not sent names it"Closed".
Each of these mutations of the code fails at least one test:
- no
closedline at all; - a line for every close;
- a line once a minute has passed, warned or not;
- the seconds from the last request rather than the first;
- the seconds from the poll before the count;
- the line without the start of its seconds;
- the earlier wording, whose words before the colon the notifier named mid-word;
- a line when a count fails after the warning;
- a line when a close request fails after the warning;
- the seconds not cut to whole ones;
- the line in red;
- the line not handed to
notify; - the shared helper printing the reset in a second call;
print_greenprinting red;- the old startup line.
What this does not cover¶
- A restart between the two lines. The close and its wait end with
the process, so the chat holds a
Still closing:message with noClosed:one. The startup'sLogged in:message is the only sign of the restart. - When the position closed, to the second. The line comes at the first count that lists none. Counts are about two seconds apart, and one that gets a slow answer takes longer, so the seconds can be late by that much.
- What follows an
opensignal's close. A placed order prints no red line, so the chat seesClosed:and then nothing. A rejected order and a failed call still send their own lines.
Alternatives considered¶
- A line for every close. Rejected: nearly every signal that replaces a position closes one within seconds, and the chat would repeat that for each trade.
- "Later signals no longer wait" in the line. Rejected: false for an
opensignal, whose order still runs inside the lock after the line. - A red line. Rejected: red marks a line the operator has to act on, and this one ends the need to.
- A line after a failure too, such as "Stopped waiting". Rejected:
Broker failed:already says that the signal stopped, and names the symbol to check. - Sending it to Telegram from a separate path. Rejected for the reason ADR 0027 gives for the red lines: one place builds the words, so the log and the chat cannot drift.