/// <summary>Called when a new user account has been assigned</summary> private void HandleAcctChanged(object sender = null, EventArgs e = null) { // Ensure closed Util.Dispose(ref m_db); // If there is no account id, don't open a database if (Model == null || !Model.Acct.AccountId.HasValue()) { return; } // Open a database of the trade history and other user account related info var filepath = Path_.CombinePath(Settings.General.AcctDataCacheDir, "Acct_{0}.db".Fmt(Model.Acct.AccountId)); m_db = new Sqlite.Database(filepath); // Tweak some DB settings for performance m_db.Execute(Sqlite.Sql("PRAGMA synchronous = OFF")); m_db.Execute(Sqlite.Sql("PRAGMA journal_mode = MEMORY")); // Ensure the table of trades exists var sql = Sqlite.Sql("create table if not exists ", Table.TradeHistory, " (\n", "[", nameof(Trade.Id), "] text primary key,\n", "[", nameof(Trade.SymbolCode), "] text)"); m_db.Execute(sql); // Ensure the table of orders exists sql = Sqlite.Sql("create table if not exists ", Table.Orders, " (\n", "[", nameof(Order.Id), "] integer primary key,\n", "[", ("TradeId"), "] text,\n", "[", nameof(Order.SymbolCode), "] text,\n", "[", nameof(Order.TradeType), "] integer)"); m_db.Execute(sql); }
public Transmitter(string sym, string db_filepath) { SymbolCode = sym; TimeFrames = new ETimeFrame[0]; // Load the instrument candle database m_db = new Sqlite.Database(db_filepath, Sqlite.OpenFlags.ReadOnly); // Read the price data PriceData = m_db.EnumRows <PriceData>("select * from PriceData").First(); }
public Instrument(MainModel model, string symbol) { m_cache = new List <Candle>(CacheSize); Model = model; SymbolCode = symbol; SupportResistLevels = new BindingSource <SnRLevel> { DataSource = new BindingListEx <SnRLevel>() }; // Load the sqlite database of historic price data m_db = new Sqlite.Database(DBFilepath); // Tweak some DB settings for performance m_db.Execute(Sqlite.Sql("PRAGMA synchronous = OFF")); m_db.Execute(Sqlite.Sql("PRAGMA journal_mode = MEMORY")); // Create a table for the price data info m_db.Execute(SqlExpr.PriceDataTable()); // Ensure tables exist for each of the time frames. // Note: timestamp is not the row id. Row Ids should not have any // meaning. It's more efficient to let the DB do the sorting // and just use 'order by' in queries foreach (var tf in Enum <ETimeFrame> .Values.Where(x => x != ETimeFrame.None)) { m_db.Execute(SqlExpr.CandleTable(tf)); } // Create a table for the SnR levels m_db.Execute(SqlExpr.SnRLevelsTable()); // Initialise from the DB, so don't write back to the db using (Scope.Create(() => ++ m_suspend_db_updates, () => -- m_suspend_db_updates)) { // Select the default time frame to begin with TimeFrame = Settings.General.DefaultTimeFrame; // Load the last known price data for the instrument PriceData = m_db.EnumRows <PriceData>(SqlExpr.GetPriceData()).FirstOrDefault() ?? new PriceData(); // Load the known support and resistance levels SupportResistLevels.AddRange(m_db.EnumRows <SnRLevel>(SqlExpr.GetSnRLevelData())); // Set up the EMAs ResetEma(); } }