Most "AI trading bot" posts show a chart that goes up and to the right. This is not one of those.

Over the last few months I built a full machine-learning research and signal platform for the Colombo Stock Exchange (CSE) in Sri Lanka, as a solo personal project. It collects the data, cleans it, trains and tests models, and turns the result into clear daily guidance in a web dashboard. It does not trade by itself: every order is still placed by a person.

The biggest lesson? Building the model took maybe 20% of the time. Data, honest testing and guardrails took the rest. Here is how it is put together and what I learned.

Why a small market is hard (and interesting)

The CSE is not the NYSE. A few things make it tricky:

Thin liquidity. Many listed shares trade only a few times a day. A model that loves an illiquid stock is useless if you cannot actually buy it.
High costs. Broker fees are around 1.1% per side, so a round trip costs more than 2%. Any edge has to beat that before it is worth anything.
Messy history. Splits, bonus issues and rights issues show up as huge fake price jumps unless you deal with them.
No clean free dataset. I had to collect it.

That shaped every design decision.

  1. The data pipeline

The first job was getting 15+ years of daily prices for 700+ securities: more than 1 million rows.

A Python collector with Playwright pulls the history in date windows, retries failures, and resumes where it stopped.
During market hours it records live intraday snapshots every couple of minutes.
It also pulls announcements and daily market-wide flow data from public sources.
Everything lands in SQLite (fast, zero setup) and is mirrored to SQL Server.
Corporate actions: the silent model killer

A 2-for-1 split looks like a 50% crash overnight. Feed that to a model and it learns nonsense.

So the pipeline flags every suspicious overnight jump and classifies it: a clean split ratio whose new price level persists is adjusted, a move that reverts is kept as a real move, and anything unclear is masked out of training instead of guessed. Unknown is safer than wrong.

  1. The model, and how I tried not to fool myself

The model itself is plain: gradient-boosted trees (scikit-learn) on price, volume and market-context features. The interesting part is the testing.

Walk-forward testing. The model is trained on the past, tested on the next block of time it has never seen, then the window moves forward. Over 15 years that gives 60 out-of-sample blocks. Every prediction in the results was made before the model "knew" what happened.

Real costs in every test. Broker fees on both sides, plus slippage of at least half a price tick. I also found a bug here during QA: I had used one tick size for every share, but the exchange uses a larger tick above a certain price. Small detail, real money.

No look-ahead. A signal at today's close can only be acted on at the next day's open. Easy to get wrong, and it inflates results a lot when you do.

Saying "no edge" out loud. The dashboard has an honest verdict for every configuration, and most variations I tried did not survive. I spent a full day testing new features (sector groups, a "beat the market" target, a liquid-only universe, monthly rebalancing). Several of them improved the overall ranking metrics, but none improved the stocks the system would actually pick, so none went live. That was the most useful day of the project.

  1. Automation with a safety gate

The system runs unattended on a laptop:

starts with Windows and resumes collection on its own,
retrains weekly, but the new model only replaces the old one if its out-of-sample score is not worse, the export matches the trained model exactly, and nothing looks off. The old model is backed up first,
paper-trades every signal with the same rules, so there is a live track record before any real money,
backs up the database to the cloud daily,
sends phone and desktop alerts.

The safety gate matters. An automatic retrain that silently ships a worse model is worse than no retraining at all.

  1. The dashboard

The front end is React 19 + TypeScript + Tailwind, served by a tiny Python HTTP server with live updates.

It has 18 pages: a control center, data quality, a model lab, a backtest studio where you can change settings and re-run instantly, paper trading with a journal, risk and system health, news, and a live intraday view.

The page I use most is Today's plan: given how much I want to invest, it shows what to buy (or, most days, "no buy today, and here is why"), what I hold, my break-even price after fees, and when each holding can be sold without a loss.

There is also a small browser extension that fills the broker's order form with the system's numbers, because typing quantities by hand is where mistakes happen. It never presses Buy or Sell; that stays a human decision.

  1. Testing the whole thing

Before calling it done I ran a full QA pass:

unit tests for the money logic (sizing, fees, tick sizes, sell rules, holidays),
integration tests that throw garbage and hostile input at every API endpoint,
UI tests that open every page at desktop and phone width and check for errors,
acceptance tests for the real user flows.

That pass found real bugs: a sizing fallback that could suggest a much larger order than the budget, a crash on a bad journal date, and a local API that another website could have called. All fixed, all covered by tests now.

What I would tell someone starting a project like this
Spend your time on data. Your model can only be as honest as your history.
Put real costs in from day one. Many "edges" disappear the moment you add fees.
Test walk-forward, never on data the model has seen.
Make "no" an easy answer. Build the system so it can tell you an idea does not work.
Automate, but with a gate. Retraining without a quality check is a risk, not a feature.
Stack

Python · scikit-learn · pandas · Playwright · SQLite · SQL Server · React 19 · TypeScript · Tailwind CSS

The source stays private, but there is a project showcase here: github.com/jkchinthaka/cse-signal-bot

I build data pipelines, ML systems, dashboards and full-stack web apps as a freelancer. If you are working on something similar, I would be happy to talk.

This is a research and learning project. Nothing here is investment advice.
(https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/mun7hwn9hithtqmhw0rm.png)