The system consists of 2 pynq board nodes communicating through a flask server hosted on an AWS EC2 Instance.
Controller
- Copy over the files within the [/controller] file directory over to PYNQ board #1.
- Open [/controller/name_of_python_notebook] and setup internet connection (blocks 1 and 3)
- Run subseqequent blocks
Trading Engine
- Copy over the files within the [trading_engine] file directory over to PYNQ board #2.
- Open [/trading_engine/name_of_python_notebook] and setup internet connection (blocks 1 and 3)
- Run subsequent blocks
This folder holds the Flask REST API for the project. It stores state in a local SQLite file (data.db). PYNQ nodes call its public URL for /matrix, /weights, /instruction, /portfolio, and related routes.
Deploy on AWS EC2 with Ubuntu Server in the order below. All terminal commands on the instance use Ubuntu conventions (apt, python3, default user ubuntu on EC2).
The EC2 instance must use the Ubuntu Server AMI (see step 1). After you SSH in, you are at an Ubuntu shell — run the commands in steps 4–8 there.
- Open the AWS Console → EC2 → Launch instance.
- Name the instance (e.g.
trading-flask-api). - AMI: Ubuntu Server (22.04 LTS or newer) — do not pick Amazon Linux if you want these exact commands to apply unchanged.
- Instance type: e.g. t3.micro or t2.micro.
- Key pair: create or select a key pair and download the
.pemfile — you need it to SSH. - Network: allow SSH (22) from My IP. Turn on Auto-assign public IP so you get a public IPv4 address.
- Click Launch instance. When the instance is Running, copy its Public IPv4 address.
Optional: In EC2 → Elastic IPs, allocate an address and associate it with this instance so the IP does not change after stop/start.
The Flask app listens on 5000. Edit the instance’s security group → Inbound rules → Add rule:
- Type: Custom TCP
- Port:
5000 - Source: your IP, or
0.0.0.0/0if devices (e.g. PYNQ boards) need open access (tighten in production).
Keep the existing SSH (22) rule so you can still log in.
From your local computer (replace the key path and IP). Example if the EC2 user is ubuntu (default for the Ubuntu AMI):
ssh -i /path/to/your-key.pem ubuntu@<PUBLIC_IP>
After this, the remaining commands are run on the Ubuntu EC2 instance.
sudo apt update
sudo apt install -y python3 python3-venv
mkdir -p ~/trading-api
cd ~/trading-api
python3 -m venv .venv
source .venv/bin/activate
Your prompt should show (.venv) when the venv is active.
Either install packages directly:
pip install flask matplotlib
Or create a requirements.txt (you can copy requirements-flask.txt from this repo) and run:
pip install -r requirements.txt
Create a new Python file in ~/trading-api (e.g. app.py) and paste in the Flask code from this repository.
nano app.py
Paste the contents, save, and exit (Ctrl+O, Enter, Ctrl+X in nano).
Alternatively, on the Ubuntu instance install git (sudo apt install -y git), clone the repo, and copy the Flask code from the Controller Code folder into ~/trading-api/app.py, or edit the file from the clone.
With the venv still activated:
python3 app.py
The app binds to all interfaces on port 5000. Test in a browser: http://<PUBLIC_IP>:5000/dashboard.
Set API_BASE_URL, BASE_URL, or equivalent on the PYNQ boards to:
http://<PUBLIC_IP>:5000
| Method | Path | Purpose |
|---|---|---|
| GET/POST | /matrix |
Latest model weights + features |
| GET/POST | /weights |
Feature names / asset (controller) |
| POST | /store_instruction |
Voice-derived instruction |
| GET | /instruction |
Latest instruction (polling) |
| GET/POST | /portfolio |
Balance + accuracy |
| GET | /graph |
PNG chart of portfolio history |
| GET | /dashboard |
HTML monitor |
| POST | /flush |
Clear portfolio table |
See the Flask code in this folder for exact JSON bodies and validation.