コード例 #1
0
        public void Create(CoinIntervalModel model, MarketTimes mt)
        {
            if (!CheckIfTableExists(mt))
            {
                CreateTable(mt);
            }

            lock (_connection)
            {
                _connection.Open();
                using (SqlCommand command = new SqlCommand("INSERT INTO " + Market + mt.ToString() + " VALUES (@TimeStamp, @Interval, @Average, @High, @LastHigh, @LastLow, @Low)", _connection))
                {
                    command.Parameters.Add("@TimeStamp", SqlDbType.DateTime).Value = model.IntervalStamp;
                    command.Parameters.Add("@Interval", SqlDbType.Int).Value       = model.Interval;
                    command.Parameters.Add("@Average", SqlDbType.Decimal).Value    = model.Average;
                    command.Parameters.Add("@High", SqlDbType.Decimal).Value       = model.High;
                    command.Parameters.Add("@LastHigh", SqlDbType.Decimal).Value   = model.LastHigh;
                    command.Parameters.Add("@LastLow", SqlDbType.Decimal).Value    = model.LastLow;
                    command.Parameters.Add("@Low", SqlDbType.Decimal).Value        = model.Low;

                    command.ExecuteNonQuery();
                }
                _connection.Close();
            }
        }
コード例 #2
0
 private void Clear(MarketTimes mt)
 {
     lock (Intervals)
     {
         Intervals[mt] = new List <CoinModel>();
     }
 }
コード例 #3
0
 public void Clear(MarketTimes mt)
 {
     lock (Intervals)
     {
         Intervals[mt].Clear();
     }
 }
コード例 #4
0
        private void CompleteInterval(MarketTimes mt)
        {
            var lcm     = Intervals[mt];
            var coinInt = cimBuilder.Build(lcm, mt);

            dbWriter.Create(coinInt, mt);
            Clear(mt);
        }
コード例 #5
0
        public bool CheckIfTableExists(MarketTimes mt)
        {
            lock (_connection)
            {
                _connection.Open();
                bool result;
                using (SqlCommand command = new SqlCommand("SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('[" + Market + mt.ToString() + "]')", _connection))
                    result = Convert.ToBoolean(command.ExecuteScalar());
                _connection.Close();

                return(result);
            }
        }
コード例 #6
0
        public IntervalData CompleteInterval(MarketTimes mt)
        {
            var interdata = new IntervalData();

            lock (Intervals)
            {
                interdata.DataPoints = Intervals[mt];
                Clear(mt);
            }
            interdata.Interval      = mt;
            interdata.IntervalStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

            return(interdata);
        }
コード例 #7
0
        public void CreateTable(MarketTimes mt)
        {
            lock (_connection)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("CREATE TABLE ");
                sb.Append(Market + mt.ToString());
                sb.Append(" ( ID int PRIMARY KEY IDENTITY, TimeStamp DATETIME NOT NULL,");
                sb.Append(" Frame int NOT NULL, Average float NOT NULL, High float NOT NULL,");
                sb.Append(" LastHigh float NOT NULL, LastLow float NOT NULL, Low float NOT NULL )");

                _connection.Open();
                using (SqlCommand command = new SqlCommand(sb.ToString(), _connection))
                    command.ExecuteNonQuery();
                _connection.Close();
            }
        }
コード例 #8
0
        public CoinIntervalModel Build(List <CoinModel> lcm, MarketTimes mt)
        {
            var cim = new CoinIntervalModel();

            cim.IntervalStamp = DateTime.Now;
            cim.Interval      = (int)mt;
            cim.High          = GetHigh(lcm);
            cim.Low           = GetLow(lcm);
            cim.LastHigh      = lcm[lcm.Count - 1].Result.Ask;
            if (lcm[lcm.Count - 1].Result.Bid >= cim.LastLow)
            {
                cim.LastLow = lcm[lcm.Count - 1].Result.Bid;
            }
            else
            {
                cim.LastLow = cim.LastLow;
            }
            cim.Average = GetAverage(lcm);
            return(cim);
        }
コード例 #9
0
 public List <CoinModel> GetInterval(MarketTimes mt)
 {
     return(Intervals[mt]);
 }