SyncDB
- Utilities
- Maxim Kuznetsov
- Version: 1.0
- Activations: 5
A service to keep the SQLite database up to date. Fast real-time operation. Saves open positions and orders, current quotes, and trading history. Take advantage of SQLite's capabilities for intermediate data storage, analytics, and integration of the MetaTrader platform. Save all your data in one place. Use the saved data in SQL analytical queries, from Python and other languages, to build dashboards and integrate MetaTrader
Parameters
SyncDB creates and maintains 2 databases at the same time :
db/{server_name}.{account}.history.db is a replenished history database that contains the history of transactions and information about instruments
db/ram/{server_name}.{account}.trade.db is an updated database that contains open orders and positions, current prices.
Where {server_name} is the name of the DC trading server, it will be delivered automatically. {account} the number of the trading account on it. Thus, with the simultaneous operation of several terminals, their data is stored separately and will not cause mutual locks and slowdowns.
I strongly recommend placing the db/ram directory on a ram disk or fast media.
Very simple parameters:
- priceUpdateSec, 15 - the period (seconds) for updating prices in the database. When using a ram disk, you can specify smaller values, up to 0
- useCommon , true. Use a [COMMON] shared data directory.
- dbFolder , "db". The name of the database storage folder
The scheme of the trade.db database
The database contains the necessary minimum, in the style of mt4 and adapted for frequent additions. 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
History.db database schema
CREATE TABLE IF NOT EXISTS History ( 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 INTEGER, 'comment' VARCHAR(255) ) WITHOUT ROWID
and
CREATE TABLE IF NOT EXISTS Symbol ( name VARCHAR(16) PRIMARY KEY, base VARCHAR(16), quote VARCHAR(16), digits INTEGER, point REAL, tickSize REAL, minLot REAL, maxLot REAL, lotStep REAL ) WITHOUT ROWID
Usage
Just run an instance of the SyncDB service, and use the data in your applications and for integration.