From 048c53585e240bff38c841e9e6f0cd64ea8018b4 Mon Sep 17 00:00:00 2001 From: Adalyat Nazirov Date: Fri, 12 Jul 2019 20:11:31 +0300 Subject: [PATCH] [Requested changes] - rename protected fields to follow coding style - rename iterface IOrderBook -> IOrderBookUpdater --- Brokerages/DefaultOrderBook.cs | 38 +++++++++++-------- .../{IOrderBook.cs => IOrderBookUpdater.cs} | 5 ++- Brokerages/QuantConnect.Brokerages.csproj | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) rename Brokerages/{IOrderBook.cs => IOrderBookUpdater.cs} (91%) diff --git a/Brokerages/DefaultOrderBook.cs b/Brokerages/DefaultOrderBook.cs index 3948da702e59..7519939edc3b 100644 --- a/Brokerages/DefaultOrderBook.cs +++ b/Brokerages/DefaultOrderBook.cs @@ -24,12 +24,20 @@ namespace QuantConnect.Brokerages /// It contains prices and order sizes for each bid and ask level. /// The best bid and ask prices are also kept up to date. /// - public class DefaultOrderBook : IOrderBook + public class DefaultOrderBook : IOrderBookUpdater { private readonly object _locker = new object(); private readonly Symbol _symbol; - protected readonly SortedDictionary _bids = new SortedDictionary(); - protected readonly SortedDictionary _asks = new SortedDictionary(); + + /// + /// Represents bid prices and sizes + /// + protected readonly SortedDictionary Bids = new SortedDictionary(); + + /// + /// Represents ask prices and sizes + /// + protected readonly SortedDictionary Asks = new SortedDictionary(); /// /// Event fired each time or are changed @@ -72,8 +80,8 @@ public void Clear() { lock (_locker) { - _bids.Clear(); - _asks.Clear(); + Bids.Clear(); + Asks.Clear(); } BestBidPrice = 0; @@ -91,7 +99,7 @@ public void UpdateBidRow(decimal price, decimal size) { lock (_locker) { - _bids[price] = size; + Bids[price] = size; } if (BestBidPrice == 0 || price >= BestBidPrice) @@ -112,7 +120,7 @@ public void UpdateAskRow(decimal price, decimal size) { lock (_locker) { - _asks[price] = size; + Asks[price] = size; } if (BestAskPrice == 0 || price <= BestAskPrice) @@ -132,15 +140,15 @@ public void RemoveBidRow(decimal price) { lock (_locker) { - _bids.Remove(price); + Bids.Remove(price); } if (price == BestBidPrice) { lock (_locker) { - BestBidPrice = _bids.Keys.LastOrDefault(); - BestBidSize = BestBidPrice > 0 ? _bids[BestBidPrice] : 0; + BestBidPrice = Bids.Keys.LastOrDefault(); + BestBidSize = BestBidPrice > 0 ? Bids[BestBidPrice] : 0; } BestBidAskUpdated?.Invoke(this, new BestBidAskUpdatedEventArgs(_symbol, BestBidPrice, BestBidSize, BestAskPrice, BestAskSize)); @@ -155,15 +163,15 @@ public void RemoveAskRow(decimal price) { lock (_locker) { - _asks.Remove(price); + Asks.Remove(price); } if (price == BestAskPrice) { lock (_locker) { - BestAskPrice = _asks.Keys.FirstOrDefault(); - BestAskSize = BestAskPrice > 0 ? _asks[BestAskPrice] : 0; + BestAskPrice = Asks.Keys.FirstOrDefault(); + BestAskSize = BestAskPrice > 0 ? Asks[BestAskPrice] : 0; } BestBidAskUpdated?.Invoke(this, new BestBidAskUpdatedEventArgs(_symbol, BestBidPrice, BestBidSize, BestAskPrice, BestAskSize)); @@ -176,11 +184,11 @@ public void RemoveAskRow(decimal price) /// public void RemovePriceLevel(decimal priceLevel) { - if (_asks.ContainsKey(priceLevel)) + if (Asks.ContainsKey(priceLevel)) { RemoveAskRow(priceLevel); } - else if (_bids.ContainsKey(priceLevel)) + else if (Bids.ContainsKey(priceLevel)) { RemoveBidRow(priceLevel); } diff --git a/Brokerages/IOrderBook.cs b/Brokerages/IOrderBookUpdater.cs similarity index 91% rename from Brokerages/IOrderBook.cs rename to Brokerages/IOrderBookUpdater.cs index c927baa3bc77..3c7992d195dc 100644 --- a/Brokerages/IOrderBook.cs +++ b/Brokerages/IOrderBookUpdater.cs @@ -20,11 +20,12 @@ namespace QuantConnect.Brokerages { /// - /// Represents an order book interface for a security. + /// Represents an orderbook updater interface for a security. + /// Provides the ability to update orderbook price level and to be alerted about updates /// /// Price level identifier /// Size at the price level - public interface IOrderBook + public interface IOrderBookUpdater { /// /// Event fired each time or are changed diff --git a/Brokerages/QuantConnect.Brokerages.csproj b/Brokerages/QuantConnect.Brokerages.csproj index cc4a3fceaa9e..7a5e93ecae16 100644 --- a/Brokerages/QuantConnect.Brokerages.csproj +++ b/Brokerages/QuantConnect.Brokerages.csproj @@ -276,7 +276,7 @@ - +