public static List <TradeBucket> GetLastBuckets(GroupBy group, double time, int buckets)
        {
            DateTime last = DateTime.MinValue;

            DateTime endTime = TimeUtil.FromUnixTime((long)time);

            string    query = string.Format(@"SELECT Time, High, Low, Volume, open, close, number_of_trades, bucket_group, ID FROM trade_buckets WHERE bucket_group = '{0}' AND TIME <= '{1}' Order By Time desc limit {2}", group.ToString(), endTime.ToString("yyyy-MM-dd HH:mm:ss"), buckets);
            DataTable dt    = RunSELECT(query);

            List <TradeBucket> results = new List <TradeBucket>();

            //need to reverse order
            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                TradeBucket tradeBucket = new TradeBucket();
                tradeBucket.Time      = (int)TimeUtil.ToUnixTime((DateTime)dt.Rows[i][0]);
                tradeBucket.High      = (decimal)dt.Rows[i][1];
                tradeBucket.Low       = (decimal)dt.Rows[i][2];
                tradeBucket.Volume    = (decimal)dt.Rows[i][3];
                tradeBucket.Open      = (decimal)dt.Rows[i][4];
                tradeBucket.Close     = (decimal)dt.Rows[i][5];
                tradeBucket.NumTrades = (int)dt.Rows[i][6];
                tradeBucket.Group     = GroupUtil.GetGroupBy((string)dt.Rows[i][7]);
                tradeBucket.Id        = (int)dt.Rows[i][8];
                results.Add(tradeBucket);
            }
            return(results);
        }
        public static List <TradeBucket> GetTwoLastKnownBucket(GroupBy group)
        {
            string             query        = string.Format(@"SELECT Time, High, Low, Volume, open, close, number_of_trades, bucket_group, ID FROM trade_buckets where bucket_group = '{0}' Order By Time desc limit 2", group.ToString());
            DataTable          dt           = RunSELECT(query);
            List <TradeBucket> tradeBuckets = new List <TradeBucket>();

            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                TradeBucket tradeBucket = new TradeBucket();
                tradeBucket.Time      = (int)TimeUtil.ToUnixTime((DateTime)dt.Rows[i][0]);
                tradeBucket.High      = (decimal)dt.Rows[i][1];
                tradeBucket.Low       = (decimal)dt.Rows[i][2];
                tradeBucket.Volume    = (decimal)dt.Rows[i][3];
                tradeBucket.Open      = (decimal)dt.Rows[i][4];
                tradeBucket.Close     = (decimal)dt.Rows[i][5];
                tradeBucket.NumTrades = (int)dt.Rows[i][6];
                tradeBucket.Group     = GroupUtil.GetGroupBy((string)dt.Rows[i][7]);
                tradeBucket.Id        = (int)dt.Rows[i][8];
                tradeBuckets.Add(tradeBucket);
            }
            return(tradeBuckets);
        }
        public override DataObject Exists()
        {
            string    query = string.Format(@"SELECT Time, High, Low, Volume, open, close, number_of_trades, bucket_group, ID FROM trade_buckets WHERE Time = '{0}' AND bucket_group = '{1}'", TimeUtil.FromUnixTime((long)Time).ToString("yyyy-MM-dd HH:mm:ss"), Group);
            DataTable dt    = RunSELECT(query);

            if (dt.Rows.Count > 0)
            {
                TradeBucket tradeBucket = new TradeBucket();
                tradeBucket.Time      = (int)TimeUtil.ToUnixTime((DateTime)dt.Rows[0][0]);
                tradeBucket.High      = (decimal)dt.Rows[0][1];
                tradeBucket.Low       = (decimal)dt.Rows[0][2];
                tradeBucket.Volume    = (decimal)dt.Rows[0][3];
                tradeBucket.Open      = (decimal)dt.Rows[0][4];
                tradeBucket.Close     = (decimal)dt.Rows[0][5];
                tradeBucket.NumTrades = (int)dt.Rows[0][6];
                tradeBucket.Group     = GroupUtil.GetGroupBy((string)dt.Rows[0][7]);
                tradeBucket.Id        = (int)dt.Rows[0][8];
                return(tradeBucket);
            }
            else
            {
                return(null);
            }
        }
        private void merge(TradeBucket tb)
        {
            TradeBucket exist = (TradeBucket)tb;

            Id = exist.Id;
        }