Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa55ce4

Browse files
committed
支持逆序功能
1 parent 1f58c83 commit fa55ce4

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

QuantBox.Data.Serializer/V2/Int2DoubleConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public PbTickView Int2Double(PbTick tick, bool descending)
138138
view.Split = Int2Double(tick.Split);
139139
view.LocalTime_Msec = tick.LocalTime_Msec;
140140
view.DepthList = Int2Double(tick.DepthList, descending);
141-
view.LoadQuote();
141+
view.LoadQuote(descending);
142142
return view;
143143
}
144144
}

QuantBox.Data.Serializer/V2/PbTickView.cs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PbTickView
2424
public DepthItemView Bid1 { get; set; }
2525
public int AskPos { get; set; }
2626
public int BidPos { get; set; }
27+
public bool descending { get; set; }
2728

2829
/// <summary>
2930
/// 成交量
@@ -70,30 +71,65 @@ public override string ToString()
7071
return LastPrice.ToString(CultureInfo.InvariantCulture);
7172
}
7273

73-
public void LoadQuote()
74+
public void LoadQuote(bool descending)
7475
{
75-
AskPos = DepthListHelper.FindAsk1Position(DepthList, AskPrice1);
76-
BidPos = AskPos - 1;
77-
Ask1 = GetAsk(0);
78-
Bid1 = GetBid(0);
76+
this.descending = descending;
77+
if(descending)
78+
{
79+
AskPos = DepthListHelper.FindAsk1PositionDescending(DepthList, AskPrice1);
80+
BidPos = AskPos + 1;
81+
Ask1 = GetAsk(1);
82+
Bid1 = GetBid(1);
83+
}
84+
else
85+
{
86+
AskPos = DepthListHelper.FindAsk1Position(DepthList, AskPrice1);
87+
BidPos = AskPos - 1;
88+
Ask1 = GetAsk(1);
89+
Bid1 = GetBid(1);
90+
}
7991
}
8092

8193
public DepthItemView GetBid(int level)
8294
{
8395
if (level > 0) {
84-
var pos = BidPos - (level - 1);
85-
if (pos >= 0) {
86-
return DepthList[pos];
96+
if(descending)
97+
{
98+
var pos = BidPos + (level - 1);
99+
if (pos <= DepthList.Count - 1)
100+
{
101+
return DepthList[pos];
102+
}
87103
}
104+
else
105+
{
106+
var pos = BidPos - (level - 1);
107+
if (pos >= 0)
108+
{
109+
return DepthList[pos];
110+
}
111+
}
112+
88113
}
89114
return null;
90115
}
91116
public DepthItemView GetAsk(int level)
92117
{
93118
if (level > 0) {
94-
var pos = AskPos + (level - 1);
95-
if (pos <= DepthList.Count - 1) {
96-
return DepthList[pos];
119+
if (descending)
120+
{
121+
var pos = AskPos - (level - 1);
122+
if (pos >= 0)
123+
{
124+
return DepthList[pos];
125+
}
126+
}
127+
else
128+
{
129+
var pos = AskPos + (level - 1);
130+
if (pos <= DepthList.Count - 1) {
131+
return DepthList[pos];
132+
}
97133
}
98134
}
99135
return null;

0 commit comments

Comments
 (0)