using System; using System.Threading; using System.Threading.Tasks; using CryptoExchange.Net.Objects; namespace CryptoExchange.Net.Interfaces { /// /// Interface for order book /// public interface ISymbolOrderBook { /// /// The exchange the book is for /// string Exchange { get; } /// /// The Api the book is for /// string Api { get; } /// /// The status of the order book. Order book is up to date when the status is `Synced` /// OrderBookStatus Status { get; set; } /// /// Last update identifier /// long LastSequenceNumber { get; } /// /// The symbol of the order book /// string Symbol { get; } /// /// Event when the state changes /// event Action OnStatusChange; /// /// Event when order book was updated. Be careful! It can generate a lot of events at high-liquidity markets /// event Action<(ISymbolOrderBookEntry[] Bids, ISymbolOrderBookEntry[] Asks)> OnOrderBookUpdate; /// /// Event when the BestBid or BestAsk changes ie a Pricing Tick /// event Action<(ISymbolOrderBookEntry BestBid, ISymbolOrderBookEntry BestAsk)> OnBestOffersChanged; /// /// Timestamp of when the last update was applied to the book, local time /// DateTime UpdateTime { get; } /// /// Timestamp of the last event that was applied, server time /// DateTime? UpdateServerTime { get; } /// /// Timestamp of the last event that was applied, in local time, estimated based on timestamp difference between client and server /// DateTime? UpdateLocalTime { get; } /// /// Age of the data, in local time, estimated based on timestamp difference between client and server + the period since last update /// TimeSpan? DataAge { get; } /// /// The number of asks in the book /// int AskCount { get; } /// /// The number of bids in the book /// int BidCount { get; } /// /// Get a snapshot of the book at this moment /// (ISymbolOrderBookEntry[] bids, ISymbolOrderBookEntry[] asks) Book { get; } /// /// The list of asks /// ISymbolOrderBookEntry[] Asks { get; } /// /// The list of bids /// ISymbolOrderBookEntry[] Bids { get; } /// /// The best bid currently in the order book /// ISymbolOrderBookEntry BestBid { get; } /// /// The best ask currently in the order book /// ISymbolOrderBookEntry BestAsk { get; } /// /// BestBid/BesAsk returned as a pair /// (ISymbolOrderBookEntry Bid, ISymbolOrderBookEntry Ask) BestOffers { get; } /// /// Start connecting and synchronizing the order book /// /// A cancellation token to stop the order book when canceled /// Task StartAsync(CancellationToken? ct = null); /// /// Stop syncing the order book /// /// Task StopAsync(); /// /// Get the average price that a market order would fill at at the current order book state. This is no guarantee that an order of that quantity would actually be filled /// at that price since between this calculation and the order placement the book might have changed. /// /// The quantity in base asset to fill /// The type /// Average fill price CallResult CalculateAverageFillPrice(decimal quantity, OrderBookEntryType type); /// /// Get the amount of base asset which can be traded with the quote quantity when placing a market order at at the current order book state. /// This is no guarantee that an order of that quantity would actually be fill the quantity returned by this since between this calculation and the order placement the book might have changed. /// /// The quantity in quote asset looking to trade /// The type /// Amount of base asset tradable with the specified amount of quote asset CallResult CalculateTradableAmount(decimal quoteQuantity, OrderBookEntryType type); /// /// String representation of the top x entries /// /// string ToString(int rows); /// /// Output the orderbook to the console /// /// Number of rows to display /// Refresh interval /// Cancellation token Task OutputToConsoleAsync(int numberOfEntries, TimeSpan refreshInterval, CancellationToken ct = default); } }