Skip to content

Commit 7aebe46

Browse files
authored
Cleanup ExchangeMarketSymbolToGlobalMarketSymbolAsync overrides (#888)
* BinanceGroupCommon: Remove redundant ExchangeMarketSymbolToGlobalMarketSymbolAsync override * MEXC: Remove redundant ExchangeMarketSymbolToGlobalMarketSymbolAsync override * BitMEX: Override ExchangeMarketSymbolToGlobalMarketSymbolAsync Adds an ExchangeMarketSymbolToGlobalMarketSymbolAsync override to convert local ISO 4217-style symbols (e.g., XBT) to global market symbols (e.g., BTC).
1 parent 454ed97 commit 7aebe46

File tree

3 files changed

+25
-42
lines changed

3 files changed

+25
-42
lines changed

src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,6 @@ protected BinanceGroupCommon()
7474
RateLimit = new RateGate(40, TimeSpan.FromSeconds(10));
7575
}
7676

77-
protected virtual string[] NonThreeLetterQuoteCurrencies => new[] { "USDT", "USDC", "EURI" };
78-
79-
public override Task<string> ExchangeMarketSymbolToGlobalMarketSymbolAsync(
80-
string marketSymbol
81-
)
82-
{
83-
foreach (var quoteCurrency in NonThreeLetterQuoteCurrencies)
84-
{
85-
if (marketSymbol.EndsWith(quoteCurrency))
86-
{
87-
return ExchangeMarketSymbolToGlobalMarketSymbolWithSeparatorAsync(
88-
marketSymbol.Substring(0, marketSymbol.Length - quoteCurrency.Length) +
89-
GlobalMarketSymbolSeparator +
90-
quoteCurrency);
91-
}
92-
}
93-
94-
return ExchangeMarketSymbolToGlobalMarketSymbolWithSeparatorAsync(
95-
marketSymbol.Substring(0, marketSymbol.Length - 3) + GlobalMarketSymbolSeparator +
96-
marketSymbol.Substring(marketSymbol.Length - 3));
97-
}
98-
9977
/// <summary>
10078
/// Get the details of all trades
10179
/// </summary>

src/ExchangeSharp/API/Exchanges/BitMEX/ExchangeBitMEXAPI.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The above copyright notice and this permission notice shall be included in all c
1212

1313
using System;
1414
using System.Collections.Generic;
15+
using System.IO;
1516
using System.Linq;
1617
using System.Net;
1718
using System.Text;
@@ -52,11 +53,32 @@ private ExchangeBitMEXAPI()
5253
RateLimit = new RateGate(300, TimeSpan.FromMinutes(5));
5354
}
5455

55-
public override Task<string> ExchangeMarketSymbolToGlobalMarketSymbolAsync(
56+
public override async Task<string> ExchangeMarketSymbolToGlobalMarketSymbolAsync(
5657
string marketSymbol
5758
)
5859
{
59-
throw new NotImplementedException();
60+
ExchangeMarket marketSymbolMetadata = await GetExchangeMarketFromCacheAsync(
61+
marketSymbol
62+
);
63+
if (marketSymbolMetadata == null)
64+
{
65+
throw new InvalidDataException(
66+
$"No market symbol metadata returned or unable to find symbol metadata for {marketSymbol}"
67+
);
68+
}
69+
70+
if (marketSymbolMetadata.BaseCurrency == "XBT")
71+
{
72+
marketSymbolMetadata.BaseCurrency = "BTC";
73+
}
74+
75+
if (marketSymbolMetadata.QuoteCurrency == "XBT")
76+
{
77+
marketSymbolMetadata.QuoteCurrency = "BTC";
78+
}
79+
80+
return await ExchangeMarketSymbolToGlobalMarketSymbolWithSeparatorAsync(
81+
marketSymbolMetadata.BaseCurrency + GlobalMarketSymbolSeparator + marketSymbolMetadata.QuoteCurrency);
6082
}
6183

6284
public override Task<string> GlobalMarketSymbolToExchangeMarketSymbolAsync(

src/ExchangeSharp/API/Exchanges/MEXC/ExchangeMEXCAPI.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,7 @@ private ExchangeMEXCAPI()
2626
RateLimit = new RateGate(20, TimeSpan.FromSeconds(2));
2727
WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas;
2828
}
29-
30-
public override Task<string> ExchangeMarketSymbolToGlobalMarketSymbolAsync(string marketSymbol)
31-
{
32-
var quoteLength = 3;
33-
if (marketSymbol.EndsWith("USDT") ||
34-
marketSymbol.EndsWith("USDC") ||
35-
marketSymbol.EndsWith("TUSD"))
36-
{
37-
quoteLength = 4;
38-
}
39-
40-
var baseSymbol = marketSymbol.Substring(marketSymbol.Length - quoteLength);
41-
42-
return ExchangeMarketSymbolToGlobalMarketSymbolWithSeparatorAsync(
43-
marketSymbol.Replace(baseSymbol, "")
44-
+ GlobalMarketSymbolSeparator
45-
+ baseSymbol);
46-
}
29+
4730

4831
protected override async Task<IEnumerable<string>> OnGetMarketSymbolsAsync()
4932
{

0 commit comments

Comments
 (0)