mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Order book logging
This commit is contained in:
parent
8ddd9ecf22
commit
af3303c7b8
@ -13,13 +13,13 @@ namespace CryptoExchange.Net.Logging.Extensions
|
|||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookStopped;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookStopped;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookConnectionLost;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookConnectionLost;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookDisconnected;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookDisconnected;
|
||||||
private static readonly Action<ILogger, string, int, Exception?> _orderBookProcessingBufferedUpdates;
|
private static readonly Action<ILogger, string, string, int, Exception?> _orderBookProcessingBufferedUpdates;
|
||||||
private static readonly Action<ILogger, string, string, long, long, Exception?> _orderBookUpdateSkipped;
|
private static readonly Action<ILogger, string, string, long, long, Exception?> _orderBookUpdateSkipped;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookOutOfSyncChecksum;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookOutOfSyncChecksum;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookResyncFailed;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookResyncFailed;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookResyncing;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookResyncing;
|
||||||
private static readonly Action<ILogger, string, string, Exception?> _orderBookResynced;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookResynced;
|
||||||
private static readonly Action<ILogger, string, Exception?> _orderBookMessageSkippedBecauseOfResubscribing;
|
private static readonly Action<ILogger, string, string, Exception?> _orderBookMessageSkippedBecauseOfResubscribing;
|
||||||
private static readonly Action<ILogger, string, string, long, long, long, Exception?> _orderBookDataSet;
|
private static readonly Action<ILogger, string, string, long, long, long, Exception?> _orderBookDataSet;
|
||||||
private static readonly Action<ILogger, string, string, long, long, long, long, Exception?> _orderBookUpdateBuffered;
|
private static readonly Action<ILogger, string, string, long, long, long, long, Exception?> _orderBookUpdateBuffered;
|
||||||
private static readonly Action<ILogger, string, string, decimal, decimal, Exception?> _orderBookOutOfSyncDetected;
|
private static readonly Action<ILogger, string, string, decimal, decimal, Exception?> _orderBookOutOfSyncDetected;
|
||||||
@ -33,204 +33,204 @@ namespace CryptoExchange.Net.Logging.Extensions
|
|||||||
_orderBookStatusChanged = LoggerMessage.Define<string, string, OrderBookStatus, OrderBookStatus>(
|
_orderBookStatusChanged = LoggerMessage.Define<string, string, OrderBookStatus, OrderBookStatus>(
|
||||||
LogLevel.Information,
|
LogLevel.Information,
|
||||||
new EventId(5000, "OrderBookStatusChanged"),
|
new EventId(5000, "OrderBookStatusChanged"),
|
||||||
"{Id} order book {Symbol} status changed: {PreviousStatus} => {NewStatus}");
|
"{Api} order book {Symbol} status changed: {PreviousStatus} => {NewStatus}");
|
||||||
|
|
||||||
_orderBookStarting = LoggerMessage.Define<string, string>(
|
_orderBookStarting = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5001, "OrderBookStarting"),
|
new EventId(5001, "OrderBookStarting"),
|
||||||
"{Id} order book {Symbol} starting");
|
"{Api} order book {Symbol} starting");
|
||||||
|
|
||||||
_orderBookStoppedStarting = LoggerMessage.Define<string, string>(
|
_orderBookStoppedStarting = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5002, "OrderBookStoppedStarting"),
|
new EventId(5002, "OrderBookStoppedStarting"),
|
||||||
"{Id} order book {Symbol} stopped while starting");
|
"{Api} order book {Symbol} stopped while starting");
|
||||||
|
|
||||||
_orderBookConnectionLost = LoggerMessage.Define<string, string>(
|
_orderBookConnectionLost = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5003, "OrderBookConnectionLost"),
|
new EventId(5003, "OrderBookConnectionLost"),
|
||||||
"{Id} order book {Symbol} connection lost");
|
"{Api} order book {Symbol} connection lost");
|
||||||
|
|
||||||
_orderBookDisconnected = LoggerMessage.Define<string, string>(
|
_orderBookDisconnected = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5004, "OrderBookDisconnected"),
|
new EventId(5004, "OrderBookDisconnected"),
|
||||||
"{Id} order book {Symbol} disconnected");
|
"{Api} order book {Symbol} disconnected");
|
||||||
|
|
||||||
_orderBookStopping = LoggerMessage.Define<string, string>(
|
_orderBookStopping = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5005, "OrderBookStopping"),
|
new EventId(5005, "OrderBookStopping"),
|
||||||
"{Id} order book {Symbol} stopping");
|
"{Api} order book {Symbol} stopping");
|
||||||
|
|
||||||
|
|
||||||
_orderBookStopped = LoggerMessage.Define<string, string>(
|
_orderBookStopped = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Trace,
|
LogLevel.Trace,
|
||||||
new EventId(5006, "OrderBookStopped"),
|
new EventId(5006, "OrderBookStopped"),
|
||||||
"{Id} order book {Symbol} stopped");
|
"{Api} order book {Symbol} stopped");
|
||||||
|
|
||||||
_orderBookProcessingBufferedUpdates = LoggerMessage.Define<string, int>(
|
_orderBookProcessingBufferedUpdates = LoggerMessage.Define<string, string, int>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5007, "OrderBookProcessingBufferedUpdates"),
|
new EventId(5007, "OrderBookProcessingBufferedUpdates"),
|
||||||
"{Id} Processing {NumberBufferedUpdated} buffered updates");
|
"{Api} order book {Symbol} Processing {NumberBufferedUpdated} buffered updates");
|
||||||
|
|
||||||
_orderBookUpdateSkipped = LoggerMessage.Define<string, string, long, long>(
|
_orderBookUpdateSkipped = LoggerMessage.Define<string, string, long, long>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5008, "OrderBookUpdateSkipped"),
|
new EventId(5008, "OrderBookUpdateSkipped"),
|
||||||
"{Id} order book {Symbol} update skipped #{SequenceNumber}, currently at #{LastSequenceNumber}");
|
"{Api} order book {Symbol} update skipped #{SequenceNumber}, currently at #{LastSequenceNumber}");
|
||||||
|
|
||||||
_orderBookOutOfSync = LoggerMessage.Define<string, string, long, long>(
|
_orderBookOutOfSync = LoggerMessage.Define<string, string, long, long>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5009, "OrderBookOutOfSync"),
|
new EventId(5009, "OrderBookOutOfSync"),
|
||||||
"{Id} order book {Symbol} out of sync (expected {ExpectedSequenceNumber}, was {SequenceNumber}), reconnecting");
|
"{Api} order book {Symbol} out of sync (expected {ExpectedSequenceNumber}, was {SequenceNumber}), reconnecting");
|
||||||
|
|
||||||
_orderBookResynced = LoggerMessage.Define<string, string>(
|
_orderBookResynced = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Information,
|
LogLevel.Information,
|
||||||
new EventId(5010, "OrderBookResynced"),
|
new EventId(5010, "OrderBookResynced"),
|
||||||
"{Id} order book {Symbol} successfully resynchronized");
|
"{Api} order book {Symbol} successfully resynchronized");
|
||||||
|
|
||||||
_orderBookMessageSkippedBecauseOfResubscribing = LoggerMessage.Define<string>(
|
_orderBookMessageSkippedBecauseOfResubscribing = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Trace,
|
LogLevel.Trace,
|
||||||
new EventId(5011, "OrderBookMessageSkippedResubscribing"),
|
new EventId(5011, "OrderBookMessageSkippedResubscribing"),
|
||||||
"{Id} Skipping message because of resubscribing");
|
"{Api} order book {Symbol} Skipping message because of resubscribing");
|
||||||
|
|
||||||
_orderBookDataSet = LoggerMessage.Define<string, string, long, long, long>(
|
_orderBookDataSet = LoggerMessage.Define<string, string, long, long, long>(
|
||||||
LogLevel.Debug,
|
LogLevel.Debug,
|
||||||
new EventId(5012, "OrderBookDataSet"),
|
new EventId(5012, "OrderBookDataSet"),
|
||||||
"{Id} order book {Symbol} data set: {BidCount} bids, {AskCount} asks. #{EndUpdateId}");
|
"{Api} order book {Symbol} data set: {BidCount} bids, {AskCount} asks. #{EndUpdateId}");
|
||||||
|
|
||||||
_orderBookUpdateBuffered = LoggerMessage.Define<string, string, long, long, long, long>(
|
_orderBookUpdateBuffered = LoggerMessage.Define<string, string, long, long, long, long>(
|
||||||
LogLevel.Trace,
|
LogLevel.Trace,
|
||||||
new EventId(5013, "OrderBookUpdateBuffered"),
|
new EventId(5013, "OrderBookUpdateBuffered"),
|
||||||
"{Id} order book {Symbol} update buffered #{StartUpdateId}-#{EndUpdateId} [{AsksCount} asks, {BidsCount} bids]");
|
"{Api} order book {Symbol} update buffered #{StartUpdateId}-#{EndUpdateId} [{AsksCount} asks, {BidsCount} bids]");
|
||||||
|
|
||||||
_orderBookOutOfSyncDetected = LoggerMessage.Define<string, string, decimal, decimal>(
|
_orderBookOutOfSyncDetected = LoggerMessage.Define<string, string, decimal, decimal>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5014, "OrderBookOutOfSyncDetected"),
|
new EventId(5014, "OrderBookOutOfSyncDetected"),
|
||||||
"{Id} order book {Symbol} detected out of sync order book. First ask: {FirstAsk}, first bid: {FirstBid}. Resyncing");
|
"{Api} order book {Symbol} detected out of sync order book. First ask: {FirstAsk}, first bid: {FirstBid}. Resyncing");
|
||||||
|
|
||||||
_orderBookReconnectingSocket = LoggerMessage.Define<string, string>(
|
_orderBookReconnectingSocket = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5015, "OrderBookReconnectingSocket"),
|
new EventId(5015, "OrderBookReconnectingSocket"),
|
||||||
"{Id} order book {Symbol} out of sync. Reconnecting socket");
|
"{Api} order book {Symbol} out of sync. Reconnecting socket");
|
||||||
|
|
||||||
_orderBookResyncing = LoggerMessage.Define<string, string>(
|
_orderBookResyncing = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5016, "OrderBookResyncing"),
|
new EventId(5016, "OrderBookResyncing"),
|
||||||
"{Id} order book {Symbol} out of sync. Resyncing");
|
"{Api} order book {Symbol} out of sync. Resyncing");
|
||||||
|
|
||||||
_orderBookResyncFailed = LoggerMessage.Define<string, string>(
|
_orderBookResyncFailed = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5017, "OrderBookResyncFailed"),
|
new EventId(5017, "OrderBookResyncFailed"),
|
||||||
"{Id} order book {Symbol} resync failed, reconnecting socket");
|
"{Api} order book {Symbol} resync failed, reconnecting socket");
|
||||||
|
|
||||||
_orderBookSkippedMessage = LoggerMessage.Define<string, string, long, long>(
|
_orderBookSkippedMessage = LoggerMessage.Define<string, string, long, long>(
|
||||||
LogLevel.Trace,
|
LogLevel.Trace,
|
||||||
new EventId(5018, "OrderBookSkippedMessage"),
|
new EventId(5018, "OrderBookSkippedMessage"),
|
||||||
"{Id} order book {Symbol} update skipped #{FirstUpdateId}-{LastUpdateId}");
|
"{Api} order book {Symbol} update skipped #{FirstUpdateId}-{LastUpdateId}");
|
||||||
|
|
||||||
_orderBookProcessedMessage = LoggerMessage.Define<string, string, long, long>(
|
_orderBookProcessedMessage = LoggerMessage.Define<string, string, long, long>(
|
||||||
LogLevel.Trace,
|
LogLevel.Trace,
|
||||||
new EventId(5019, "OrderBookProcessedMessage"),
|
new EventId(5019, "OrderBookProcessedMessage"),
|
||||||
"{Id} order book {Symbol} update processed #{FirstUpdateId}-{LastUpdateId}");
|
"{Api} order book {Symbol} update processed #{FirstUpdateId}-{LastUpdateId}");
|
||||||
|
|
||||||
_orderBookOutOfSyncChecksum = LoggerMessage.Define<string, string>(
|
_orderBookOutOfSyncChecksum = LoggerMessage.Define<string, string>(
|
||||||
LogLevel.Warning,
|
LogLevel.Warning,
|
||||||
new EventId(5020, "OrderBookOutOfSyncChecksum"),
|
new EventId(5020, "OrderBookOutOfSyncChecksum"),
|
||||||
"{Id} order book {Symbol} out of sync. Checksum mismatch, resyncing");
|
"{Api} order book {Symbol} out of sync. Checksum mismatch, resyncing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookStatusChanged(this ILogger logger, string id, string symbol, OrderBookStatus previousStatus, OrderBookStatus newStatus)
|
public static void OrderBookStatusChanged(this ILogger logger, string api, string symbol, OrderBookStatus previousStatus, OrderBookStatus newStatus)
|
||||||
{
|
{
|
||||||
_orderBookStatusChanged(logger, id, symbol, previousStatus, newStatus, null);
|
_orderBookStatusChanged(logger, api, symbol, previousStatus, newStatus, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookStarting(this ILogger logger, string id, string symbol)
|
public static void OrderBookStarting(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookStarting(logger, id, symbol, null);
|
_orderBookStarting(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookStoppedStarting(this ILogger logger, string id, string symbol)
|
public static void OrderBookStoppedStarting(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookStoppedStarting(logger, id, symbol, null);
|
_orderBookStoppedStarting(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookConnectionLost(this ILogger logger, string id, string symbol)
|
public static void OrderBookConnectionLost(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookConnectionLost(logger, id, symbol, null);
|
_orderBookConnectionLost(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookDisconnected(this ILogger logger, string id, string symbol)
|
public static void OrderBookDisconnected(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookDisconnected(logger, id, symbol, null);
|
_orderBookDisconnected(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookStopping(this ILogger logger, string id, string symbol)
|
public static void OrderBookStopping(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookStopping(logger, id, symbol, null);
|
_orderBookStopping(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookStopped(this ILogger logger, string id, string symbol)
|
public static void OrderBookStopped(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookStopped(logger, id, symbol, null);
|
_orderBookStopped(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookProcessingBufferedUpdates(this ILogger logger, string id, int numberBufferedUpdated)
|
public static void OrderBookProcessingBufferedUpdates(this ILogger logger, string api, string symbol, int numberBufferedUpdated)
|
||||||
{
|
{
|
||||||
_orderBookProcessingBufferedUpdates(logger, id, numberBufferedUpdated, null);
|
_orderBookProcessingBufferedUpdates(logger, api, symbol, numberBufferedUpdated, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookUpdateSkipped(this ILogger logger, string id, string symbol, long sequence, long lastSequenceNumber)
|
public static void OrderBookUpdateSkipped(this ILogger logger, string api, string symbol, long sequence, long lastSequenceNumber)
|
||||||
{
|
{
|
||||||
_orderBookUpdateSkipped(logger, id, symbol, sequence, lastSequenceNumber, null);
|
_orderBookUpdateSkipped(logger, api, symbol, sequence, lastSequenceNumber, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookOutOfSync(this ILogger logger, string id, string symbol, long expectedSequenceNumber, long sequenceNumber)
|
public static void OrderBookOutOfSync(this ILogger logger, string api, string symbol, long expectedSequenceNumber, long sequenceNumber)
|
||||||
{
|
{
|
||||||
_orderBookOutOfSync(logger, id, symbol, expectedSequenceNumber, sequenceNumber, null);
|
_orderBookOutOfSync(logger, api, symbol, expectedSequenceNumber, sequenceNumber, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookResynced(this ILogger logger, string id, string symbol)
|
public static void OrderBookResynced(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookResynced(logger, id, symbol, null);
|
_orderBookResynced(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookMessageSkippedResubscribing(this ILogger logger, string id)
|
public static void OrderBookMessageSkippedResubscribing(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookMessageSkippedBecauseOfResubscribing(logger, id, null);
|
_orderBookMessageSkippedBecauseOfResubscribing(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookDataSet(this ILogger logger, string id, string symbol, long bidCount, long askCount, long endUpdateId)
|
public static void OrderBookDataSet(this ILogger logger, string api, string symbol, long bidCount, long askCount, long endUpdateId)
|
||||||
{
|
{
|
||||||
_orderBookDataSet(logger, id, symbol, bidCount, askCount, endUpdateId, null);
|
_orderBookDataSet(logger, api, symbol, bidCount, askCount, endUpdateId, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookUpdateBuffered(this ILogger logger, string id, string symbol, long startUpdateId, long endUpdateId, long asksCount, long bidsCount)
|
public static void OrderBookUpdateBuffered(this ILogger logger, string api, string symbol, long startUpdateId, long endUpdateId, long asksCount, long bidsCount)
|
||||||
{
|
{
|
||||||
_orderBookUpdateBuffered(logger, id, symbol, startUpdateId, endUpdateId, asksCount, bidsCount, null);
|
_orderBookUpdateBuffered(logger, api, symbol, startUpdateId, endUpdateId, asksCount, bidsCount, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookOutOfSyncDetected(this ILogger logger, string id, string symbol, decimal firstAsk, decimal firstBid)
|
public static void OrderBookOutOfSyncDetected(this ILogger logger, string api, string symbol, decimal firstAsk, decimal firstBid)
|
||||||
{
|
{
|
||||||
_orderBookOutOfSyncDetected(logger, id, symbol, firstAsk, firstBid, null);
|
_orderBookOutOfSyncDetected(logger, api, symbol, firstAsk, firstBid, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookReconnectingSocket(this ILogger logger, string id, string symbol)
|
public static void OrderBookReconnectingSocket(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookReconnectingSocket(logger, id, symbol, null);
|
_orderBookReconnectingSocket(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookResyncing(this ILogger logger, string id, string symbol)
|
public static void OrderBookResyncing(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookResyncing(logger, id, symbol, null);
|
_orderBookResyncing(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookResyncFailed(this ILogger logger, string id, string symbol)
|
public static void OrderBookResyncFailed(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookResyncFailed(logger, id, symbol, null);
|
_orderBookResyncFailed(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookSkippedMessage(this ILogger logger, string id, string symbol, long firstUpdateId, long lastUpdateId)
|
public static void OrderBookSkippedMessage(this ILogger logger, string api, string symbol, long firstUpdateId, long lastUpdateId)
|
||||||
{
|
{
|
||||||
_orderBookSkippedMessage(logger, id, symbol, firstUpdateId, lastUpdateId, null);
|
_orderBookSkippedMessage(logger, api, symbol, firstUpdateId, lastUpdateId, null);
|
||||||
}
|
}
|
||||||
public static void OrderBookProcessedMessage(this ILogger logger, string id, string symbol, long firstUpdateId, long lastUpdateId)
|
public static void OrderBookProcessedMessage(this ILogger logger, string api, string symbol, long firstUpdateId, long lastUpdateId)
|
||||||
{
|
{
|
||||||
_orderBookProcessedMessage(logger, id, symbol, firstUpdateId, lastUpdateId, null);
|
_orderBookProcessedMessage(logger, api, symbol, firstUpdateId, lastUpdateId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OrderBookOutOfSyncChecksum(this ILogger logger, string id, string symbol)
|
public static void OrderBookOutOfSyncChecksum(this ILogger logger, string api, string symbol)
|
||||||
{
|
{
|
||||||
_orderBookOutOfSyncChecksum(logger, id, symbol, null);
|
_orderBookOutOfSyncChecksum(logger, api, symbol, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null!;
|
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null!;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsEnabled(LogLevel logLevel) => (int)logLevel < (int)_logLevel;
|
public bool IsEnabled(LogLevel logLevel) => (int)logLevel >= (int)_logLevel;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
||||||
{
|
{
|
||||||
if ((int)logLevel < (int)_logLevel)
|
if (!IsEnabled(logLevel))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var logMessage = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff} | {logLevel} | {(_categoryName == null ? "" : $"{_categoryName} | ")}{formatter(state, exception)}";
|
var logMessage = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff} | {logLevel} | {(_categoryName == null ? "" : $"{_categoryName} | ")}{formatter(state, exception)}";
|
||||||
|
@ -12,6 +12,7 @@ using CryptoExchange.Net.Objects;
|
|||||||
using CryptoExchange.Net.Objects.Options;
|
using CryptoExchange.Net.Objects.Options;
|
||||||
using CryptoExchange.Net.Objects.Sockets;
|
using CryptoExchange.Net.Objects.Sockets;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.OrderBook
|
namespace CryptoExchange.Net.OrderBook
|
||||||
{
|
{
|
||||||
@ -89,7 +90,10 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
protected int? Levels { get; set; } = null;
|
protected int? Levels { get; set; } = null;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Id { get; }
|
public string Exchange { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string Api { get; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public OrderBookStatus Status
|
public OrderBookStatus Status
|
||||||
@ -102,7 +106,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
|
|
||||||
var old = _status;
|
var old = _status;
|
||||||
_status = value;
|
_status = value;
|
||||||
_logger.OrderBookStatusChanged(Id, Symbol, old, value);
|
_logger.OrderBookStatusChanged(Api, Symbol, old, value);
|
||||||
OnStatusChange?.Invoke(old, _status);
|
OnStatusChange?.Invoke(old, _status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,14 +197,17 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Logger to use. If not provided will create a TraceLogger</param>
|
/// <param name="logger">Logger to use. If not provided will create a TraceLogger</param>
|
||||||
/// <param name="id">The id of the order book. Should be set to {Exchange}[{type}], for example: Kucoin[Spot]</param>
|
/// <param name="exchange">The exchange of the order book</param>
|
||||||
|
/// <param name="api">The API the book is for, for example Spot</param>
|
||||||
/// <param name="symbol">The symbol the order book is for</param>
|
/// <param name="symbol">The symbol the order book is for</param>
|
||||||
protected SymbolOrderBook(ILogger? logger, string id, string symbol)
|
protected SymbolOrderBook(ILoggerFactory? logger, string exchange, string api, string symbol)
|
||||||
{
|
{
|
||||||
if (symbol == null)
|
if (symbol == null)
|
||||||
throw new ArgumentNullException(nameof(symbol));
|
throw new ArgumentNullException(nameof(symbol));
|
||||||
|
|
||||||
Id = id;
|
Exchange = exchange;
|
||||||
|
Api = api;
|
||||||
|
|
||||||
_processBuffer = new List<ProcessBufferRangeSequenceEntry>();
|
_processBuffer = new List<ProcessBufferRangeSequenceEntry>();
|
||||||
_processQueue = new ConcurrentQueue<object>();
|
_processQueue = new ConcurrentQueue<object>();
|
||||||
_queueEvent = new AsyncResetEvent(false, true);
|
_queueEvent = new AsyncResetEvent(false, true);
|
||||||
@ -211,7 +218,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
_asks = new SortedList<decimal, ISymbolOrderBookEntry>();
|
_asks = new SortedList<decimal, ISymbolOrderBookEntry>();
|
||||||
_bids = new SortedList<decimal, ISymbolOrderBookEntry>(new DescComparer<decimal>());
|
_bids = new SortedList<decimal, ISymbolOrderBookEntry>(new DescComparer<decimal>());
|
||||||
|
|
||||||
_logger = logger ?? new TraceLogger();
|
_logger = logger?.CreateLogger(Exchange) ?? NullLoggerFactory.Instance.CreateLogger(Exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -233,7 +240,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
if (Status != OrderBookStatus.Disconnected)
|
if (Status != OrderBookStatus.Disconnected)
|
||||||
throw new InvalidOperationException($"Can't start book unless state is {OrderBookStatus.Disconnected}. Current state: {Status}");
|
throw new InvalidOperationException($"Can't start book unless state is {OrderBookStatus.Disconnected}. Current state: {Status}");
|
||||||
|
|
||||||
_logger.OrderBookStarting(Id, Symbol);
|
_logger.OrderBookStarting(Api, Symbol);
|
||||||
_cts = new CancellationTokenSource();
|
_cts = new CancellationTokenSource();
|
||||||
ct?.Register(async () =>
|
ct?.Register(async () =>
|
||||||
{
|
{
|
||||||
@ -258,7 +265,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
|
|
||||||
if (_cts.IsCancellationRequested)
|
if (_cts.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.OrderBookStoppedStarting(Id, Symbol);
|
_logger.OrderBookStoppedStarting(Api, Symbol);
|
||||||
await startResult.Data.CloseAsync().ConfigureAwait(false);
|
await startResult.Data.CloseAsync().ConfigureAwait(false);
|
||||||
Status = OrderBookStatus.Disconnected;
|
Status = OrderBookStatus.Disconnected;
|
||||||
return new CallResult<bool>(new CancellationRequestedError());
|
return new CallResult<bool>(new CancellationRequestedError());
|
||||||
@ -273,8 +280,9 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
return new CallResult<bool>(true);
|
return new CallResult<bool>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleConnectionLost() {
|
private void HandleConnectionLost()
|
||||||
_logger.OrderBookConnectionLost(Id, Symbol);
|
{
|
||||||
|
_logger.OrderBookConnectionLost(Api, Symbol);
|
||||||
if (Status != OrderBookStatus.Disposed) {
|
if (Status != OrderBookStatus.Disposed) {
|
||||||
Status = OrderBookStatus.Reconnecting;
|
Status = OrderBookStatus.Reconnecting;
|
||||||
Reset();
|
Reset();
|
||||||
@ -282,7 +290,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void HandleConnectionClosed() {
|
private void HandleConnectionClosed() {
|
||||||
_logger.OrderBookDisconnected(Id, Symbol);
|
_logger.OrderBookDisconnected(Api, Symbol);
|
||||||
Status = OrderBookStatus.Disconnected;
|
Status = OrderBookStatus.Disconnected;
|
||||||
_ = StopAsync();
|
_ = StopAsync();
|
||||||
}
|
}
|
||||||
@ -294,7 +302,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task StopAsync()
|
public async Task StopAsync()
|
||||||
{
|
{
|
||||||
_logger.OrderBookStopping(Id, Symbol);
|
_logger.OrderBookStopping(Api, Symbol);
|
||||||
Status = OrderBookStatus.Disconnected;
|
Status = OrderBookStatus.Disconnected;
|
||||||
_cts?.Cancel();
|
_cts?.Cancel();
|
||||||
_queueEvent.Set();
|
_queueEvent.Set();
|
||||||
@ -307,7 +315,8 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
_subscription.ConnectionClosed -= HandleConnectionClosed;
|
_subscription.ConnectionClosed -= HandleConnectionClosed;
|
||||||
_subscription.ConnectionRestored -= HandleConnectionRestored;
|
_subscription.ConnectionRestored -= HandleConnectionRestored;
|
||||||
}
|
}
|
||||||
_logger.OrderBookStopped(Id, Symbol);
|
|
||||||
|
_logger.OrderBookStopped(Api, Symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -465,7 +474,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
{
|
{
|
||||||
var pbList = _processBuffer.ToList();
|
var pbList = _processBuffer.ToList();
|
||||||
if (pbList.Count > 0)
|
if (pbList.Count > 0)
|
||||||
_logger.OrderBookProcessingBufferedUpdates(Id, pbList.Count);
|
_logger.OrderBookProcessingBufferedUpdates(Api, Symbol, pbList.Count);
|
||||||
|
|
||||||
foreach (var bufferEntry in pbList)
|
foreach (var bufferEntry in pbList)
|
||||||
{
|
{
|
||||||
@ -484,14 +493,14 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
{
|
{
|
||||||
if (sequence <= LastSequenceNumber)
|
if (sequence <= LastSequenceNumber)
|
||||||
{
|
{
|
||||||
_logger.OrderBookSkippedMessage(Id, Symbol, sequence, LastSequenceNumber);
|
_logger.OrderBookSkippedMessage(Api, Symbol, sequence, LastSequenceNumber);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sequencesAreConsecutive && sequence > LastSequenceNumber + 1)
|
if (_sequencesAreConsecutive && sequence > LastSequenceNumber + 1)
|
||||||
{
|
{
|
||||||
// Out of sync
|
// Out of sync
|
||||||
_logger.OrderBookOutOfSync(Id, Symbol, LastSequenceNumber + 1, sequence);
|
_logger.OrderBookOutOfSync(Api, Symbol, LastSequenceNumber + 1, sequence);
|
||||||
_stopProcessing = true;
|
_stopProcessing = true;
|
||||||
Resubscribe();
|
Resubscribe();
|
||||||
return false;
|
return false;
|
||||||
@ -645,7 +654,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
success = resyncResult;
|
success = resyncResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.OrderBookResynced(Id, Symbol);
|
_logger.OrderBookResynced(Api, Symbol);
|
||||||
Status = OrderBookStatus.Synced;
|
Status = OrderBookStatus.Synced;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,7 +671,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
|
|
||||||
if (_stopProcessing)
|
if (_stopProcessing)
|
||||||
{
|
{
|
||||||
_logger.OrderBookMessageSkippedResubscribing(Id);
|
_logger.OrderBookMessageSkippedResubscribing(Api, Symbol);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +703,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
BidCount = _bids.Count;
|
BidCount = _bids.Count;
|
||||||
|
|
||||||
UpdateTime = DateTime.UtcNow;
|
UpdateTime = DateTime.UtcNow;
|
||||||
_logger.OrderBookDataSet(Id, Symbol, BidCount, AskCount, item.EndUpdateId);
|
_logger.OrderBookDataSet(Api, Symbol, BidCount, AskCount, item.EndUpdateId);
|
||||||
CheckProcessBuffer();
|
CheckProcessBuffer();
|
||||||
OnOrderBookUpdate?.Invoke((item.Bids, item.Asks));
|
OnOrderBookUpdate?.Invoke((item.Bids, item.Asks));
|
||||||
OnBestOffersChanged?.Invoke((BestBid, BestAsk));
|
OnBestOffersChanged?.Invoke((BestBid, BestAsk));
|
||||||
@ -714,7 +723,8 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
FirstUpdateId = item.StartUpdateId,
|
FirstUpdateId = item.StartUpdateId,
|
||||||
LastUpdateId = item.EndUpdateId,
|
LastUpdateId = item.EndUpdateId,
|
||||||
});
|
});
|
||||||
_logger.OrderBookUpdateBuffered(Id, Symbol, item.StartUpdateId, item.EndUpdateId, item.Asks.Count(), item.Bids.Count());
|
|
||||||
|
_logger.OrderBookUpdateBuffered(Api, Symbol, item.StartUpdateId, item.EndUpdateId, item.Asks.Count(), item.Bids.Count());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -727,7 +737,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
|
|
||||||
if (_asks.First().Key < _bids.First().Key)
|
if (_asks.First().Key < _bids.First().Key)
|
||||||
{
|
{
|
||||||
_logger.OrderBookOutOfSyncDetected(Id, Symbol, _asks.First().Key, _bids.First().Key);
|
_logger.OrderBookOutOfSyncDetected(Api, Symbol, _asks.First().Key, _bids.First().Key);
|
||||||
_stopProcessing = true;
|
_stopProcessing = true;
|
||||||
Resubscribe();
|
Resubscribe();
|
||||||
return;
|
return;
|
||||||
@ -761,7 +771,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
|
|
||||||
if (!checksumResult)
|
if (!checksumResult)
|
||||||
{
|
{
|
||||||
_logger.OrderBookOutOfSyncChecksum(Id, Symbol);
|
_logger.OrderBookOutOfSyncChecksum(Api, Symbol);
|
||||||
_stopProcessing = true;
|
_stopProcessing = true;
|
||||||
Resubscribe();
|
Resubscribe();
|
||||||
}
|
}
|
||||||
@ -785,7 +795,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
if (!await _subscription!.ResubscribeAsync().ConfigureAwait(false))
|
if (!await _subscription!.ResubscribeAsync().ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
// Resubscribing failed, reconnect the socket
|
// Resubscribing failed, reconnect the socket
|
||||||
_logger.OrderBookResyncFailed(Id, Symbol);
|
_logger.OrderBookResyncFailed(Api, Symbol);
|
||||||
Status = OrderBookStatus.Reconnecting;
|
Status = OrderBookStatus.Reconnecting;
|
||||||
_ = _subscription!.ReconnectAsync();
|
_ = _subscription!.ReconnectAsync();
|
||||||
}
|
}
|
||||||
@ -800,7 +810,7 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
{
|
{
|
||||||
if (lastUpdateId <= LastSequenceNumber)
|
if (lastUpdateId <= LastSequenceNumber)
|
||||||
{
|
{
|
||||||
_logger.OrderBookUpdateSkipped(Id, Symbol, firstUpdateId, lastUpdateId);
|
_logger.OrderBookUpdateSkipped(Api, Symbol, firstUpdateId, lastUpdateId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -826,7 +836,8 @@ namespace CryptoExchange.Net.OrderBook
|
|||||||
}
|
}
|
||||||
|
|
||||||
LastSequenceNumber = lastUpdateId;
|
LastSequenceNumber = lastUpdateId;
|
||||||
_logger.OrderBookProcessedMessage(Id, Symbol, firstUpdateId, lastUpdateId);
|
|
||||||
|
_logger.OrderBookProcessedMessage(Api, Symbol, firstUpdateId, lastUpdateId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user