public static int GetDepthTick(DepthTick tick, int pos) { DepthTick from_next = tick; while (pos > 0) { if (from_next == null) { return(0); } if (pos <= 14) { return(GetDepthTick14(from_next, pos)); } pos -= 14; if (pos > 0) { if (from_next.Next == null) { return(0); } from_next = from_next.Next; } } return(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; } } }
public static void ListToStruct(IEnumerable <DepthItem> list, int dataCount, DepthTick tick) { var pos = 0; foreach (var currItem in list) { 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; } } }
public static void SetDepthTick(DepthTick tick, int pos, int value) { DepthTick from_next = tick; while (pos > 0) { if (from_next == null) { return; } if (pos <= 14) { SetDepthTick14(from_next, pos, value); } pos -= 14; if (pos > 0) { if (from_next.Next == null) { from_next.Next = new DepthTick(); } from_next = from_next.Next; } } }
public static int GetDepthTick14(DepthTick tick, int pos) { DepthTick from_next = tick; switch (pos) { case 1: return(from_next.Value1); case 2: return(from_next.Value2); case 3: return(from_next.Value3); case 4: return(from_next.Value4); case 5: return(from_next.Value5); case 6: return(from_next.Value6); case 7: return(from_next.Value7); case 8: return(from_next.Value8); case 9: return(from_next.Value9); case 10: return(from_next.Value10); case 11: return(from_next.Value11); case 12: return(from_next.Value12); case 13: return(from_next.Value13); case 14: return(from_next.Value14); } return(0); }
/// <summary> /// 将列表中的数据平铺到结构体中 /// 只在保存到文件时操作,其它时候都不要调用 /// 以后用户要使用数据时直接操作列表即可 /// </summary> public void PrepareObjectBeforeWrite(ConfigInfo _Config) { if (DepthList == null || DepthList.Count == 0) { Depth = null; return; } List <DepthItem> tempList = new List <DepthItem>(); DepthListHelper.PriceMinusInOneList(DepthList, tempList); // 还是使用新的,因为不知道以前是否已经有数据,导致混淆 Depth = new DepthTick(); //if(tempList.Count>0) // tempList[0].Price = LastPrice - tempList[0].Price; DepthListHelper.ListToStruct(tempList, _Config.MarketType, Depth); }
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; } } }
public static void SetDepthTick14(DepthTick tick, int pos, int value) { DepthTick from_next = tick; switch (pos) { case 1: from_next.Value1 = value; break; case 2: from_next.Value2 = value; break; case 3: from_next.Value3 = value; break; case 4: from_next.Value4 = value; break; case 5: from_next.Value5 = value; break; case 6: from_next.Value6 = value; break; case 7: from_next.Value7 = value; break; case 8: from_next.Value8 = value; break; case 9: from_next.Value9 = value; break; case 10: from_next.Value10 = value; break; case 11: from_next.Value11 = value; break; case 12: from_next.Value12 = value; break; case 13: from_next.Value13 = value; break; case 14: from_next.Value14 = value; break; } }
/// <summary> /// 将列表中的数据平铺到结构体中 /// 只在保存到文件时操作,其它时候都不要调用 /// 以后用户要使用数据时直接操作列表即可 /// </summary> public void PrepareObjectBeforeWrite(ConfigInfo _Config) { if (DepthList == null || DepthList.Count == 0) { Depth = null; return; } List<DepthItem> tempList = new List<DepthItem>(); DepthListHelper.PriceMinusInOneList(DepthList, tempList); // 还是使用新的,因为不知道以前是否已经有数据,导致混淆 Depth = new DepthTick(); //if(tempList.Count>0) // tempList[0].Price = LastPrice - tempList[0].Price; DepthListHelper.ListToStruct(tempList, _Config.MarketType, Depth); }
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; } } }
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; } } }
public static int GetDepthTick(DepthTick tick, int pos) { DepthTick from_next = tick; while (pos > 0) { if (from_next == null) return 0; if (pos <= 14) { return GetDepthTick14(from_next, pos); } pos -= 14; if (pos > 0) { if (from_next.Next == null) return 0; from_next = from_next.Next; } } return 0; }
public static void SetDepthTick(DepthTick tick, int pos, int value) { DepthTick from_next = tick; while (pos > 0) { if (from_next == null) return; if (pos <= 14) { SetDepthTick14(from_next, pos, value); } pos -= 14; if (pos > 0) { if (from_next.Next == null) from_next.Next = new DepthTick(); from_next = from_next.Next; } } }
public static int GetDepthTick14(DepthTick tick, int pos) { DepthTick from_next = tick; switch (pos) { case 1: return from_next.Value1; case 2: return from_next.Value2; case 3: return from_next.Value3; case 4: return from_next.Value4; case 5: return from_next.Value5; case 6: return from_next.Value6; case 7: return from_next.Value7; case 8: return from_next.Value8; case 9: return from_next.Value9; case 10: return from_next.Value10; case 11: return from_next.Value11; case 12: return from_next.Value12; case 13: return from_next.Value13; case 14: return from_next.Value14; } return 0; }
static void Main(string[] args) { List<DepthItem> oldPrevList = new List<DepthItem>(); List<DepthItem> oldCurrList = new List<DepthItem>(); List<DepthItem> newPrevList = new List<DepthItem>(); List<DepthItem> newCurrList = new List<DepthItem>(); DepthListHelper test = new DepthListHelper(); // 处理老的多一条 oldPrevList.Add(new DepthItem(1, 100, 0)); oldPrevList.Add(new DepthItem(7, 100, 0)); oldPrevList.Add(new DepthItem(12, 100, 0)); int j11 = DepthListHelper.FindAsk1Position(oldPrevList, 0); int j12 = DepthListHelper.FindAsk1Position(oldPrevList, 1); int j13 = DepthListHelper.FindAsk1Position(oldPrevList, 12); int j14 = DepthListHelper.FindAsk1Position(oldPrevList, 15); List<DepthItemView> oldPrevListV = new List<DepthItemView>(); oldPrevListV.Add(new DepthItemView() { Price = 10}); oldPrevListV.Add(new DepthItemView() { Price = 5 }); oldPrevListV.Add(new DepthItemView() { Price = 1 }); int j21 = DepthListHelper.FindAsk1PositionDescending(oldPrevListV, 12); int j22 = DepthListHelper.FindAsk1PositionDescending(oldPrevListV, 10); int j23 = DepthListHelper.FindAsk1PositionDescending(oldPrevListV, 1); int j24 = DepthListHelper.FindAsk1PositionDescending(oldPrevListV, 0); //oldCurrList.Add(new DepthItem(5, 100, 0)); //oldCurrList.Add(new DepthItem(8, 100, 0)); //oldCurrList.Add(new DepthItem(13, 100, 0)); DepthListHelper.ExpandTwoListsToSameLength(oldPrevList, oldCurrList, 5, 13, newPrevList, newCurrList); List<DepthItem> newList = new List<DepthItem>(); DepthListHelper.SizeMinusInTwoLists(newPrevList, newCurrList, newList); List<DepthItem> newList2 = new List<DepthItem>(); DepthListHelper.SizeAddInTwoLists(newPrevList, newList, newList2); List<DepthItem> newList3 = new List<DepthItem>(); DepthListHelper.PriceMinusInOneList(newList2, newList3); List<DepthItem> newList4 = new List<DepthItem>(); DepthListHelper.PriceAddInOneList(newList3, newList4); DepthTick tick = new DepthTick(); DepthListHelper.SetDepthTick(tick, 4, 100); DepthListHelper.SetDepthTick(tick, 10, 200); DepthListHelper.SetDepthTick(tick, 15, 300); DepthListHelper.SetDepthTick(tick, 28, 400); DepthListHelper.SetDepthTick(tick, 30, 500); int i1 = DepthListHelper.GetDepthTick(tick, 4); int i2 = DepthListHelper.GetDepthTick(tick, 10); int i3 = DepthListHelper.GetDepthTick(tick, 15); int i4 = DepthListHelper.GetDepthTick(tick, 28); int i5 = DepthListHelper.GetDepthTick(tick, 30); int i6 = DepthListHelper.GetDepthTick(tick, 45); DepthTick tick2 = new DepthTick(); DepthListHelper.ListToStruct(newPrevList, 2, tick2); List<DepthItem> newList5 = new List<DepthItem>(); DepthListHelper.StructToList(tick2, 2, newList5); //int j1 = test.FindAsk1Position(oldCurrList, 5); //int j2 = test.FindAsk1Position(oldCurrList, 8); //int j3 = test.FindAsk1Position(oldCurrList, 12); //int j4 = test.FindAsk1Position(oldCurrList, 13); //int j5 = test.FindAsk1Position(oldCurrList, 14); //int j6 = test.FindAsk1Position(oldCurrList, 15); //int j7 = test.FindAsk1Position(oldCurrList, 4); //int j8 = test.FindAsk1Position(oldCurrList, 7); //oldPrevList = new List<DepthItem>(); //oldPrevList.Add(new DepthItem(3, 100, 0)); //oldPrevList.Add(new DepthItem(7, 100, 0)); //oldPrevList.Add(new DepthItem(12, 100, 0)); //int x1 = test.FindAsk1Position(oldPrevList, 3); //int x2 = test.FindAsk1Position(oldPrevList, 7); //int x3 = test.FindAsk1Position(oldPrevList, 12); //int x4 = test.FindAsk1Position(oldPrevList, 5); //int x5 = test.FindAsk1Position(oldPrevList, 13); //int x6 = test.FindAsk1Position(oldPrevList, 2); // 处理新的多一条 //oldPrevList.Add(new DepthItem(1, 100, 0)); //oldCurrList.Add(new DepthItem(1, 100, 0)); //oldCurrList.Add(new DepthItem(5, 100, 0)); //test.Do(oldPrevList, oldCurrList, newPrevList, newCurrList); //test. }