1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-07 16:06:15 +00:00
This commit is contained in:
JKorf 2024-01-04 21:27:59 +01:00
parent c1ee36dd8a
commit 9ead87d350
5 changed files with 37 additions and 7 deletions

View File

@ -112,8 +112,29 @@ namespace CryptoExchange.Net.Converters
return item.Type == JTokenType.Array;
}
public bool IsEmptyArray(IEnumerable<int> indexes)
{
var item = _token;
foreach (var index in indexes)
{
if (item.Type != JTokenType.Array)
return false;
var arr = ((JArray)item);
if (arr.Count <= index)
return false;
item = arr[index];
}
return item.Type == JTokenType.Array && !item.HasValues;
}
private JToken? GetToken(string key)
{
if (key == null)
return _token;
if (_cache.TryGetValue(key, out var token))
return token;

View File

@ -9,6 +9,7 @@ namespace CryptoExchange.Net.Interfaces
{
bool IsObject(string? key);
bool IsArray(IEnumerable<int> indexes);
bool IsEmptyArray(IEnumerable<int> indexes);
string? GetStringValue(string key);
int? GetIntValue(string key);
public int? GetCount(string key);

View File

@ -30,7 +30,7 @@ namespace CryptoExchange.Net.Sockets
/// <summary>
/// Strings to identify this subscription with
/// </summary>
public abstract List<string> StreamIdentifiers { get; }
public abstract List<string> StreamIdentifiers { get; set; }
/// <summary>
/// The query request object
@ -47,7 +47,7 @@ namespace CryptoExchange.Net.Sockets
/// </summary>
public int Weight { get; }
public abstract Dictionary<string, Type> TypeMapping { get; }
public abstract Dictionary<string, Type> TypeMapping { get; set; }
/// <summary>
/// ctor
@ -108,10 +108,18 @@ namespace CryptoExchange.Net.Sockets
/// <typeparam name="TResponse">Response object type</typeparam>
public abstract class Query<TResponse> : BaseQuery
{
public override Dictionary<string, Type> TypeMapping => new Dictionary<string, Type>
private Dictionary<string, Type> _typeMapping = new Dictionary<string, Type>
{
{ "", typeof(TResponse) }
};
public override Dictionary<string, Type> TypeMapping
{
get => _typeMapping;
set
{
_typeMapping = value;
}
}
/// <summary>
/// The typed call result

View File

@ -35,8 +35,8 @@ namespace CryptoExchange.Net.Sockets
if (listeners == null)
return null;
listeners.First().TypeMapping.TryGetValue(typeIdentifier ?? "", out var type);
return type;
var result = listeners.SelectMany(l => l.TypeMapping).FirstOrDefault(x => x.Key == (typeIdentifier ?? ""));
return result.Value;
}
}
@ -85,7 +85,7 @@ namespace CryptoExchange.Net.Sockets
if (!_listeners.TryGetValue(id, out var idListeners))
return false;
listeners = idListeners.ToList();
listeners = idListeners.Where(i => data.TypeIdentifier == null || i.TypeMapping.ContainsKey(data.TypeIdentifier)).ToList();
}
foreach (var listener in listeners)

View File

@ -57,7 +57,7 @@ namespace CryptoExchange.Net.Sockets
/// <summary>
/// Strings to identify this subscription with
/// </summary>
public abstract List<string> StreamIdentifiers { get; }
public abstract List<string> StreamIdentifiers { get; set; }
/// <summary>
/// Cancellation token registration