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);
        }
예제 #2
0
        public static List <Advice> GetAllRecentAdvices()
        {
            List <Advice> advices = new List <Advice>();
            string        query   = string.Format(@"SELECT Time, Confidence, Price, Action, aa.algorithm_name, aa.bucket_group, Created_at FROM advices aa  INNER Join (SELECT algorithm_name, bucket_group, MAX(Time) as t FROM advices group by algorithm_name, bucket_group) bg on bg.bucket_group = aa.bucket_group AND bg.t = aa.Time AND aa.algorithm_name = bg.algorithm_name Order by Time Desc");
            DataTable     dt      = RunSELECT(query);

            foreach (DataRow dr in dt.Rows)
            {
                Advice advice = new Advice();
                advice.Time          = (int)TimeUtil.ToUnixTime((DateTime)dr[0]);
                advice.Confidence    = (decimal)dr[1];
                advice.Price         = (decimal)dr[2];
                advice.Action        = ActionUtil.GetTradeActionBy((string)dr[3]);
                advice.AlgorithmName = ((string)dr[4]).Trim();
                advice.Group         = GroupUtil.GetGroupBy((string)dr[5]);
                advice.CreatedAt     = (DateTime)dr[6];
                advices.Add(advice);
            }

            return(advices);
        }
예제 #3
0
        public static List <Advice> GetAllAdvicesInRange(string algorithmName, GroupBy group, double start, double end)
        {
            List <Advice> advices = new List <Advice>();

            string    query = string.Format(@"SELECT Time, Confidence, Price, Action, algorithm_name, bucket_group, Created_at, id FROM advices WHERE Time >= '{0}' AND Time <= '{3}' AND algorithm_name = '{1}' AND bucket_group = '{2}' Order By Time Asc", TimeUtil.FromUnixTime((long)start).ToString("yyyy-MM-dd HH:mm:ss"), algorithmName, group.ToString(), TimeUtil.FromUnixTime((long)end).ToString("yyyy-MM-dd HH:mm:ss"));
            DataTable dt    = RunSELECT(query);

            foreach (DataRow dr in dt.Rows)
            {
                Advice advice = new Advice();
                advice.Time          = (int)TimeUtil.ToUnixTime((DateTime)dr[0]);
                advice.Confidence    = (decimal)dr[1];
                advice.Price         = (decimal)dr[2];
                advice.Action        = ActionUtil.GetTradeActionBy((string)dr[3]);
                advice.AlgorithmName = ((string)dr[4]).Trim();
                advice.Group         = GroupUtil.GetGroupBy((string)dr[5]);
                advice.Id            = (int)dr[6];
                advices.Add(advice);
            }
            return(advices);
        }
        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);
        }
예제 #5
0
        public override DataObject Exists()
        {
            string    query = string.Format(@"SELECT Time, Confidence, Price, Action, algorithm_name, bucket_group, Created_at, id, email_sent FROM advices WHERE Time = '{0}' AND algorithm_name = '{1}' AND bucket_group = '{2}'", TimeUtil.FromUnixTime((long)Time).ToString("yyyy-MM-dd HH:mm:ss"), AlgorithmName, Group.ToString());
            DataTable dt    = RunSELECT(query);

            if (dt.Rows.Count > 0)
            {
                Advice advice = new Advice();
                advice.Time          = (int)TimeUtil.ToUnixTime((DateTime)dt.Rows[0][0]);
                advice.Confidence    = (decimal)dt.Rows[0][1];
                advice.Price         = (decimal)dt.Rows[0][2];
                advice.Action        = ActionUtil.GetTradeActionBy((string)dt.Rows[0][3]);
                advice.AlgorithmName = ((string)dt.Rows[0][4]).Trim();
                advice.Group         = GroupUtil.GetGroupBy((string)dt.Rows[0][5]);
                advice.Id            = (int)dt.Rows[0][7];
                advice.EmailSent     = (bool)dt.Rows[0][8];
                return(advice);
            }
            else
            {
                return(null);
            }
        }
        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);
            }
        }