Exemplo n.º 1
0
        public static void ListToStruct(List <DepthItem> list, int dataCount, DepthTick tick)
        {
            int pos = 0;

            for (int i = 0; i < list.Count; ++i)
            {
                DepthItem currItem = list[i];

                switch (dataCount)
                {
                case 1:
                    SetDepthTick(tick, ++pos, currItem.Price);
                    break;

                case 2:
                    SetDepthTick(tick, ++pos, currItem.Price);
                    SetDepthTick(tick, ++pos, currItem.Size);
                    break;

                case 3:
                    SetDepthTick(tick, ++pos, currItem.Price);
                    SetDepthTick(tick, ++pos, currItem.Size);
                    SetDepthTick(tick, ++pos, currItem.Count);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void PriceMinusInOneList(List <DepthItem> oldList, List <DepthItem> newList)
        {
            newList.Clear();

            DepthItem prevItem = null;

            for (int i = 0; i < oldList.Count; ++i)
            {
                DepthItem currItem = oldList[i];
                // 这里为0的丢弃
                if (currItem.Size == 0)
                {
                    continue;
                }

                if (prevItem == null)
                {
                    newList.Add(currItem);
                }
                else
                {
                    newList.Add(new DepthItem(currItem.Price - prevItem.Price - 1, currItem.Size, currItem.Count));
                }

                prevItem = currItem;
            }
        }
Exemplo n.º 3
0
        public static void SizeMinusInTwoLists(List <DepthItem> oldPrevList, List <DepthItem> oldCurrList, List <DepthItem> newList)
        {
            if (oldPrevList.Count != oldCurrList.Count)
            {
            }

            newList.Clear();
            for (int i = 0; i < oldPrevList.Count; ++i)
            {
                DepthItem prevItem = oldPrevList[i];
                DepthItem currItem = oldCurrList[i];
                newList.Add(new DepthItem(currItem.Price, currItem.Size - prevItem.Size, currItem.Count - prevItem.Count));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 只处理价格是正确的数据
        /// 如何处理
        /// 只有卖价,0,即第一个位置就是卖一
        /// 只有买价,=list.count,比如说count=2,那买一价就是list.count-1=1
        /// 都没有,list.count=0;-1
        /// </summary>
        /// <param name="list"></param>
        /// <param name="AskPrice1"></param>
        /// <returns></returns>
        public static int FindAsk1Position(List <DepthItem> list, int AskPrice1)
        {
            if (list == null || list.Count == 0)
            {
                return(-1);
            }

            int i = 0;

            for (; i < list.Count; ++i)
            {
                DepthItem currItem = list[i];
                if (currItem.Price >= AskPrice1)
                {
                    break;
                }
            }
            return(i);
        }
Exemplo n.º 5
0
        public static void SizeAddInTwoLists(List <DepthItem> oldPrevList, List <DepthItem> oldCurrList, List <DepthItem> newList)
        {
            if (oldPrevList.Count != oldCurrList.Count)
            {
            }

            newList.Clear();
            for (int i = 0; i < oldPrevList.Count; ++i)
            {
                DepthItem prevItem = oldPrevList[i];
                DepthItem currItem = oldCurrList[i];
                // 为0的跳过,减少无效的显示
                int size = currItem.Size + prevItem.Size;
                if (size != 0)
                {
                    newList.Add(new DepthItem(currItem.Price, size, currItem.Count + prevItem.Count));
                }
            }
        }
Exemplo n.º 6
0
        public static void PriceAddInOneList(IEnumerable <DepthItem> oldList, List <DepthItem> newList)
        {
            newList.Clear();

            DepthItem prevItem = null;

            foreach (var currItem in oldList)
            {
                if (prevItem == null)
                {
                    prevItem = currItem;
                    newList.Add(currItem);
                }
                else
                {
                    prevItem = new DepthItem(currItem.Price + prevItem.Price + 1, currItem.Size, currItem.Count);
                    newList.Add(prevItem);
                }
            }
        }
Exemplo n.º 7
0
        public static void PriceAddInOneList(List <DepthItem> oldList, List <DepthItem> newList)
        {
            newList.Clear();

            DepthItem prevItem = null;

            for (int i = 0; i < oldList.Count; ++i)
            {
                DepthItem currItem = oldList[i];

                if (prevItem == null)
                {
                    prevItem = currItem;
                    newList.Add(currItem);
                }
                else
                {
                    prevItem = new DepthItem(currItem.Price + prevItem.Price + 1, currItem.Size, currItem.Count);
                    newList.Add(prevItem);
                }
            }
        }
Exemplo n.º 8
0
        public static void ExpandTwoListsToSameLength(List <DepthItem> oldPrevList, List <DepthItem> oldCurrList, int StartPrice, int EndPrice, List <DepthItem> newPrevList, List <DepthItem> newCurrList)
        {
            newPrevList.Clear();
            newCurrList.Clear();

            if (oldPrevList == null)
            {
                oldPrevList = new List <DepthItem>();
            }
            if (oldCurrList == null)
            {
                oldCurrList = new List <DepthItem>();
            }

            DepthItem prevItem = null;
            DepthItem currItem = null;

            // 从新一条记录开始算起
            int i = 0;
            int j = 0;

            for (; i < oldCurrList.Count; ++i)
            {
                currItem = oldCurrList[i];

                // 处理新列表中数据的范围
                if (currItem.Price < StartPrice)
                {
                    continue;
                }
                if (currItem.Price > EndPrice)
                {
                    break;
                }

                for (; j < oldPrevList.Count; ++j)
                {
                    prevItem = oldPrevList[j];


                    if (prevItem.Price < StartPrice)
                    {
                        continue;
                    }
                    // 条件是&&的原因是curr在范围内,而prev在范围外的情况会出现
                    if (prevItem.Price > EndPrice && currItem.Price > EndPrice)
                    {
                        break;
                    }

                    if (currItem.Price == prevItem.Price)
                    {
                        // 两边都有,直接两边都复制
                        newPrevList.Add(prevItem);
                        newCurrList.Add(currItem);

                        // 这样将两个指针都向后移动
                        ++j;
                        break;
                    }
                    else if (currItem.Price < prevItem.Price)
                    {
                        // 新序列的价格小,按新的复制,然后将新的指针向后移动
                        newCurrList.Add(currItem);
                        newPrevList.Add(new DepthItem()
                        {
                            Price = currItem.Price
                        });
                        break;
                    }
                    else
                    {
                        // 老的价格小,按老的复制,然后继续遍历老序列
                        newPrevList.Add(prevItem);
                        newCurrList.Add(new DepthItem()
                        {
                            Price = prevItem.Price
                        });
                    }
                }

                // 历史的已经刷完,当前的还有
                if (j == oldPrevList.Count)
                {
                    if (currItem.Price > EndPrice)
                    {
                        break;
                    }

                    // 只有新数据,没有老数据的情况
                    if (prevItem == null || currItem.Price > prevItem.Price)
                    {
                        newCurrList.Add(currItem);
                        newPrevList.Add(new DepthItem()
                        {
                            Price = currItem.Price
                        });
                    }
                }
            }
            // 当前的已经刷完,去刷历史了
            for (; j < oldPrevList.Count; ++j)
            {
                prevItem = oldPrevList[j];

                // 只有历史没有最新
                if (prevItem.Price < StartPrice)
                {
                    continue;
                }
                if (prevItem.Price > EndPrice)
                {
                    break;
                }

                newPrevList.Add(prevItem);
                newCurrList.Add(new DepthItem()
                {
                    Price = prevItem.Price
                });
            }
        }
Exemplo n.º 9
0
        public static void StructToList(DepthTick tick, int dataCount, List <DepthItem> list)
        {
            list.Clear();

            DepthTick from_next = tick;

            DepthItem item = null;
            int       pos  = 0;

            while (from_next != null)
            {
                for (int i = 1; i <= 14; ++i)
                {
                    ++pos;
                    if (dataCount == 3)
                    {
                        switch (pos % dataCount)
                        {
                        case 1:
                            item       = new DepthItem();
                            item.Price = GetDepthTick14(from_next, i);
                            break;

                        case 2:
                            item.Size = GetDepthTick14(from_next, i);
                            break;

                        case 0:
                            item.Count = GetDepthTick14(from_next, i);
                            list.Add(item);
                            break;
                        }
                    }
                    else if (dataCount == 2)
                    {
                        switch (pos % dataCount)
                        {
                        case 1:
                            item       = new DepthItem();
                            item.Price = GetDepthTick14(from_next, i);
                            break;

                        case 0:
                            item.Size = GetDepthTick14(from_next, i);
                            list.Add(item);
                            break;
                        }
                    }
                    else if (dataCount == 1)
                    {
                        switch (pos % dataCount)
                        {
                        case 0:
                            item       = new DepthItem();
                            item.Price = GetDepthTick14(from_next, i);
                            list.Add(item);
                            break;
                        }
                    }
                }

                // 指向下一个可用数据
                from_next = from_next.Next;
            }

            // 由于上面结构的特点,最后会有些数据为空的内容加入,要删去
            for (int j = list.Count - 1; j >= 0; --j)
            {
                if (list[j].IsZero)
                {
                    list.RemoveAt(j);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 10
0
        public static void StructToList(DepthTick tick, int dataCount, List<DepthItem> list)
        {
            list.Clear();

            DepthTick from_next = tick;

            DepthItem item = null;
            int pos = 0;

            while (from_next != null)
            {
                for (int i = 1; i <= 14; ++i)
                {
                    ++pos;
                    if (dataCount == 3)
                    {
                        switch (pos % dataCount)
                        {
                            case 1:
                                item = new DepthItem();
                                item.Price = GetDepthTick14(from_next, i);
                                break;
                            case 2:
                                item.Size = GetDepthTick14(from_next, i);
                                break;
                            case 0:
                                item.Count = GetDepthTick14(from_next, i);
                                list.Add(item);
                                break;
                        }
                    }
                    else if (dataCount == 2)
                    {
                        switch (pos % dataCount)
                        {
                            case 1:
                                item = new DepthItem();
                                item.Price = GetDepthTick14(from_next, i);
                                break;
                            case 0:
                                item.Size = GetDepthTick14(from_next, i);
                                list.Add(item);
                                break;
                        }
                    }
                    else if (dataCount == 1)
                    {
                        switch (pos % dataCount)
                        {
                            case 0:
                                item = new DepthItem();
                                item.Price = GetDepthTick14(from_next, i);
                                list.Add(item);
                                break;
                        }
                    }
                }

                // 指向下一个可用数据
                from_next = from_next.Next;
            }

            // 由于上面结构的特点,最后会有些数据为空的内容加入,要删去
            for (int j = list.Count - 1; j >= 0; --j)
            {
                if (list[j].IsZero)
                {
                    list.RemoveAt(j);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 11
0
        public static void PriceAddInOneList(List<DepthItem> oldList, List<DepthItem> newList)
        {
            newList.Clear();

            DepthItem prevItem = null;

            for (int i = 0; i < oldList.Count; ++i)
            {
                DepthItem currItem = oldList[i];

                if (prevItem == null)
                {
                    prevItem = currItem;
                    newList.Add(currItem);
                }
                else
                {
                    prevItem = new DepthItem(currItem.Price + prevItem.Price + 1, currItem.Size, currItem.Count);
                    newList.Add(prevItem);
                }
            }
        }