SyncTradeSQL
- Utilities
- Maxim Kuznetsov
- Version: 1.0
Script for quick updates (synchronization) up-to-date data in the SQLite database. Saves open positions and orders, current quotes.
Take advantage of SQLite's capabilities for intermediate data storage, analytics, and integrations of the MetaTrader platform. Keep all your data in one place.
Use the saved data in SQL analytical queries, from Python and other languages, to build dashboards
Parameters
- useDefaults true - use default parameters. Save data to the COMMON hierarchy, to the db/ram/{server_name} directory.{account number}.trade.db
you can specify useDefaults=false and set your own save options:
- useCommon - use the COMMON hierarchy or the data directory of the current terminal
- useFolder - directory to save the database
- useFilename - the name of the database inside the directory
Database schema
The database contains the necessary minimum, in the style of mt4 and adapted for frequent changes. After creating the database with the script, you can make your own adjustments to it (add indexes, computable fields, additional data and tables)
CREATE TABLE IF NOT EXISTS Trade ( ticket INT PRIMARY KEY, symbol VARCHAR(16), 'type' VARCHAR(16), lots REAL, openPrice REAL, stopLoss REAL, takeProfit REAL, price REAL, 'time' DATETIME, closeTime DATETIME, expiration DATETIME, profit REAL, swap REAL, commission REAL, magic INT , 'comment' VARCHAR(255) ) WITHOUT ROWID
and
CREATE TABLE IF NOT EXISTS Watch ( name VARCHAR(16) PRIMARY KEY, 'time' DATETIME, bid REAL, ask REAL, spread INTEGER, stopLevel INTEGER, tickValue REAL ) WITHOUT ROWID
Using
Just run the script when you need to get the data.
For optimization, I recommend putting the db/ram directory on a ram disk