Quant Trading Bot Devlog

한국어로 보기

The Morning Round Misfired on a Late-Open Day - Gating It on the Real Open Time

On a day the market opens an hour late, restarting a stopped schedule timer instantly fired its already-elapsed trigger, so the morning round sent orders into a closed market. Every order was rejected, and because that round had claimed the execution slot, the later rounds were blocked too. This is how I tracked it down and made the system read the actual open time from the calendar so a pre-open round holds itself back.

This is the English version of a post originally written in Korean for my algorithmic trading system devlog(new tab).

Some days the market opens an hour late

The Korean market has one day a year — the national college entrance exam day — when the open is pushed back by an hour.

It normally opens at 9 a.m., but on that day it opens at 10. The first trading day of the new year can be a 10 a.m. open too.

My order-execution and safety layer(new tab) runs in three rounds — morning, midday, afternoon. But the morning round's schedule had a "9 a.m. open" assumption baked into it.

Today happened to be one of those hour-late opens.

Restarting a stopped timer instantly fired a trigger that had already passed

The incident came from two things overlapping.

One is a behavior of the schedule timer. I had briefly stopped and then restarted the timer that runs the morning round — and this kind of calendar-based timer, the moment you turn it back on, immediately fires once for a trigger time that has already gone by.

The other is the open-time assumption I mentioned. The system still thought the open was at 9.

With both overlapping, just after 9 a.m. the morning round sent orders at a market that wasn't even open yet.

Every order rejected, and the slot claimed

The result was a clean sweep of rejections.

The market wasn't open, so the broker sent every order back with a "market not open" reason. Not a single one filled.

Up to here it was actually safe — a wrongly-sent order can't fill against a closed market.

The real problem came next. The morning round starts by first claiming a marker that says "I've got this morning's execution" — an execution slot, there to prevent duplicate runs.

But this round got rejected wholesale while still holding the slot. So when the market actually opened at 10, the morning round that should have run normally nearly refused to start, saying "someone already has this."

Today I released that claimed slot by hand, then re-ran a fallback round at 10:05 and confirmed it executed normally. A human stepping in to fill the gap.

The fix — read the actual open time from the calendar

In the evening I went after the root cause.

The core was to delete the "9 a.m. open" assumption from the code. Instead, the system now reads that day's actual open time from the calendar.

A late-open day comes only once a year, so it's awkward to detect perfectly on its own. So I stacked three tiers: days I know in advance, like exam day, go into a manual table; otherwise the exchange calendar; and if both fail, a 9 a.m. default.

Once it knows the real open time, when the morning round tries to fire before the open it holds itself back — "not open yet" — and runs again at a fallback time right after the actual open.

A normal trading day (9 a.m. open) behaves exactly as before. This hold only kicks in on a late-open day.

I added the alert, but not an auto-release

One more thing: when every order in a round is rejected for "market not open," the system now journals that fact and raises an alert.

So a case like today — a whole round fired into a closed market — is something a human notices right away.

But I deliberately did not add a feature that auto-releases the claimed slot.

Auto-releasing the slot would be convenient, but it conflicts with the safety layer's basic principle: when execution goes sideways, don't touch anything more on your own — stop and call a human. Who releases the slot, and when, I left as a human's call.

The next late-open day — the first trading day of the new year — will be when this fix actually gets tested in the wild.

A side note — handing the quote feed's canonical path to a different collector

Today I also changed one thing on the data-collection side.

In the quote-feed stream of my data archive(new tab), I promoted a collector that had only been running as a backup to the canonical (reference) path.

I'd been pulling the same data down two paths to compare quality, and now that the promoted one has proven steadier, from tomorrow (Nov 20) it becomes the reference.

I disabled the old path but left a rollback route, so one line of config brings it back if anything breaks.

#quant #order execution #safety #incident