BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
Query.h
Go to the documentation of this file.
1
9#pragma once
10
11namespace data::query {
12 // Trade Table
13 constexpr auto createTradeTableQuery
14 = "CREATE TABLE IF NOT EXISTS trades (trade_id INTEGER PRIMARY "
15 "KEY, symbol TEXT, buy_order_id INTEGER, sell_order_id INTEGER, "
16 "quantity INTEGER, price REAL, timestamp INTEGER);";
18 = "INSERT INTO trades (trade_id, symbol, buy_order_id, "
19 "sell_order_id, quantity, price, timestamp) VALUES (?, ?, ?, ?, "
20 "?, ?, ?);";
21
22 // Trade ID Table
24 = "CREATE TABLE IF NOT EXISTS trade_id (id INTEGER PRIMARY KEY);";
25 constexpr auto getTradeIdQuery = "SELECT id FROM trade_id;";
26 constexpr auto setTradeIdQuery
27 = "INSERT OR REPLACE INTO trade_id (id) VALUES (?);";
28 constexpr auto truncateTradeIdQuery = "DELETE FROM trade_id;";
29
30 // Order Table
31 constexpr auto createOrderTableQuery
32 = "CREATE TABLE IF NOT EXISTS orders (core_order_id INTEGER "
33 "PRIMARY "
34 "KEY, client_order_id INTEGER, client_id TEXT, sender_comp_id "
35 "TEXT, symbol TEXT, side TEXT, type TEXT, "
36 "time_in_force TEXT, price REAL, original_quantity INTEGER, "
37 "remaining_quantity INTEGER, status TEXT, timestamp INTEGER);";
39 = "INSERT INTO orders (core_order_id, client_order_id, client_id, "
40 "sender_comp_id, symbol, side, type, "
41 "time_in_force, price, original_quantity, remaining_quantity, "
42 "status, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
43 "?);";
45 = "SELECT core_order_id, client_order_id, client_id, "
46 "sender_comp_id, symbol, side, type, time_in_force, "
47 "price, original_quantity, remaining_quantity, status, timestamp "
48 "FROM orders WHERE symbol = ? AND (status = 'New' OR status = "
49 "'PartiallyFilled');";
50 constexpr auto removeOrderQuery
51 = "DELETE FROM orders WHERE core_order_id = ?;";
52 constexpr auto updateOrderQuery = "UPDATE orders SET remaining_quantity = "
53 "?, status = ? WHERE core_order_id = ?;";
54
55 // Clients Table
57 = "CREATE TABLE IF NOT EXISTS clients (sender_comp_id TEXT PRIMARY "
58 "KEY, is_active INTEGER);";
59 constexpr auto insertClientQuery
60 = "INSERT OR IGNORE INTO clients (sender_comp_id, is_active) "
61 "VALUES (?, ?);";
62 constexpr auto loadClientsQuery
63 = "SELECT sender_comp_id FROM clients WHERE is_active = 1;";
64 constexpr auto truncateClientsQuery = "DELETE FROM clients;";
65
66 // Sequence Table
67 constexpr auto createSequenceTable
68 = "CREATE TABLE IF NOT EXISTS FIX_Sequences ("
69 "compId TEXT PRIMARY KEY NOT NULL,"
70 "inSeqNum INTEGER NOT NULL,"
71 "outSeqNum INTEGER NOT NULL"
72 ");";
73 constexpr auto getSequenceNumberQuery = "SELECT inSeqNum, outSeqNum FROM "
74 "FIX_Sequences WHERE compId = ?";
76 = "INSERT INTO FIX_Sequences (compId, "
77 "inSeqNum, outSeqNum) "
78 "VALUES (?, ?, ?) "
79 "ON CONFLICT(compId) DO UPDATE SET "
80 "inSeqNum=excluded.inSeqNum, "
81 "outSeqNum=excluded.outSeqNum;";
82
83 // Candle Table
85 = "CREATE TABLE IF NOT EXISTS candles (symbol TEXT, interval INTEGER, "
86 "timestamp INTEGER, open REAL, high REAL, low REAL, close REAL, volume INTEGER, "
87 "PRIMARY KEY(symbol, interval, timestamp));";
88 constexpr auto insertCandleQuery
89 = "INSERT OR REPLACE INTO candles (symbol, interval, timestamp, open, high, "
90 "low, close, volume) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
91 constexpr auto loadHistoryQuery
92 = "SELECT symbol, interval, timestamp, open, high, low, close, volume "
93 "FROM candles WHERE symbol = ? AND interval = ? ORDER BY timestamp DESC LIMIT ?;";
94} // namespace data::query
Definition Query.h:11
constexpr auto createCandleTableQuery
Definition Query.h:85
constexpr auto updateOrderQuery
Definition Query.h:52
constexpr auto insertIntoTradeTableQuery
Definition Query.h:18
constexpr auto truncateClientsQuery
Definition Query.h:64
constexpr auto loadHistoryQuery
Definition Query.h:92
constexpr auto insertClientQuery
Definition Query.h:60
constexpr auto createOrderTableQuery
Definition Query.h:32
constexpr auto truncateTradeIdQuery
Definition Query.h:28
constexpr auto removeOrderQuery
Definition Query.h:51
constexpr auto loadOrdersForInstrumentQuery
Definition Query.h:45
constexpr auto createTradeTableQuery
Definition Query.h:14
constexpr auto insertCandleQuery
Definition Query.h:89
constexpr auto insertIntoOrderTableQuery
Definition Query.h:39
constexpr auto getTradeIdQuery
Definition Query.h:25
constexpr auto getSequenceNumberQuery
Definition Query.h:73
constexpr auto createSequenceTable
Definition Query.h:68
constexpr auto createTradeIdTableQuery
Definition Query.h:24
constexpr auto loadClientsQuery
Definition Query.h:63
constexpr auto updateSequenceNumberQuery
Definition Query.h:76
constexpr auto createClientTableQuery
Definition Query.h:57
constexpr auto setTradeIdQuery
Definition Query.h:27