-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.py
83 lines (73 loc) · 3.65 KB
/
create_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sqlite3
import config
connection = sqlite3.connect(config.DB_FILE)
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS stock (
id INTEGER PRIMARY KEY,
symbol TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
exchange TEXT NOT NULL
)
"""
)
cursor.execute("""
CREATE TABLE IF NOT EXISTS ticker_details (
id INTEGER PRIMARY KEY,
stock_id INTEGER,
active BOOLEAN,
address TEXT,
city TEXT,
state TEXT,
logo TEXT,
description TEXT,
ticker TEXT,
list_date DATE,
market_cap INTEGER,
name TEXT,
primary_exchange TEXT,
FOREIGN KEY (stock_id) REFERENCES stock (id)
)
"""
)
cursor.execute("""
CREATE TABLE IF NOT EXISTS stock_price (
id INTEGER PRIMARY KEY,
stock_id INTEGER,
date NOT NULL,
open NOT NULL,
high NOT NULL,
low NOT NULL,
close NOT NULL,
volume NOT NULL,
sma_20,
sma_50,
rsi_14,
FOREIGN KEY (stock_id) REFERENCES stock (id)
)
"""
)
cursor.execute("""
CREATE TABLE IF NOT EXISTS strategy (
id INTEGER PRIMARY KEY,
name NOT NULL,
desc TEXT NOT NULL
)
"""
)
cursor.execute("""
CREATE TABLE IF NOT EXISTS stock_strategy (
stock_id INTEGER NOT NULL,
strategy_id INTEGER NOT NULL,
FOREIGN KEY (stock_id) REFERENCES stock(id),
FOREIGN KEY (strategy_id) REFERENCES strategy(id)
)
""")
strategies = [['Opening Range Breakout', 'Due to high significance and non-random price movement, the open gives plenty of insights to build a successful trading strategy. It is often associated with high volume and volatility with multiple trading opportunities. Traders use the opening range to set entry and predict the price action of the day. The theory gained steam during the 1990s when traders started to use the trading signals from the first hour or the opening range to set their strategy. Later though, with the availability of advanced software and data, traders also used 15-minutes and 30-minutes timeframes, but the name stuck on.'],
['Opening Range Breakdown', 'Due to high significance and non-random price movement, the open gives plenty of insights to build a successful trading strategy. It is often associated with high volume and volatility with multiple trading opportunities. Traders use the opening range to set entry and predict the price action of the day. The theory gained steam during the 1990s when traders started to use the trading signals from the first hour or the opening range to set their strategy. Later though, with the availability of advanced software and data, traders also used 15-minutes and 30-minutes timeframes, but the name stuck on.'],
['Bollinger Bands', 'Due to high significance and non-random price movement, the open gives plenty of insights to build a successful trading strategy. It is often associated with high volume and volatility with multiple trading opportunities. Traders use the opening range to set entry and predict the price action of the day. The theory gained steam during the 1990s when traders started to use the trading signals from the first hour or the opening range to set their strategy. Later though, with the availability of advanced software and data, traders also used 15-minutes and 30-minutes timeframes, but the name stuck on.']]
for strategy in strategies:
cursor.execute("""
INSERT INTO strategy (name, desc) VALUES (?, ?)
""", (strategy[0], strategy[1],))
connection.commit()