Press enter or click to view image in full size
Working at a stock brokerage firm, I’m surrounded by massive, complex architecture that can be both fascinating and a bit overwhelming.
Could you strip it all down and build a lightweight prototype? A stock broker using, well, almost nothing? With that in mind, armed with a Raspberry Pi, I decided to dive in and see what could be done.
The Idea
The concept was straightforward: a basic stock brokerage platform. A sandbox for trading, if you will — no real money involved, just pure learning and experimentation. You should be able to build portfolios, analyse and trade stocks. It should all be based on fake money. And, a stretch goal, compete with friends. We’ll call it Playtrader.
Press enter or click to view image in full size
The Tools
To bring this idea to life, I needed a frontend, backend, some storage, and some way to run it.
I ended up using Pocketbase. It’s a lightweight open source backend, complete with a collection based database. And it comes with a JS sdk. It’s basically a self-hosted alternative to Firebase; perfect for a project of this scale.
Press enter or click to view image in full size
For storage, I went with SQLite, mainly because it pairs well with Pocketbase. With a few tweaks, like enabling the Write-Ahead Logging (WAL) mode, it turned out to be quite robust and super easy to manage. Keep it simple.
The core logic was written in Go, a language I’ve grown to appreciate for its simplicity and performance. Furthermore, since Pocketbase is written in Go, and extendable using Go, I could incorporate business logic in the same binary. Monolithic design, hurray.
For the frontend, I opted for Svelte, which is a breath of fresh air compared to the heavyweight champions, React and Angular. Svelte’s ability to create fast, reactive user interfaces with minimal code provided a smooth ride for my backend-ish profile.
I also incorporated Flowbite, which provided pre-designed components that looked great out of the box, saving me loads of time on UI development.
The Build
Getting everything to run on a Raspberry Pi was surprisingly smooth — no major hiccups. It’s arm, and my laptop is Intel, so I prepared myself for some debugging, but compiling using some flags worked like a charm.
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build .
Pocketbase and SQLite are a natural fit for low-resource environments, and Go’s performance on the Pi was more than enough for what I was trying to achieve. I linked up the frontend and backend, set up the database, and implemented basic trading features. Users can create portfolios, execute trades, and use the built-in tools to analyze stock trends. While it’s all done with fake money, the goal was to replicate the feel of real trading as closely as possible.
Press enter or click to view image in full size
To streamline content creation, I leaned on Chat-GPT and Midjourney, setting up bullet points to guide the information provided.
I created my own lib (github@nasdaq-go-retriever) to keep stock values updated. It’s a simple cron with a cache backed on-demand retriever. Again, keeping it simple.
Some indexes for the historic stock data, along side wal, was also needed in order to keep the database reactive. All stock histories are located in the same table, it’s a few million rows; so that’s why.
Deployment
Deployment was where things got interesting. After a few iterations, I ended up creating a systemd service. To avoid overloading the Raspberry Pi’s SD card — since excessive IO can lead to corruption — I connected a USB drive for logs, databases, backups, and other storage-heavy tasks. It’s still working, 6 months later, so I file that under “success”.
I registered a domain through Loopia — not the best, not the worst — and linked the A record to a static IP that my ISP, Bahnhof, set up for me. They were incredibly accommodating, which was a pleasant surprise. For SSL, I initially set up the certificate using Certbot but later found out that Pocketbase handles SSL as well. Still, I stuck with my setup because I wanted to keep the rate limiting provided by Nginx.
One of the most rewarding parts was building the analysis tools. I’ve always been intrigued by the math behind stock trading, so coding features like regression analysis and Bollinger Bands was a fantastic learning experience. Seeing them operate seamlessly on something as small as a Raspberry Pi was incredibly satisfying.
Press enter or click to view image in full size
The Result
The end product is a simple but functional stock brokerage platform. It’s not going to replace your favorite trading app, but it’s a fantastic tool for learning about the stock market and experimenting with trading strategies — without the risk. And the fact that it runs entirely on a Raspberry Pi? That’s just plain cool.
If you’re curious to see it in action, check out the platform at https://playtrader.se/. It’s in Swedish and focused on the Nordic markets, so if that’s up your alley, you might find it quite interesting.
Press enter or click to view image in full size
Closing Thoughts
This project started as a fun little challenge to see if I could build something from almost nothing, and I’m thrilled with how it turned out. It’s a testament to how much you can accomplish with the right tools, a bit of creativity, and a tiny, budget-friendly Raspberry Pi. Whether you’re an experienced developer or just someone who enjoys tinkering, I highly recommend giving a project like this a try. You never know what you might learn along the way.
Next stop is attaching a machine learning trading bot to the platform. Fun times.