Skip to content

Commit

Permalink
Added websocket connection ratelimiter, updated CryptoExchange.Net ve…
Browse files Browse the repository at this point in the history
…rsion to fix some reconnect issues
  • Loading branch information
JKorf committed Aug 25, 2024
1 parent 5ec9fab commit 7d02624
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions BitMart.Net/BitMart.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>10.0</LangVersion>
Expand Down Expand Up @@ -48,10 +48,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.11.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.11.0" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions BitMart.Net/BitMartExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ private void Initialize()
{
BitMart = new RateLimitGate("BitMart IP");
BitMart.RateLimitTriggered += (x) => RateLimitTriggered?.Invoke(x);
SocketLimits = new RateLimitGate("Socket limits")
.AddGuard(new RateLimitGuard(RateLimitGuard.PerHost, new LimitItemTypeFilter(RateLimitItemType.Connection), 100, TimeSpan.FromSeconds(60), RateLimitWindowType.Sliding, connectionWeight: 1));
SocketLimits.RateLimitTriggered += (x) => RateLimitTriggered?.Invoke(x);
}


internal IRateLimitGate BitMart { get; private set; }
internal IRateLimitGate SocketLimits { get; private set; }

}
}
2 changes: 1 addition & 1 deletion BitMart.Net/Clients/SpotApi/BitMartSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ internal BitMartSocketClientSpotApi(ILogger logger, BitMartSocketOptions options
base(logger, options.Environment.SocketClientSpotAddress!, options, options.SpotOptions)
{
KeepAliveInterval = TimeSpan.Zero;

RegisterPeriodicQuery("ping", TimeSpan.FromSeconds(15), x => new PingQuery(), null);
RateLimiter = BitMartExchange.RateLimiter.SocketLimits;
}
#endregion

Expand Down

0 comments on commit 7d02624

Please sign in to comment.