Beispiel #1
0
        public K2DataObjects.PriceBar[] GetPriceBars(string mnemonic, long startTick, int count)
        {
            using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
            {
                var barSet =
                   (from bar in db.PriceBars
                    where (bar.Mnemonic == mnemonic) && (bar.TimeStamp >= startTick)
                    select bar).Take(count);

                return (barSet.ToArray());

            }
        }
Beispiel #2
0
        public K2DataObjects.PriceBar GetLastPriceBars(string mnemonic, long startTick)
        {
            using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
            {
                var barSet =
                   (from bar in db.PriceBars
                    where (bar.Mnemonic == mnemonic) && (bar.TimeStamp >= startTick)
                    select bar).LastOrDefault();

                return (barSet);

            }
        }
Beispiel #3
0
        public void Insert(K2DataObjects.PriceBar inBar, bool allowUpdate)
        {
            try
            {

                using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
                {
                    var dbPriceBars =
                      (from bar in db.PriceBars
                       where bar.Mnemonic == inBar.Mnemonic &&
                        bar.ItemType == inBar.ItemType &&
                        bar.ItemSize == inBar.ItemSize &&
                        bar.TimeStamp == inBar.TimeStamp &&
                        bar.RequestID == inBar.RequestID
                       select bar).SingleOrDefault();

                    if (dbPriceBars != null)
                    {
                        if (allowUpdate)
                        {
                            db.PriceBars.DeleteOnSubmit(dbPriceBars);
                            db.SubmitChanges();
                        }
                        else
                        {
                            throw new Exception("bar exists");
                        }
                    }
                    db.PriceBars.InsertOnSubmit(inBar);

                    db.SubmitChanges();

                }

            }
            catch (Exception myE)
            {
                m_Log.Error("Insert", myE);
            }
        }
Beispiel #4
0
        public decimal[][] GetCurveValues(string mnemonic, long startTick, int count, List<string> headerIDs)
        {
            try
            {
                Dictionary<string, int> headerIndex = new Dictionary<string, int>();
                int i = 0;
                foreach (string header in headerIDs)
                {
                    if (!headerIndex.ContainsKey(header))
                    {
                        headerIndex.Add(header, i++);
                    }
                }
                List<decimal[]> cvResult = new List<decimal[]>();
                using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
                {
                    var curveValueSet =
                       (from cv in db.CurveValues
                        where (cv.Mnemonic == mnemonic) && (cv.TimeStamp >= startTick)
                        orderby cv.TimeStamp
                        select cv);

                    long prevTimeStamp = 0;
                    decimal[] headerValues=null;
                    // NEED TO AGGRGATE TO N second chuncks so match bars
                    // ELSE NEED SOME FAST LOOK UP
                    long roundedTime = 0;
                    foreach (K2DataObjects.CurveValue v in curveValueSet)
                    {
                        roundedTime = RoundTimeStamp(v.TimeStamp, 60000);

                        if (prevTimeStamp != roundedTime)
                        {
                            // DONT ADD IF NOT USED i.e. 0 values
                            headerValues = new decimal[headerIDs.Count];
                            cvResult.Add(headerValues);
                            prevTimeStamp = roundedTime;
                            if (cvResult.Count >= count)
                            {
                                break;
                            }

                        }
                        if (headerIndex.ContainsKey(v.HeaderID))
                        {
                            // MARK ROW AS USED
                            if (v.Value > 0)
                            {
                                headerValues[headerIndex[v.HeaderID]] = v.Value;
                            }
                        }
                        if (headerIndex.ContainsKey("TimeStamp"))
                        {
                            if (v.Value > 0)
                            {
                                headerValues[headerIndex["TimeStamp"]] = v.TimeStamp;
                            }
                        }
                    }

                }
                return cvResult.ToArray();

            }
            catch (Exception ex)
            {
            }
            return null;
        }
Beispiel #5
0
        public void Insert(K2DataObjects.CurveValue inCurveValue, bool allowUpdate)
        {
            try
            {

                using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
                {
                    var dbCurveVals =
                      (from cv in db.CurveValues
                       where cv.Mnemonic == inCurveValue.Mnemonic &&
                        cv.ItemType == inCurveValue.ItemType &&
                        cv.ItemSize == inCurveValue.ItemSize &&
                        cv.TimeStamp == inCurveValue.TimeStamp &&
                        cv.RequestID == inCurveValue.RequestID &&
                        cv.HeaderID == inCurveValue.HeaderID
                       select cv).SingleOrDefault();

                    if (dbCurveVals != null)
                    {
                        if (allowUpdate)
                        {
                            db.CurveValues.DeleteOnSubmit(dbCurveVals);
                            db.SubmitChanges();
                        }
                        else
                        {
                            throw new Exception("bar exists");
                        }
                    }
                    db.CurveValues.InsertOnSubmit(inCurveValue);

                    db.SubmitChanges();

                }

            }
            catch (Exception myE)
            {
                m_Log.Error("Insert", myE);
            }
        }
Beispiel #6
0
        public long GetLastCurveValueTimeTick(string mnemonic, long startTick)
        {
            try
            {

                using (K2DataObjects.DataContext db = new K2DataObjects.DataContext(_connectString))
                {
                    var curveValueSet =
                       (from cv in db.CurveValues
                        where (cv.Mnemonic == mnemonic) && (cv.TimeStamp >= startTick)
                        orderby cv.TimeStamp
                        select cv).LastOrDefault();

                    return curveValueSet.TimeStamp;
                }

            }
            catch (Exception ex)
            {
            }
            return 0;
        }