Skip to content

Commit e3ed233

Browse files
authored
Use a single rate gate per type of api (#702)
* Use a single rate gate per type of api * Store rate gate to limit dictionary calls * Upgrade to net 6, make get type case insensitive
1 parent 8e0fe5b commit e3ed233

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

examples/ExchangeSharpWinForms/ExchangeSharpWinForms.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<ProjectGuid>{571623F9-1652-4669-8E17-A6FAD1426181}</ProjectGuid>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFramework>net6.0-windows</TargetFramework>
66
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
77
<AssemblyTitle>ExchangeSharpWinForms</AssemblyTitle>
88
<Product>ExchangeSharpWinForms</Product>
@@ -21,9 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<Compile Update="MainForm.cs">
25-
<SubType>Form</SubType>
26-
</Compile>
24+
<Compile Update="MainForm.cs" />
2725
<Compile Update="MainForm.Designer.cs">
2826
<DependentUpon>MainForm.cs</DependentUpon>
2927
</Compile>

src/ExchangeSharp.Forms/ExchangeSharp.Forms.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFramework>net6.0-windows</TargetFramework>
55
<DefineConstants>HAS_WINDOWS_FORMS</DefineConstants>
66
<NeutralLanguage>en</NeutralLanguage>
77
<LangVersion>8</LangVersion>
8+
<UseWindowsForms>true</UseWindowsForms>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -19,6 +20,10 @@
1920
<None Include="../../LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="" />
2021
</ItemGroup>
2122

23+
<ItemGroup>
24+
<PackageReference Include="Maikebing.System.Windows.Forms.DataVisualization" Version="5.0.1" />
25+
</ItemGroup>
26+
2227
<ItemGroup>
2328
<ProjectReference Include="..\ExchangeSharp\ExchangeSharp.csproj" />
2429
</ItemGroup>

src/ExchangeSharp.Forms/Forms/PlotForm.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ExchangeSharp.Forms/Forms/PlotForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT LICENSE
33
44
Copyright 2017 Digital Ruby, LLC - http://www.digitalruby.com

src/ExchangeSharp/API/Common/BaseAPI.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The above copyright notice and this permission notice shall be included in all c
1111
*/
1212
#nullable enable
1313
using System;
14+
using System.Collections.Concurrent;
1415
using System.Collections.Generic;
1516
using System.Diagnostics;
1617
using System.Globalization;
@@ -176,10 +177,17 @@ public IAPIRequestMaker RequestMaker
176177
/// </summary>
177178
public System.Security.SecureString? Passphrase { get; set; }
178179

180+
private static readonly ConcurrentDictionary<Type, RateGate> rateLimiters = new ConcurrentDictionary<Type, RateGate>();
181+
private RateGate rateGate;
179182
/// <summary>
180183
/// Rate limiter - set this to a new limit if you are seeing your ip get blocked by the API
184+
/// One rate limiter is created per type of api
181185
/// </summary>
182-
public RateGate RateLimit { get; set; } = new RateGate(5, TimeSpan.FromSeconds(15.0d));
186+
public RateGate RateLimit
187+
{
188+
get => rateGate ??= rateLimiters.GetOrAdd(GetType(), v => new RateGate(5, TimeSpan.FromSeconds(15.0d)));
189+
set => rateLimiters[GetType()] = rateGate = value;
190+
}
183191

184192
/// <summary>
185193
/// Default request method

src/ExchangeSharp/API/Exchanges/_Base/ExchangeName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal static Type GetExchangeType(string exchangeName)
4747
try
4848
{
4949
// make sure we have a valid type for the name
50-
Type type = Type.GetType($"ExchangeSharp.Exchange{exchangeName}API");
50+
Type type = Type.GetType($"ExchangeSharp.Exchange{exchangeName}API", true, true);
5151

5252
// we had better have a type sub-classing from ExchangeAPI
5353
if (type is null || !type.IsSubclassOf(exchangeApiType))

src/ExchangeSharpConsole/ExchangeSharpConsole.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<AssemblyName>exchange-sharp</AssemblyName>
6-
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<TargetFramework>net6.0</TargetFramework>
77
<NeutralLanguage>en</NeutralLanguage>
88
<LangVersion>8</LangVersion>
99
<AssemblyVersion>0.9.1</AssemblyVersion>

0 commit comments

Comments
 (0)