mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-04-12 16:13:12 +00:00
Updated WebSocket message routing improving performance for scenarios with multiple different subscriptions and topics Added AddCommaSeparated helper for Enum value arrays to ParameterCollection Improved EnumConverter performance and removed string allocation for happy path Fixed CreateParamString extension method for ArrayParametersSerialization.Json Fixed Shared GetOrderBookOptions and GetRecentTradeOptions base validations not being called
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using CryptoExchange.Net.Objects;
|
|
using CryptoExchange.Net.Objects.Sockets;
|
|
using CryptoExchange.Net.Sockets;
|
|
using CryptoExchange.Net.Sockets.Default;
|
|
using CryptoExchange.Net.Sockets.Default.Routing;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection.Metadata;
|
|
using System.Text;
|
|
|
|
namespace CryptoExchange.Net.UnitTests.Implementations
|
|
{
|
|
internal class TestSubscription<T> : Subscription
|
|
{
|
|
private readonly Action<DataEvent<T>> _handler;
|
|
private bool _subQuery;
|
|
|
|
public TestSubscription(ILogger logger, Action<DataEvent<T>> handler, bool subQuery, bool authenticated) : base(logger, authenticated, true)
|
|
{
|
|
_handler = handler;
|
|
_subQuery = subQuery;
|
|
|
|
MessageRouter = MessageRouter.CreateWithoutTopicFilter<T>("test", HandleUpdate);
|
|
}
|
|
|
|
protected override Query? GetSubQuery(SocketConnection connection)
|
|
{
|
|
if (!_subQuery)
|
|
return null;
|
|
|
|
return new TestQuery(new TestSocketMessage { Id = 1, Data = "Sub" }, false);
|
|
}
|
|
|
|
protected override Query? GetUnsubQuery(SocketConnection connection)
|
|
{
|
|
if (!_subQuery)
|
|
return null;
|
|
|
|
return new TestQuery(new TestSocketMessage { Id = 2, Data = "Unsub" }, false);
|
|
}
|
|
|
|
|
|
private CallResult? HandleUpdate(SocketConnection connection, DateTime time, string? originalData, T data)
|
|
{
|
|
_handler(new DataEvent<T>("Test", data, time, originalData));
|
|
return CallResult.SuccessResult;
|
|
}
|
|
}
|
|
}
|