private static long StreamLevels(string pair, OrderBookSourceMock source, ICryptoOrderBook book, int iterations, int maxBidPrice, int maxAskPrice, bool slowDown = false) { var bid = book.BidLevels[0]; var ask = book.AskLevels[0]; var sw = new Stopwatch(); var iterationsSafe = iterations * 13; for (int i = 0; i < iterationsSafe; i += 13) { var newBidPrice = i % maxBidPrice; var newAskPrice = maxBidPrice + (i % maxAskPrice); // update levels var bulk = GetUpdateBulkL2( CreateLevel(pair, newBidPrice, CryptoOrderSide.Bid, bid.Id), CreateLevel(pair, newAskPrice, CryptoOrderSide.Ask, ask.Id) ); sw.Start(); source.StreamBulk(bulk); sw.Stop(); if (slowDown && i % 1000 == 0) { Thread.Sleep(10); } } return(sw.ElapsedMilliseconds); }
private static void HandleQuoteChanged(ICryptoOrderBook ob) { var bids = ob.BidLevels.Take(10).ToArray(); var asks = ob.AskLevels.Take(10).ToArray(); var max = Math.Max(bids.Length, asks.Length); var msg = string.Empty; for (int i = 0; i < max; i++) { var bid = bids.Length > i ? bids[i] : null; var ask = asks.Length > i ? asks[i] : null; var bidMsg = bid != null ? $"#{i+1} " + $"{"p: " + (bid?.Price ?? 0).ToString("#.00##") + " a: " + (bid?.Amount ?? 0).ToString("0.00#")} " + $"[{bid.AmountUpdatedCount}]" : " "; var askMsg = ask != null ? $"#{i+1} " + $"{"p: " + (ask?.Price ?? 0).ToString("#.00##") + " a: " + (ask?.Amount ?? 0).ToString("0.00#")} " + $"[{ask.AmountUpdatedCount}]" : " "; bidMsg = $"{bidMsg,50}"; askMsg = $"{askMsg,50}"; msg+= $"{Environment.NewLine}{bidMsg} {askMsg}"; } Log.Information($"ORDER BOOK {ob.ExchangeName} {ob.TargetPairOriginal}: {msg}{Environment.NewLine}"); }
private static void ConfigureOptimized(IOrderBookSource source, ICryptoOrderBook orderBook) { source.BufferEnabled = true; source.BufferInterval = TimeSpan.FromMilliseconds(0); orderBook.DebugEnabled = false; orderBook.DebugLogEnabled = false; orderBook.ValidityCheckEnabled = false; }