Skip to content

Commit 9cf6379

Browse files
committed
Refactor global currency and creation of exchange api
Exchange API now uses private constructor, and provides methods to get an exchange by type rather than by name.
1 parent 7fc36d4 commit 9cf6379

34 files changed

+502
-468
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ When creating a new Exchange API, please do the following:
2626
- Ensure that the unit tests and integrations tests (```ExchangeSharpConsole.exe test exchangeName=[name]```) pass before submitting a pull request.
2727
- Set needed properties in the constructor of the exchange, such as NonceStyle, NonceEndPoint, NonceEndPointField, NonceEndPointStyle and any property in /API/Exchanges/_Base/ExchangeAPIDefinitions.cs.
2828
- If you have very custom nonce offset calculation logic, you can override OnGetNonceOffset, but please do only if absolutely necessary.
29+
- Exchange implementation classes should be sealed and have a private constructor.
30+
- One-time exchange initialization can be performed by overring `OnInitializeAsync()`.
2931

3032

3133

src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed partial class ExchangeAquanowAPI : ExchangeAPI
2626
public string MarketUrl { get; set; } = "https://market.aquanow.io";
2727
public override string BaseUrlWebSocket { get; set; } = "wss://market.aquanow.io/";
2828

29-
public ExchangeAquanowAPI()
29+
private ExchangeAquanowAPI()
3030
{
3131
NonceStyle = NonceStyle.UnixMilliseconds;
3232
RequestContentType = "application/x-www-form-urlencoded";

src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class ExchangeBL3PAPI : ExchangeAPI
3131
/// </summary>
3232
public BL3PCurrencyFee DefaultFeeCurrency { get; set; } = BL3PCurrencyFee.BTC;
3333

34-
public ExchangeBL3PAPI()
34+
private ExchangeBL3PAPI()
3535
{
3636
MarketSymbolIsUppercase = true;
3737
MarketSymbolIsReversed = true;

src/ExchangeSharp/API/Exchanges/BTSE/ExchangeBTSEAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed partial class ExchangeBTSEAPI : ExchangeAPI
1313
public override string BaseUrl { get; set; } = "https://api.btse.com/spot";
1414
public const string TestnetUrl = "https://testapi.btse.io/spot";
1515

16-
public ExchangeBTSEAPI()
16+
private ExchangeBTSEAPI()
1717
{
1818
NonceStyle = NonceStyle.UnixMillisecondsString;
1919
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ public abstract class BinanceGroupCommon : ExchangeAPI
3131

3232
public const string GetCurrenciesUrl = "/assetWithdraw/getAllAsset.html";
3333

34-
static BinanceGroupCommon()
35-
{
36-
ExchangeGlobalCurrencyReplacements[typeof(BinanceGroupCommon)] = new KeyValuePair<string, string>[]
37-
{
38-
new KeyValuePair<string, string>("BCC", "BCH")
39-
};
40-
}
41-
4234
protected async Task<string> GetWebSocketStreamUrlForSymbolsAsync(string suffix, params string[] marketSymbols)
4335
{
4436
if (marketSymbols == null || marketSymbols.Length == 0)
@@ -67,6 +59,7 @@ protected BinanceGroupCommon()
6759
NonceOffset = TimeSpan.FromSeconds(15); // 15 seconds are deducted from current UTCTime as base of the request time window
6860
MarketSymbolSeparator = string.Empty;
6961
WebSocketOrderBookType = WebSocketOrderBookType.DeltasOnly;
62+
ExchangeGlobalCurrencyReplacements["BCC"] = "BCH";
7063
}
7164

7265
public override Task<string> ExchangeMarketSymbolToGlobalMarketSymbolAsync(string marketSymbol)

src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,15 @@ public sealed partial class ExchangeBitBankAPI : ExchangeAPI
1818
private const decimal MakerFee = -0.0005m;
1919
private const decimal TakerFee = 0.0015m;
2020

21-
static ExchangeBitBankAPI()
22-
{
23-
ExchangeGlobalCurrencyReplacements[typeof(ExchangeBitBankAPI)] = new KeyValuePair<string, string>[]
24-
{
25-
new KeyValuePair<string, string>("BCC", "BCH")
26-
};
27-
}
28-
29-
public ExchangeBitBankAPI()
21+
private ExchangeBitBankAPI()
3022
{
3123
NonceStyle = NonceStyle.UnixMilliseconds;
3224
NonceOffset = TimeSpan.FromSeconds(0.1);
3325
WebSocketOrderBookType = WebSocketOrderBookType.DeltasOnly;
3426
MarketSymbolSeparator = "_";
3527
MarketSymbolIsUppercase = false;
36-
}
28+
ExchangeGlobalCurrencyReplacements["BCC"] = "BCH";
29+
}
3730

3831
# region Public APIs
3932

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

Lines changed: 2 additions & 2 deletions
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
@@ -33,7 +33,7 @@ public sealed partial class ExchangeBitMEXAPI : ExchangeAPI
3333
private SortedDictionary<long, decimal> dict_long_decimal = new SortedDictionary<long, decimal>();
3434
private SortedDictionary<decimal, long> dict_decimal_long = new SortedDictionary<decimal, long>();
3535

36-
public ExchangeBitMEXAPI()
36+
private ExchangeBitMEXAPI()
3737
{
3838
RequestWindow = TimeSpan.Zero;
3939
NonceStyle = NonceStyle.ExpiresUnixSeconds;

src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ namespace ExchangeSharp {
2424
using System.Text.RegularExpressions;
2525
using System.Threading.Tasks;
2626

27-
public sealed partial class ExchangeBitfinexAPI :ExchangeAPI {
27+
public sealed partial class ExchangeBitfinexAPI :ExchangeAPI
28+
{
2829
public override string BaseUrl { get; set; } = "https://api.bitfinex.com/v2";
2930
public override string BaseUrlWebSocket { get; set; } = "wss://api.bitfinex.com/ws";
3031

3132
public Dictionary<string, string> DepositMethodLookup { get; }
3233

3334
public string BaseUrlV1 { get; set; } = "https://api.bitfinex.com/v1";
3435

35-
public ExchangeBitfinexAPI()
36+
private ExchangeBitfinexAPI()
3637
{
3738
NonceStyle = NonceStyle.UnixMillisecondsString;
3839
RateLimit = new RateGate(1, TimeSpan.FromSeconds(6.0));

src/ExchangeSharp/API/Exchanges/Bithumb/ExchangeBithumbAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed partial class ExchangeBithumbAPI : ExchangeAPI
2222
{
2323
public override string BaseUrl { get; set; } = "https://api.bithumb.com";
2424

25-
public ExchangeBithumbAPI()
25+
private ExchangeBithumbAPI()
2626
{
2727
MarketSymbolIsUppercase = true;
2828
}

src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public string CustomerId
3535
set { Passphrase = value.ToSecureString(); }
3636
}
3737

38-
/// <summary>
39-
/// In order to use private functions of the API, you must set CustomerId by calling constructor with parameter,
40-
/// or setting it later in the ExchangeBitstampAPI object.
41-
/// </summary>
42-
public ExchangeBitstampAPI()
38+
/// <summary>
39+
/// In order to use private functions of the API, you must set CustomerId by calling constructor with parameter,
40+
/// or setting it later in the ExchangeBitstampAPI object.
41+
/// </summary>
42+
private ExchangeBitstampAPI()
4343
{
4444
RequestContentType = "application/x-www-form-urlencoded";
4545
NonceStyle = NonceStyle.UnixMilliseconds;

0 commit comments

Comments
 (0)