Skip to content

Commit 49f9f85

Browse files
committed
chore: add 'aiosqlite' to 'bot' dependencies; chore: add first version of schema for 'alpha' bot database (using SQLite)
1 parent d7fcf24 commit 49f9f85

6 files changed

Lines changed: 95 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,6 @@ cython_debug/
175175

176176
# VSCode
177177
.vscode/
178+
179+
# Database
180+
**/*.db

ctenex/bot/bots/alpha/sql/init.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Price moments table
2+
3+
CREATE TABLE IF NOT EXISTS price_moments (
4+
id SERIAL PRIMARY KEY,
5+
timestamp TIMESTAMP NOT NULL,
6+
price DECIMAL(10,2) NOT NULL,
7+
volume DECIMAL(10,2) NOT NULL,
8+
best_bid DECIMAL(10,2) NOT NULL,
9+
best_ask DECIMAL(10,2) NOT NULL
10+
);
11+
12+
-- EMA (Exponential Moving Average) calculations table
13+
14+
CREATE TABLE IF NOT EXISTS ema_calculations (
15+
id SERIAL PRIMARY KEY,
16+
timestamp TIMESTAMP NOT NULL,
17+
price DECIMAL(10,2) NOT NULL,
18+
ema_short DECIMAL(10,2) NOT NULL, -- e.g., 12-period EMA
19+
ema_long DECIMAL(10,2) NOT NULL, -- e.g., 26-period EMA
20+
momentum DECIMAL(10,2) NOT NULL -- ema_short - ema_long
21+
);
22+
23+
-- Spread analysis table
24+
25+
CREATE TABLE IF NOT EXISTS spread_analysis (
26+
id SERIAL PRIMARY KEY,
27+
timestamp TIMESTAMP NOT NULL,
28+
best_bid DECIMAL(10,2) NOT NULL,
29+
best_ask DECIMAL(10,2) NOT NULL,
30+
spread DECIMAL(10,2) NOT NULL,
31+
spread_percentage DECIMAL(5,2) NOT NULL,
32+
volume_at_bid DECIMAL(10,2) NOT NULL,
33+
volume_at_ask DECIMAL(10,2) NOT NULL
34+
);
35+
36+
-- Trading signals table
37+
38+
CREATE TABLE IF NOT EXISTS trading_signals (
39+
id SERIAL PRIMARY KEY,
40+
timestamp TIMESTAMP NOT NULL,
41+
price DECIMAL(10,2) NOT NULL,
42+
momentum DECIMAL(10,2) NOT NULL,
43+
spread DECIMAL(10,2) NOT NULL,
44+
spread_percentage DECIMAL(5,2) NOT NULL,
45+
signal_strength DECIMAL(5,2) NOT NULL,
46+
recommended_action VARCHAR(10) NOT NULL
47+
);

ctenex/bot/db/__init__.py

Whitespace-only changes.

ctenex/bot/db/init.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pathlib
2+
3+
from aiosqlite import connect
4+
5+
6+
async def init_db(bot_name: str):
7+
"""
8+
Initialize the bot database schema.
9+
10+
This function will create the database file if it doesn't exist.
11+
It places the database file in the same directory as the script and
12+
names it after the bot name.
13+
14+
It also assumes that the database schema is stored in the `sql` directory
15+
in a file named `init.sql`.
16+
"""
17+
db_schema_path = pathlib.Path(__file__).parent / "sql" / "init.sql"
18+
db_path = pathlib.Path(__file__).parent / f"{bot_name}.db"
19+
20+
init_script = db_schema_path.read_text()
21+
22+
async with connect(db_path) as db:
23+
await db.executescript(init_script)
24+
await db.commit()

poetry.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ typer = "^0.15.3"
4242
[tool.poetry.group.bot.dependencies]
4343
httpx = "^0.28.1"
4444
pydantic = "^2.11.4"
45-
45+
aiosqlite = "^0.21.0"

0 commit comments

Comments
 (0)