Ejemplo n.º 1
0
        private int DoSaveBars(SymbolFreq symbol, List<BarData> bars)
        {
            if (bars.Count == 0)
            {
                return 0;
            }

            DateTime firstDate = DateTime.MaxValue;
            DateTime lastDate = DateTime.MinValue;
            foreach (BarData bar in bars)
            {
                if (bar.BarStartTime < firstDate)
                {
                    firstDate = bar.BarStartTime;
                }
                if (bar.BarStartTime > lastDate)
                {
                    lastDate = bar.BarStartTime;
                }
            }

            //int symbolId = GetSymbolID(symbol.Symbol, symbol.Frequency);
            string symbolId = symbol.ToUniqueId();
            //int updatedBars = 0;

            using (OleDbConnection dbConnection = new OleDbConnection(connectionString))
            {
                dbConnection.Open();

                OleDbCommand command = new OleDbCommand("DELETE FROM BarData WHERE SymbolID = '" + symbolId +
                    "' AND [BarDateTime] >= @FirstDate AND [BarDateTime] <= @LastDate", dbConnection);

                OleDbParameter paramFirstDate = new OleDbParameter("@FirstDate", OleDbType.DBTimeStamp);
                paramFirstDate.Value = firstDate;
                command.Parameters.Add(paramFirstDate);

                OleDbParameter paramLastDate = new OleDbParameter("@LastDate", OleDbType.DBTimeStamp);
                paramLastDate.Value = lastDate;
                command.Parameters.Add(paramLastDate);

                command.ExecuteNonQuery();

                OleDbTransaction transaction;

                transaction = dbConnection.BeginTransaction(IsolationLevel.ReadUncommitted);

                foreach (BarData bar in bars)
                {
                    InsertBar(dbConnection, transaction, bar, symbol.ToUniqueId());
                }

                transaction.Commit();

                return bars.Count;
            }
        }
Ejemplo n.º 2
0
        public bool DeleteBars(SymbolFreq symbol)
        {
            DoDeleteBars(symbol.ToUniqueId());

            return true;
        }
Ejemplo n.º 3
0
 public int SaveBars(SymbolFreq symbol, List<BarData> bars)
 {
     // Moving the guts to a private member for obfuscation purposes
     return DoSaveBars(symbol, bars);
 }
Ejemplo n.º 4
0
        private List<BarData> DoLoadBars(SymbolFreq symbol, DateTime startDateTime, DateTime endDateTime, int barCount, bool loadFromEnd)
        {
            List<BarData> bars = new List<BarData>();

            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            dbConnection.Open();

            string query = "SELECT ";
            if (barCount > 0)
            {
                query += "TOP " + barCount + " ";
            }

            query += "* FROM BarData WHERE SymbolID = '" + symbol.ToUniqueId() + "'";
            if (startDateTime != DateTime.MinValue)
            {
                query += " AND BarDateTime >= " + DBDateTime(startDateTime);
            }

            if (endDateTime != DateTime.MaxValue)
            {
                query += " AND BarDateTime <= " + DBDateTime(endDateTime);
            }

            query += " ORDER BY BarDateTime ";

            if (loadFromEnd)
            {
                query += "DESC";
            }
            else
            {
                query += "ASC";
            }

            OleDbCommand command = new OleDbCommand(query, dbConnection);
            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                BarData bar = new BarData();
                bar.EmptyBar = Convert.ToBoolean(reader["EmptyBar"]);

                if (!bar.EmptyBar)
                {
                    bar.BarStartTime = Convert.ToDateTime(reader["BarDateTime"]);
                    bar.Open = Convert.ToDouble(reader["Open"]);
                    bar.Close = Convert.ToDouble(reader["Close"]);
                    bar.High = Convert.ToDouble(reader["High"]);
                    bar.Low = Convert.ToDouble(reader["Low"]);
                    bar.Bid = Convert.ToDouble(reader["Bid"]);
                    bar.Ask = Convert.ToDouble(reader["Ask"]);
                    bar.Volume = Convert.ToUInt64(reader["Volume"]);
                    bar.OpenInterest = Convert.ToInt32(reader["OpenInterest"]);
                }

                bars.Add(bar);
            }

            if (dbConnection.State == ConnectionState.Open)
            {
                dbConnection.Close();
            }

            if (loadFromEnd)
            {
                bars.Reverse();
            }

            return bars;
        }
Ejemplo n.º 5
0
 public List<BarData> LoadBars(SymbolFreq symbol, DateTime startDateTime, DateTime endDateTime, int barCount, bool loadFromEnd)
 {
     // Moved guts to a private for obfuscation purposes
     return DoLoadBars(symbol, startDateTime, endDateTime, barCount, loadFromEnd);
 }
Ejemplo n.º 6
0
 public long GetBarCount(SymbolFreq symbol, DateTime startDateTime, DateTime endDateTime)
 {
     // Moving the guts to a private member for obfuscation purposes
     return DoGetBarCount(symbol.ToUniqueId(), startDateTime, endDateTime);
 }
Ejemplo n.º 7
0
        public int SaveBars(SymbolFreq symbol, List<BarData> bars)
        {
            //SqlConnection dbConnection = new SqlConnection(connectionString);

            //Guid symbol = new Guid(symbolId);
            return DoSaveBars(symbol.ToUniqueId(), bars);
        }
Ejemplo n.º 8
0
 public List<BarData> LoadBars(SymbolFreq symbol, DateTime startDateTime, DateTime endDateTime, int maxLoadBars, bool loadFromEnd)
 {
     return DoLoadBars(symbol.ToUniqueId(), startDateTime, endDateTime, maxLoadBars, loadFromEnd);
 }
Ejemplo n.º 9
0
 public long GetBarCount(SymbolFreq symbol, DateTime startDateTime, DateTime endDateTime)
 {
     return DoGetBarCount(symbol.ToUniqueId(), startDateTime, endDateTime);
 }