public static List<Candle> Get(string instrumentID, DateTime fromTradingDay) { var table = new DataTable(); var command = new SQLiteCommand("SELECT * FROM candle WHERE instrumentid=@InstrumentID AND tradingday>=@TradingDay", DALUtil.Connection); command.Parameters.AddWithValue("@InstrumentID", instrumentID); command.Parameters.AddWithValue("@TradingDay", fromTradingDay); var adapter = new SQLiteDataAdapter(command); adapter.Fill(table); var candles = new List<Candle>(); foreach (var item in table.Rows) { var row = item as DataRow; var candle = new Candle(); candle.InstrumentID = row.Field<string>(0); candle.TradingDay = row.Field<DateTime>(1); candle.CandleTime = row.Field<DateTime>(2); candle.Open = DALUtil.GetDouble(row[3]); candle.Close = DALUtil.GetDouble(row[4]); candle.High = DALUtil.GetDouble(row[5]); candle.Low = DALUtil.GetDouble(row[6]); candle.Volume = row.Field<int>(7); candle.OpenInterest = DALUtil.GetDouble(row[8]); candles.Add(candle); } return candles; }
public bool ProcessQuotation(Quotation quotation, int volume) { DateTime newCandleTime = CandleHelper.GetCandleTime(quotation.Time, quotation.TradingDay, this.type); if (this.LastData == null || this.LastData.CandleTime != newCandleTime) { this.LastData = new Candle(quotation, newCandleTime, volume); return true; } else { this.LastData.UpdateCandle(quotation, volume); return false; } }
private static Candle CombineCandle(List<Candle> candles, DateTime candleTime) { Candle first = candles[0]; Candle last = candles[candles.Count - 1]; Candle result = new Candle() { InstrumentID = first.InstrumentID, TradingDay = first.TradingDay, CandleTime = candleTime, Open = first.Open, Close = last.Close, High = candles.Max(p => p.High), Low = candles.Min(p => p.Low), Volume = candles.Sum(p => p.Volume), OpenInterest = last.OpenInterest }; return result; }
public static Candle GetLast(string instrumentID) { var command = new SQLiteCommand("SELECT * FROM candle WHERE instrumentid=@InstrumentID order by candletime desc limit 1", DALUtil.Connection); command.Parameters.AddWithValue("@InstrumentID", instrumentID); SQLiteDataReader reader = command.ExecuteReader(); if (!reader.Read()) { return null; } var candle = new Candle(); candle.InstrumentID = reader.GetString(0); candle.TradingDay = reader.GetDateTime(1); candle.CandleTime = reader.GetDateTime(2); candle.Open = DALUtil.GetDouble(reader[3]); candle.Close = DALUtil.GetDouble(reader[4]); candle.High = DALUtil.GetDouble(reader[5]); candle.Low = DALUtil.GetDouble(reader[6]); candle.Volume = reader.GetInt32(7); candle.OpenInterest = DALUtil.GetDouble(reader[8]); return candle; }
public static void AddCandle(Candle candle) { candleQueue.Enqueue(candle); }
public CandleBuilder(Candle lastData, CandleType type) { this.LastData = lastData; this.type = type; }