Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_tinkoff-trading-bot-develop/app/stats/sqlite_client.py
5935 views
1
from app.sqlite.client import SQLiteClient
2
3
4
class StatsSQLiteClient:
5
def __init__(self, db_name: str):
6
self.db_client = SQLiteClient(db_name)
7
self.db_client.connect()
8
9
self._create_tables()
10
11
def _create_tables(self):
12
self.db_client.execute(
13
"""
14
CREATE TABLE IF NOT EXISTS orders (
15
id INTEGER PRIMARY KEY,
16
figi str,
17
direction TEXT,
18
price REAL,
19
quantity INTEGER,
20
status TEXT
21
)
22
"""
23
)
24
25
def add_order(
26
self,
27
order_id: str,
28
figi: str,
29
order_direction: str,
30
price: float,
31
quantity: int,
32
status: str,
33
):
34
self.db_client.execute_insert(
35
"INSERT INTO orders VALUES (?, ?, ?, ?, ?, ?)",
36
(order_id, figi, order_direction, price, quantity, status),
37
)
38
39
def get_orders(self):
40
return self.db_client.execute_select("SELECT * FROM orders")
41
42
def update_order_status(self, order_id: str, status: str):
43
self.db_client.execute_update(
44
"UPDATE orders SET status=? WHERE id=?",
45
(status, order_id),
46
)
47
48