public void Ask_Heap_Latency() { const int size = 1024 * 1024; var arr1 = new Quote[128 * 1024]; Populate(arr1); var arr2 = new Quote[(1024 - 129) * 1024 - 1]; Populate(arr2); var arr3 = new Quote[1025]; Populate(arr3); var quote1 = new Quote(0.5m, 1, Guid.NewGuid().ToString(), 1, null, 1); var quote2 = new Quote(0.6m, 1, Guid.NewGuid().ToString(), 1, null, 1); var quote3 = new Quote(0.7m, 1, Guid.NewGuid().ToString(), 1, null, 1); var fullArray = new Quote[size + 3]; Array.Copy(arr1, 0, fullArray, 0, arr1.Length); Array.Copy(arr2, 0, fullArray, arr1.Length, arr2.Length); Array.Copy(arr3, 0, fullArray, arr1.Length + arr2.Length, arr3.Length); fullArray[fullArray.Length - 3] = quote1; fullArray[fullArray.Length - 2] = quote2; fullArray[fullArray.Length - 1] = quote3; fullArray = fullArray.OrderBy(x => x.QuotePrice).ToArray(); var heaps = new[] { CreateMinHeap(arr1, 0), CreateMinHeap(arr2, 1), CreateMinHeap(arr3, 2) }; var askHeap = new AskHeap(heaps); heaps[0].InsertVal(quote1); heaps[1].InsertVal(quote2); heaps[2].InsertVal(quote3); var position = new BuyPosition(fullArray.Sum(x => x.QuotePrice)); var sw = Stopwatch.StartNew(); Parallel.For(0, 1, i => { var cnt = 0; do { position.LastSize = 0; askHeap.FindSizeAndPrice(position); Assert.True(fullArray[cnt].QuotePrice.Equals(position.LastPrice)); } while (++cnt < fullArray.Length); position.LastSize = 0; askHeap.FindSizeAndPrice(position); Assert.True(position.LastSize.Equals(0)); }); sw.Stop(); Console.Out.WriteLine($"AskHeap Extract Time:{sw.Elapsed.TotalMilliseconds}"); }
public TraderGroup(CryptoCurrency currency, IExchange[] xchgs) { _askHeap = new AskHeap(xchgs.Select(x => x.AskHeap(currency)).ToList()); _bidHeap = new BidHeap(xchgs.Select(x => x.BidHeap(currency)).ToList()); }