Skip to content

Commit 6d246e9

Browse files
authored
Fix ExchangeAPI.GetExchangeMarketFromCacheAsync (#831)
Fix for avoiding multiple requests when pair name listed in tickers is missing in symbols response.
1 parent 9486d77 commit 6d246e9

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,7 @@ public virtual async Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataA
976976
}
977977

978978
/// <summary>
979-
/// Gets the exchange market from this exchange's SymbolsMetadata cache. This will make a network request if needed to retrieve fresh markets from the exchange using GetSymbolsMetadataAsync().
980-
/// Please note that sending a symbol that is not found over and over will result in many network requests. Only send symbols that you are confident exist on the exchange.
979+
/// Gets the exchange market from this exchange's SymbolsMetadata cache.
981980
/// </summary>
982981
/// <param name="marketSymbol">The market symbol. Ex. ADA/BTC. This is assumed to be normalized and already correct for the exchange.</param>
983982
/// <returns>The ExchangeMarket or null if it doesn't exist in the cache or there was an error</returns>
@@ -993,34 +992,11 @@ string marketSymbol
993992
try
994993
{
995994
// *NOTE*: custom caching, do not wrap in CacheMethodCall...
996-
// *NOTE*: vulnerability exists where if spammed with not found symbols, lots of network calls will happen, stalling the application
997-
// TODO: Add not found dictionary, or some mechanism to mitigate this risk
998995
// not sure if this is needed, but adding it just in case
999996
await new SynchronizationContextRemover();
1000-
Dictionary<string, ExchangeMarket> lookup =
1001-
await this.GetExchangeMarketDictionaryFromCacheAsync();
997+
var lookup = await this.GetExchangeMarketDictionaryFromCacheAsync();
1002998

1003-
foreach (KeyValuePair<string, ExchangeMarket> kvp in lookup)
1004-
{
1005-
if (
1006-
(kvp.Key == marketSymbol)
1007-
|| (kvp.Value.MarketSymbol == marketSymbol)
1008-
|| (kvp.Value.AltMarketSymbol == marketSymbol)
1009-
|| (kvp.Value.AltMarketSymbol2 == marketSymbol)
1010-
)
1011-
{
1012-
return kvp.Value;
1013-
}
1014-
}
1015-
1016-
// try again with a fresh request
1017-
Cache.Remove(nameof(GetMarketSymbolsMetadataAsync));
1018-
Cache.Remove(
1019-
nameof(ExchangeAPIExtensions.GetExchangeMarketDictionaryFromCacheAsync)
1020-
);
1021-
lookup = await this.GetExchangeMarketDictionaryFromCacheAsync();
1022-
1023-
foreach (KeyValuePair<string, ExchangeMarket> kvp in lookup)
999+
foreach (var kvp in lookup)
10241000
{
10251001
if (
10261002
(kvp.Key == marketSymbol)

0 commit comments

Comments
 (0)