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); }
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 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); } }