to make it it easy I took a code snippet of a reference sample which builds a list of market depth and populates or updates that list.
protected override void OnMarketDepth(MarketDepthEventArgs e)
{
lock (e.Instrument.SyncMarketDepth)
{
List<LadderRow> rows = (e.MarketDataType == MarketDataType.Ask ? askRows: bidRows);
LadderRow row = new LadderRow { MarketMaker = e.MarketMaker, Price = e.Price, Volume = e.Volume };
if (e.Operation == Operation.Add || (e.Operation == Operation.Update && (rows.Count == 0 || rows.Count <= e.Position)))
{
if (rows.Count <= e.Position)
rows.Add(row);
else
rows.Insert(e.Position, row);
}
else if (e.Operation == Operation.Remove && rows.Count >= e.Position)
{
rows.RemoveAt(e.Position);
}
else if (e.Operation == Operation.Update)
{
if (rows[e.Position] == null)
{
rows[e.Position] = row;
}
else
{
rows[e.Position].Price = e.Price;
rows[e.Position].Volume = e.Volume;
}
}
}
}
Question is:
How can I modify the above or a overall comparable code to only store and or update a limited amount of depth rows e.g. 10 bid and ask depth rows.
I tried different ways, but cannot get the desired outcome.
Regards and thanks in advance.
Comment