Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Dockerfile
LICENSE
README.md
scripts
Dockerfile
LICENSE
README.md
scripts
scripts/
50 changes: 50 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# .gitattributes snippet to force users to use same line endings for project.
#
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

#
# The above will handle all files NOT found below
# https://help.github.com/articles/dealing-with-line-endings/
# https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes



# These files are text and should be normalized (Convert crlf => lf)
*.php text
*.css text
*.js text
*.json text
*.htm text
*.html text
*.xml text
*.txt text
*.ini text
*.inc text
*.pl text
*.rb text
*.py text
*.scm text
*.sql text
.htaccess text
*.sh text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary
*.pyc binary
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# MacOS
# MacOS
.DS_Store
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM timescale/timescaledb:latest-pg12
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD password
ENV POSTGRES_DB quantx
COPY init/create.sql /docker-entrypoint-initdb.d/
COPY init/load.sql /docker-entrypoint-initdb.d/
FROM timescale/timescaledb:latest-pg12
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD password
ENV POSTGRES_DB quantx
COPY init/create.sql /docker-entrypoint-initdb.d/
COPY init/load.sql /docker-entrypoint-initdb.d/
COPY . .
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SETUP
## SETUP
- Read through https://docs.timescale.com/
- Can be setup standalone (but intended for use with server)
- TO SETUP: bash ./scripts/start.sh
- TO TEARDOWN: bash ./scripts/teardown.sh
- TO TEST SETUP (setup and teardown): ./test_setup.py
# SETUP

## SETUP

- Read through https://docs.timescale.com/

- Can be setup standalone (but intended for use with server)
- TO SETUP: bash ./scripts/start.sh
- TO TEARDOWN: bash ./scripts/teardown.sh
- TO TEST SETUP (setup and teardown): ./test_setup.py
144 changes: 72 additions & 72 deletions init/create.sql
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
CREATE TABLE Users (
id INT GENERATED BY DEFAULT AS IDENTITY,
email TEXT UNIQUE NOT NULL,
hashed_password TEXT NOT NULL,
firstname VARCHAR(255),
lastname VARCHAR(255),
description TEXT,
PRIMARY KEY(id)
);
CREATE TABLE Strategy (
id INT GENERATED BY DEFAULT AS IDENTITY,
uid INT REFERENCES Users(id),
code TEXT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE Backtest (
id INT GENERATED BY DEFAULT AS IDENTITY,
result TEXT,
code_snapshot TEXT NOT NULL,
test_start TIMESTAMP NOT NULL,
test_end TIMESTAMP NOT NULL,
created TIMESTAMP NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE Competition (
id INT GENERATED BY DEFAULT AS IDENTITY,
title TEXT NOT NULL,
description TEXT NOT NULL,
owner INT REFERENCES Users(id),
created TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,
test_start TIMESTAMP NOT NULL,
test_end TIMESTAMP NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE CompetitionEnrollment (
comp_id INT REFERENCES Competition(id),
uid INT REFERENCES Users(id),
PRIMARY KEY(uid, comp_id)
);
CREATE TABLE CompetitionEntry (
comp_id INT REFERENCES Competition(id),
backtest_id INT REFERENCES Backtest(id),
PRIMARY KEY(comp_id, backtest_id)
);
CREATE TABLE Symbol (
symbol TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
description TEXT
);
CREATE TABLE Quote (
time TIMESTAMP NOT NULL,
symbol TEXT REFERENCES Symbol(symbol),
price_open DOUBLE PRECISION NULL,
price_high DOUBLE PRECISION NULL,
price_low DOUBLE PRECISION NULL,
price_close DOUBLE PRECISION NULL,
PRIMARY KEY (symbol, time)
);
CREATE EXTENSION IF NOT EXISTS timescaledb;
/* Create hypertable from Quotes table */
SELECT create_hypertable('Quote', 'time');
CREATE TABLE Users (
id INT GENERATED BY DEFAULT AS IDENTITY,
email TEXT UNIQUE NOT NULL,
hashed_password TEXT NOT NULL,
firstname VARCHAR(255),
lastname VARCHAR(255),
description TEXT,
PRIMARY KEY(id)
);

CREATE TABLE Strategy (
id INT GENERATED BY DEFAULT AS IDENTITY,
uid INT REFERENCES Users(id),
code TEXT NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE Backtest (
id INT GENERATED BY DEFAULT AS IDENTITY,
result TEXT,
code_snapshot TEXT NOT NULL,
test_start TIMESTAMP NOT NULL,
test_end TIMESTAMP NOT NULL,
created TIMESTAMP NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE Competition (
id INT GENERATED BY DEFAULT AS IDENTITY,
title TEXT NOT NULL,
description TEXT NOT NULL,
owner INT REFERENCES Users(id),
created TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,
test_start TIMESTAMP NOT NULL,
test_end TIMESTAMP NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE CompetitionEnrollment (
comp_id INT REFERENCES Competition(id),
uid INT REFERENCES Users(id),
PRIMARY KEY(uid, comp_id)
);

CREATE TABLE CompetitionEntry (
comp_id INT REFERENCES Competition(id),
backtest_id INT REFERENCES Backtest(id),
PRIMARY KEY(comp_id, backtest_id)
);

CREATE TABLE Symbol (
symbol TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
description TEXT
);

CREATE TABLE Quote (
time TIMESTAMP NOT NULL,
symbol TEXT REFERENCES Symbol(symbol),
price_open DOUBLE PRECISION NULL,
price_high DOUBLE PRECISION NULL,
price_low DOUBLE PRECISION NULL,
price_close DOUBLE PRECISION NULL,

PRIMARY KEY (symbol, time)
);

CREATE EXTENSION IF NOT EXISTS timescaledb;

/* Create hypertable from Quotes table */
SELECT create_hypertable('Quote', 'time');
6 changes: 3 additions & 3 deletions init/data/Quotes.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2021-06-16 20:00:00,AAPL,129.21,129.1,129.21,129.21
2021-06-16 19:59:00,AAPL,129.22,129.15,129.15,129.25
2021-06-16 19:58:00,AAPL,129.33,129.2,129.2,129.33
2021-06-16 20:00:00,AAPL,129.21,129.1,129.21,129.21
2021-06-16 19:59:00,AAPL,129.22,129.15,129.15,129.25
2021-06-16 19:58:00,AAPL,129.33,129.2,129.2,129.33
20 changes: 10 additions & 10 deletions init/data/Users.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
1,user1@gmail.com,$2b$12$wIFJhDVqFgvTX8nRENs5.uUtBpVZmgsEpgTgN6vFeRluy7riDl3vO,,,
2,user2@gmail.com,$2b$12$drK3vo5bvE.sM3XFoezJseAEp8grWu/Ahd5gL8qir4k4mOFFN92/O,,,
3,user3@gmail.com,$2b$12$XRmWWJYrR02Z6Dh1LFz73u67V5GwDSBgxwF300DAS4GbtPDDZ11.m,,,
4,user4@gmail.com,$2b$12$WpjkoreSHLLobze3LWDXmO7oPj2OdN01qIjIOufCHSz14OIwjfFf2,,,
5,user5@gmail.com,$2b$12$PGphjZB09baxtCPMFa8WA.p6Ri/Q5ZIAG.AzT6NLryQaDE0Nn0yO6,,,
6,user6@gmail.com,$2b$12$Tj.LIdkQlldq7PyS4qPuneV8pJm2.Qvi2CthMbkIGX8ecwx17MS5.,,,
7,user7@gmail.com,$2b$12$IDyQYvBSar3VIjkxaEDrWOUJJ/WvP.DW0gyA1t0oG.sXhANes9H12,,,
8,user8@gmail.com,$2b$12$8Nh7uzdAnc5Sk98o3qlexOXKaMQGd/BVQ1x6qUSyfx7QLbiCLPm4q,,,
9,user9@gmail.com,$2b$12$pNPLL73rtNcaZ3T4dsRcaetnUhsRzLMb9asXF5bI65u9.xcrMQLyy,,,
10,user10@gmail.com,$2b$12$H40Ad7BnYdzfT7pmC.7CSOZsHL16ePoIu0Bi8FOixOnEzxQ44vM2i,,,
1,user1@gmail.com,$2b$12$wIFJhDVqFgvTX8nRENs5.uUtBpVZmgsEpgTgN6vFeRluy7riDl3vO,,,
2,user2@gmail.com,$2b$12$drK3vo5bvE.sM3XFoezJseAEp8grWu/Ahd5gL8qir4k4mOFFN92/O,,,
3,user3@gmail.com,$2b$12$XRmWWJYrR02Z6Dh1LFz73u67V5GwDSBgxwF300DAS4GbtPDDZ11.m,,,
4,user4@gmail.com,$2b$12$WpjkoreSHLLobze3LWDXmO7oPj2OdN01qIjIOufCHSz14OIwjfFf2,,,
5,user5@gmail.com,$2b$12$PGphjZB09baxtCPMFa8WA.p6Ri/Q5ZIAG.AzT6NLryQaDE0Nn0yO6,,,
6,user6@gmail.com,$2b$12$Tj.LIdkQlldq7PyS4qPuneV8pJm2.Qvi2CthMbkIGX8ecwx17MS5.,,,
7,user7@gmail.com,$2b$12$IDyQYvBSar3VIjkxaEDrWOUJJ/WvP.DW0gyA1t0oG.sXhANes9H12,,,
8,user8@gmail.com,$2b$12$8Nh7uzdAnc5Sk98o3qlexOXKaMQGd/BVQ1x6qUSyfx7QLbiCLPm4q,,,
9,user9@gmail.com,$2b$12$pNPLL73rtNcaZ3T4dsRcaetnUhsRzLMb9asXF5bI65u9.xcrMQLyy,,,
10,user10@gmail.com,$2b$12$H40Ad7BnYdzfT7pmC.7CSOZsHL16ePoIu0Bi8FOixOnEzxQ44vM2i,,,
6 changes: 3 additions & 3 deletions init/initdata.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
psql -af ./init/create.sql quantx
#!/bin/bash

psql -af ./init/create.sql quantx
psql -af ./init/load.sql quantx
4 changes: 2 additions & 2 deletions init/load.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- \COPY Users FROM './init/data/Users.csv' WITH DELIMITER ',' NULL '' CSV;
-- \COPY Symbol FROM './init/data/Symbols.csv' WITH DELIMITER ',' NULL '' CSV;
-- \COPY Users FROM './init/data/Users.csv' WITH DELIMITER ',' NULL '' CSV;
-- \COPY Symbol FROM './init/data/Symbols.csv' WITH DELIMITER ',' NULL '' CSV;
-- \COPY Quote FROM './init/data/Quotes.csv' WITH DELIMITER ',' NULL '' CSV;
2 changes: 1 addition & 1 deletion init/todo.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Create Result table
- Create Result table
- Enforce only one competition entry per user
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/bin/bash

docker build -t timedb . && docker run -d --name timedb -p 5432:5432 timedb
4 changes: 2 additions & 2 deletions scripts/teardown.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/bin/bash

docker rm -f timedb
26 changes: 13 additions & 13 deletions scripts/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import subprocess
CURR_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(CURR_DIR)
PYTHON = 'python3'
def main():
subprocess.call([PYTHON, os.path.join(CURR_DIR, "start.sh")])
subprocess.call(os.path.join(CURR_DIR, 'teardown.sh'))
if __name__ == "__main__":
import os
import subprocess

CURR_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(CURR_DIR)

PYTHON = 'python3'

def main():
subprocess.call([PYTHON, os.path.join(CURR_DIR, "start.sh")])
subprocess.call(os.path.join(CURR_DIR, 'teardown.sh'))

if __name__ == "__main__":
main()