-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBinanceUsageContext.cs
31 lines (26 loc) · 1.02 KB
/
BinanceUsageContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Outcompute.Trader.Models;
using System.Collections.Concurrent;
namespace Outcompute.Trader.Trading.Binance;
internal class BinanceUsageContext
{
private readonly ConcurrentDictionary<(RateLimitType Type, TimeSpan Window), int> _limits = new();
private readonly ConcurrentDictionary<(RateLimitType Type, TimeSpan Window), (int Used, DateTime Updated)> _usages = new();
public void SetLimit(RateLimitType type, TimeSpan window, int limit)
{
_limits[(type, window)] = limit;
}
public void SetUsed(RateLimitType type, TimeSpan window, int used, DateTime updated)
{
_usages[(type, window)] = (used, updated);
}
public IEnumerable<(RateLimitType Type, TimeSpan Window, int Limit, int Used, DateTime Updated)> EnumerateAll()
{
foreach (var limit in _limits)
{
if (_usages.TryGetValue(limit.Key, out var used))
{
yield return (limit.Key.Type, limit.Key.Window, limit.Value, used.Used, used.Updated);
}
}
}
}