I am having a somewhat brain blackout (weather is sh1t or I am just dumb - not sure)...
I know there are bunch of prominent programmers here.
And I am guessing that most of them already did that. So if it is not too big a secret, would you guys please offer an algorithm for bid/ask levels keeping..
and by that I mean:
I want to keep n levels. I want an array (or whatever 2D structure) where 1st column is price and the 2nd is some data object (doesnt matter here).
lets reduce the task by making bids work (cos asks can be mirrored if a right solution found for the bids).
so its like
bids[0] =
bids[1] =
bids[2] =
...
bids[n-1] =
so there are 2 important keys - prices itself (lets call it level) and index.
the array must be sorted (so the best bid has index == 0)
bids are coming randomly.
the number of levels is fixed (this is important part), so if there are less levels than N the array item should look like bids[x] = , if there are more levels the lower (higher for asks) price levels must be ignored.
bid with size == 0 cancels a level (the only way to know that this particular level is not going to be reported - time to make it )
there can be gaps in levels. even if price can be legitimately 100.05 in this examply but the level is missing simply because there are no bids at that level at the moment, so the empty level must not be in the array.
ticks are coming as objects, something like:
I need a rough algorithm - how you guys will go about it. Any language/pseudocode is OK (except Hindu please :))
void OnTick(Tick tick)
{
if(tick.Type == TickType.Bid)
{
// your code goes here
}
}
P.S. this will be implemented in C# so the challenge here is to make it efficient from .NET collections/array manipulation stands point.