OrderBook

StockSharp.MatchingEngine

Order book implementation.

Implements: IOrderBook

Constructors

OrderBook
public OrderBook(SecurityId securityId)
orderBook = OrderBook(securityId)

Order book implementation.

Properties

AskLevels
public int AskLevels { get; }
value = orderBook.AskLevels

Number of ask levels.

BestAsk
public ValueTuple<decimal, decimal>? BestAsk { get; }
value = orderBook.BestAsk

Get best ask price and volume.

BestBid
public ValueTuple<decimal, decimal>? BestBid { get; }
value = orderBook.BestBid

Get best bid price and volume.

BidLevels
public int BidLevels { get; }
value = orderBook.BidLevels

Number of bid levels.

SecurityId
public SecurityId SecurityId { get; }
value = orderBook.SecurityId

Security ID.

TotalAskVolume
public decimal TotalAskVolume { get; }
value = orderBook.TotalAskVolume

Total volume of all asks.

TotalBidVolume
public decimal TotalBidVolume { get; }
value = orderBook.TotalBidVolume

Total volume of all bids.

Methods

AddQuote
public void AddQuote(EmulatorOrder order)
orderBook.AddQuote(order)

Add a quote to the order book.

order
Order or market quote to add. If TransactionId is default, it is treated as a market quote.
Clear
public void Clear(Sides side)
orderBook.Clear(side)

Clear all quotes for a specific side.

side
Side to clear.
Clear
public void Clear()
orderBook.Clear()

Clear all quotes.

ConsumeVolume
public IEnumerable<ValueTuple<decimal, decimal, IReadOnlyList<MatchFill>>> ConsumeVolume(Sides side, decimal? maxPrice, decimal volume)
result = orderBook.ConsumeVolume(side, maxPrice, volume)

Consume volume from best levels (for matching).

side
Side to consume from (opposite to order side).
maxPrice
Maximum price for buy / minimum for sell.
volume
Volume to consume.

Returns: Executions (price, volume, volume taken from each resting order).

GetLevels
public IEnumerable<OrderBookLevel> GetLevels(Sides side)
result = orderBook.GetLevels(side)

Get quotes for a side, ordered by price (best first).

side
Side to retrieve levels for.
GetOrdersAtPrice
public IEnumerable<EmulatorOrder> GetOrdersAtPrice(Sides side, decimal price)
result = orderBook.GetOrdersAtPrice(side, price)

Get all user orders at a specific price level.

side
Side to query.
price
Price level to query.
GetTotalVolume
public decimal GetTotalVolume(Sides side)
result = orderBook.GetTotalVolume(side)

Get total volume for a side.

side
Side to get total volume for.
GetVolumeAtPrice
public decimal GetVolumeAtPrice(Sides side, decimal price)
result = orderBook.GetVolumeAtPrice(side, price)

Get volume at a specific price level.

side
Side to query.
price
Price level to query.
GetWorstAsk
public ValueTuple<decimal, decimal>? GetWorstAsk()
result = orderBook.GetWorstAsk()

Get worst (highest) ask level.

GetWorstBid
public ValueTuple<decimal, decimal>? GetWorstBid()
result = orderBook.GetWorstBid()

Get worst (lowest) bid level.

HasLevel
public bool HasLevel(Sides side, decimal price)
result = orderBook.HasLevel(side, price)

Check if there's a quote at the specified price.

side
Side to check.
price
Price level to check.
RemoveLevel
public IEnumerable<EmulatorOrder> RemoveLevel(Sides side, decimal price)
result = orderBook.RemoveLevel(side, price)

Remove entire level at price.

side
Side to remove level from.
price
Price level to remove.

Returns: Removed orders that were present at that level.

RemoveQuote
public bool RemoveQuote(long transactionId, Sides side, decimal price)
result = orderBook.RemoveQuote(transactionId, side, price)

Remove a quote from the order book.

transactionId
Transaction id of the order to remove.
side
Side (buy/sell) where the order is placed.
price
Price level of the order.

Returns: True if removed, false if not found.

SetSnapshot
public void SetSnapshot(IEnumerable<QuoteChange> bids, IEnumerable<QuoteChange> asks)
orderBook.SetSnapshot(bids, asks)

Set the order book from a snapshot (replaces all non-user quotes).

bids
Sequence of bid quote changes to set.
asks
Sequence of ask quote changes to set.
ToMessage
public QuoteChangeMessage ToMessage(DateTime localTime, DateTime serverTime)
result = orderBook.ToMessage(localTime, serverTime)

Create a QuoteChangeMessage from current state.

localTime
Local time to set on the generated message.
serverTime
Server time to set on the generated message.
TryRemoveOrder
public bool TryRemoveOrder(long transactionId, Sides side, EmulatorOrder order)
result = orderBook.TryRemoveOrder(transactionId, side, order)

Find and remove order by transaction ID from any level.

UpdateLevel
public void UpdateLevel(Sides side, decimal price, decimal volume)
orderBook.UpdateLevel(side, price, volume)

Update volume at a price level (for market quotes).

side
Side to update.
price
Price level to update.
volume
New market volume at the level.