mirror of
https://github.com/chrisnov-it/quantumbotx.git
synced 2026-07-27 18:57:47 +00:00
78737b6835
- Update `.gitignore` to include `lab/` for backtesting and raw data. - Refactor `app.py` to improve error handling and logging. - Remove deprecated files: `core/bot_logic.py`, `core/bots/base_bot.py`, `core/bots/manager.py`, `core/db/database.py`, `core/routes/api_analysis.py`, `core/routes/api_bots_analysis.py`, `core/strategies/logic_ma.py`, `core/strategies/logic_rsi.py`. - Modify multiple files to enhance bot management, routing, and strategy handling. - Update JavaScript and HTML templates for better UI and functionality.
94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
import sqlite3
|
|
import os
|
|
|
|
# Nama file database
|
|
DB_FILE = "bots.db"
|
|
|
|
def create_connection(db_file):
|
|
""" Membuat koneksi ke database SQLite """
|
|
conn = None
|
|
try:
|
|
conn = sqlite3.connect(db_file)
|
|
print(f"Berhasil terhubung ke SQLite versi {sqlite3.version}")
|
|
return conn
|
|
except sqlite3.Error as e:
|
|
print(e)
|
|
return conn
|
|
|
|
def create_table(conn, create_table_sql):
|
|
""" Membuat tabel dari statement SQL """
|
|
try:
|
|
c = conn.cursor()
|
|
c.execute(create_table_sql)
|
|
print("Tabel berhasil dibuat.")
|
|
except sqlite3.Error as e:
|
|
print(e)
|
|
|
|
def main():
|
|
# Hapus database lama jika ada, untuk memastikan mulai dari awal
|
|
if os.path.exists(DB_FILE):
|
|
os.remove(DB_FILE)
|
|
print(f"File database lama '{DB_FILE}' telah dihapus.")
|
|
|
|
# SQL statement untuk membuat tabel 'bots'
|
|
sql_create_bots_table = """
|
|
CREATE TABLE IF NOT EXISTS bots (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
market TEXT NOT NULL,
|
|
status TEXT NOT NULL DEFAULT 'Dijeda',
|
|
lot_size REAL NOT NULL DEFAULT 0.01,
|
|
sl_pips INTEGER NOT NULL DEFAULT 100,
|
|
tp_pips INTEGER NOT NULL DEFAULT 200,
|
|
timeframe TEXT NOT NULL DEFAULT 'H1',
|
|
check_interval_seconds INTEGER NOT NULL DEFAULT 60,
|
|
strategy TEXT NOT NULL
|
|
);
|
|
"""
|
|
|
|
# SQL statement untuk membuat tabel 'trade_history'
|
|
sql_create_history_table = """
|
|
CREATE TABLE IF NOT EXISTS trade_history (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
bot_id INTEGER NOT NULL,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
action TEXT NOT NULL,
|
|
details TEXT,
|
|
FOREIGN KEY (bot_id) REFERENCES bots (id) ON DELETE CASCADE
|
|
);
|
|
"""
|
|
|
|
# SQL statement untuk membuat tabel 'notifications'
|
|
sql_create_notifications_table = """
|
|
CREATE TABLE IF NOT EXISTS notifications (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
bot_id INTEGER,
|
|
message TEXT NOT NULL,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
is_read INTEGER NOT NULL DEFAULT 0,
|
|
FOREIGN KEY (bot_id) REFERENCES bots (id) ON DELETE CASCADE
|
|
);
|
|
"""
|
|
|
|
# Buat koneksi database
|
|
conn = create_connection(DB_FILE)
|
|
|
|
# Buat tabel-tabel
|
|
if conn is not None:
|
|
print("\nMembuat tabel 'bots'...")
|
|
create_table(conn, sql_create_bots_table)
|
|
|
|
print("\nMembuat tabel 'trade_history'...")
|
|
create_table(conn, sql_create_history_table)
|
|
|
|
print("\nMembuat tabel 'notifications'...")
|
|
create_table(conn, sql_create_notifications_table)
|
|
|
|
conn.close()
|
|
print(f"\nDatabase '{DB_FILE}' berhasil dibuat dengan semua tabel yang diperlukan.")
|
|
else:
|
|
print("Error! Tidak dapat membuat koneksi database.")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|