Esempio n. 1
0
        public void SavePurgeCandlesSQLite(SQLiteCommand cmd)
        {
            cmd.CommandText = string.Format("SELECT * FROM {0} ORDER BY datetime(DateTime) DESC Limit 1", MarketDelta);
            DateTime dateTime = Convert.ToDateTime(cmd.ExecuteScalar());

            List <HistDataLine> removeList = new List <HistDataLine>();

            foreach (HistDataLine line in Candles5m)
            {
                if (line.T >= LastStoredCandle.Subtract(TimeSpan.FromHours(3)))
                {
                    break;
                }
                if (line.T <= dateTime)
                {
                    continue;
                }
                else
                {
                    cmd.CommandText = string.Format(
                        "INSERT INTO {0} (DateTime, Open, High, Low, Close, Volume, BaseVolume) "
                        + "VALUES ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')",
                        MarketDelta,
                        line.T.ToString("yyyy-MM-dd HH:mm:ss"), line.O, line.H, line.L, line.C, line.V, line.BV);

                    cmd.ExecuteNonQuery();
                    removeList.Add(line);
                }
            }

            Candles5m = (List <HistDataLine>)Candles5m.Except(removeList);
        }
Esempio n. 2
0
        public void BuildCandleFromRecentFills(DateTime NextCandleTime)
        {
            //check current, if not, rectify
            //If candle is current, Candles are Resolved
            if (NextCandleTime.AddMinutes(5) > DateTime.UtcNow)
            {
                return;
            }

            Decimal       BV          = 0;
            List <mdFill> candleFills = new List <mdFill>();

            foreach (mdFill fill in RecentFills)
            {
                if (fill.TimeStamp < NextCandleTime)
                {
                    continue;
                }
                else if (fill.TimeStamp >= NextCandleTime.AddMinutes(5))
                {
                    break;
                }
                else
                {
                    BV += (fill.Quantity * fill.Rate);
                    candleFills.Add(fill);
                }
            }

            if (candleFills.Count == 0)
            {
                return;
            }

            Decimal O = candleFills.First().Rate,
                    H = candleFills.Max(x => x.Rate),
                    L = candleFills.Min(x => x.Rate),
                    C = candleFills.Last().Rate,
                    V = candleFills.Sum(x => x.Quantity);

            HistDataLine candle = new HistDataLine(NextCandleTime, O, H, L, C, V, BV);

            Candles5m.Add(candle);
            LastStoredCandle = LastStoredCandle.AddMinutes(5);
        }