Esempio n. 1
0
        /// <summary>
        /// Returns a new NodesData with the nodes inside the range [start to end). See GetNodesWithNanos().
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public NodesData SliceSpawnWithNanos(long start, long end)
        {
            NodesData result = new NodesData();

            List <Node> nodes = GetNodesWithNanos(start, end);

            if (nodes.Count == 0)
            {
                throw new Exception("Returned zero nodes. Is that expected?");
            }


            if ((nodes[nodes.Count - 1].EndNano - nodes[0].StartNano) % NodeInterval != 0)
            {
                throw new Exception("NodeInterval won't divide cleanly into the difference between start and end.");
            }

            result.Start = nodes[0].StartNano;

            result.End = nodes[nodes.Count - 1].EndNano;

            result.NodeInterval = NodeInterval;

            result.Nodes = nodes;


            int checkCount = 0;

            for (int n = 0; n < nodes.Count; n++)
            {
                if (!nodes[n].TradePriceEstimated && result.FirstNonEstimatedTradePrice == -1)
                {
                    result.FirstNonEstimatedTradePrice = n;
                    checkCount++;
                }
                if (!nodes[n].BidPriceEstimated && result.FirstNonEstimatedBidPrice == -1)
                {
                    result.FirstNonEstimatedBidPrice = n;
                    checkCount++;
                }
                if (!nodes[n].AskPriceEstimated && result.FirstNonEstimatedAskPrice == -1)
                {
                    result.FirstNonEstimatedAskPrice = n;
                    checkCount++;
                }
                if (checkCount == 3)
                {
                    break;
                }
            }

            checkCount = 0;


            for (int n = nodes.Count - 1; n >= 0; n--)
            {
                if (!nodes[n].TradePriceEstimated && result.LastNonEstimatedTradePrice == -1)
                {
                    result.LastNonEstimatedTradePrice = n;
                    checkCount++;
                }
                if (!nodes[n].BidPriceEstimated && result.LastNonEstimatedBidPrice == -1)
                {
                    result.LastNonEstimatedBidPrice = n;
                    checkCount++;
                }
                if (!nodes[n].AskPriceEstimated && result.LastNonEstimatedAskPrice == -1)
                {
                    result.LastNonEstimatedAskPrice = n;
                    checkCount++;
                }
                if (checkCount == 3)
                {
                    break;
                }
            }



            return(result);
        }
Esempio n. 2
0
        /*
         * public int GetNodeIndexByStartNano(decimal start)
         * {
         *  int index = (int)((start - Start) / NodeInterval); // works perfectly if no gaps
         *
         *  decimal gapFactor = GetGapFactorByStartNano(start);
         *
         *  int indexAdjustment = (int)(gapFactor / NodeInterval);
         *
         *  index -= indexAdjustment;
         *
         *  return index;
         *
         * }
         *
         * public decimal GetGapFactorByStartNano(decimal start)
         * {
         *  decimal gapFactor = 0L;
         *
         *  // this could potentially be reversed?
         *  for (int n = 0; n < Gaps.Count; n++)
         *  {
         *      if (start >= Gaps[n].Start)
         *      {
         *          gapFactor = Gaps[n].Missing;
         *      }
         *      else
         *      {
         *          break;
         *      }
         *  }
         *
         *  return gapFactor;
         * }
         */

        public void AttachNodesData(NodesData attach)
        {
            DataMethods.AttachNodesData(attach, this);

            ComputeGaps();
        }