Path: blob/master/ invest-robot-contest_tinkoff-trading-bot-develop/app/stats/sqlite_client.py
5935 views
from app.sqlite.client import SQLiteClient123class StatsSQLiteClient:4def __init__(self, db_name: str):5self.db_client = SQLiteClient(db_name)6self.db_client.connect()78self._create_tables()910def _create_tables(self):11self.db_client.execute(12"""13CREATE TABLE IF NOT EXISTS orders (14id INTEGER PRIMARY KEY,15figi str,16direction TEXT,17price REAL,18quantity INTEGER,19status TEXT20)21"""22)2324def add_order(25self,26order_id: str,27figi: str,28order_direction: str,29price: float,30quantity: int,31status: str,32):33self.db_client.execute_insert(34"INSERT INTO orders VALUES (?, ?, ?, ?, ?, ?)",35(order_id, figi, order_direction, price, quantity, status),36)3738def get_orders(self):39return self.db_client.execute_select("SELECT * FROM orders")4041def update_order_status(self, order_id: str, status: str):42self.db_client.execute_update(43"UPDATE orders SET status=? WHERE id=?",44(status, order_id),45)464748