Skip to content

Database

Constantin edited this page Jun 13, 2025 · 11 revisions

Structure

Metis uses a SQLite database stored in the file /database/data.db.

PK: Primary Key

AI: Auto-increment

UN: Unique

NN: Not Null

Table name Field name Type PK AI UN NN Description
market_data timestamp TEXT Timestamp of data in format: "YYYY-MM-DD HH:MM:SS+00:00". The data will always be GMT+00
symbol TEXT Symbol in yfinance format, for example "AAPL" for Apple or "^GSPC" for S&P500
open REAL A float value denoting the opening price
high REAL A float value denoting the highest price during the time period
low REAL A float value denoting the lowest price during the time period
close REAL A float value denoting the close price
volume INTEGER An integer value denoting trading volume during the time period
backtest_results start_timestamp TEXT Start of simulation in format:"YYYY-MM-DD HH:MM:SS+00:00". The data will always be GMT+00
end_timestamp TEXT End of simulation in format: "YYYY-MM-DD HH:MM:SS+00:00". The data will always be GMT+00
symbol TEXT Symbol in yfinance format, for example "AAPL" for Apple or "^GSPC" for S&P500
interval TEXT Interval in yfinance format, for example "1d" for daily or "1h" for hourly. Influences the format start and end timestamps.
decisions TEXT Stores the decisions the strategy made in a NOT YET DEFINED format
revenue REAL Float value of total revenue the strategy made. Can be negative if the strategy lost money.
start_capital REAL The capital that the strategy could invest in the beginning.
strategy TEXT The name of the strategy.
forwardtest_results id INTEGER Used to uniquely identify a certain simulation
start_price REAL The starting price of the simulation
path TEXT The simulated stock data in a NOT YET DEFINED format
decisions TEXT Stores the decisions the strategy made in a NOT YET DEFINED format
revenue REAL Float value of total revenue the strategy made. Can be negative if the strategy lost money.
start_capital REAL The capital that the strategy could invest in the beginning.
strategy TEXT The name of the strategy.

API

The database API is written in Python and can be found in the path /database/api.py.

Usage

To use the Database API in another Python script you can import the functions by using:

from database.api import <function>

for example:

from database.api import create_db # Allows you to use create_db() in this file

Create Database

The create_db() function has no arguments and creates the database data.db, following the schema shown in the Structure section. It safely establishes and closes the connection to the database. For example:

create_db()

Initialize Connection

The initialize_db() function has no arguments and initializes a connection and creates a cursor. It returns both in the same order as previously named. For example:

connection, cursor = initialize_db()

Close Connection

The close_db() function takes conn as a positional argument and safely closes the connection to the database. For example:

close_db(connection)

Clone this wiki locally