Skip to content

Commit 786de5e

Browse files
authored
change ExchangeMarket properties to nullable (#730)
- Not all exchanges provide every property. Instead of returning a value like decimal.MaxValue or 0, null should be returned instead. That way, the user cna decide how to handle it.
1 parent fbcc1e3 commit 786de5e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected internal override async Task<IEnumerable<ExchangeMarket>> OnGetMarketS
210210

211211
protected override async Task<IEnumerable<string>> OnGetMarketSymbolsAsync()
212212
{
213-
return (await GetMarketSymbolsMetadataAsync()).Where(market => market.IsActive).Select(market => market.MarketSymbol);
213+
return (await GetMarketSymbolsMetadataAsync()).Where(market => market.IsActive ?? true).Select(market => market.MarketSymbol);
214214
}
215215

216216
protected override async Task<IReadOnlyDictionary<string, ExchangeCurrency>> OnGetCurrenciesAsync()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ protected virtual Task<IWebSocket> OnUserDataWebSocketAsync(Action<object> callb
245245
protected async Task<decimal> ClampOrderPrice(string marketSymbol, decimal outputPrice)
246246
{
247247
ExchangeMarket? market = await GetExchangeMarketFromCacheAsync(marketSymbol);
248-
return market == null ? outputPrice : CryptoUtility.ClampDecimal(market.MinPrice, market.MaxPrice, market.PriceStepSize, outputPrice);
248+
if (market.MinPrice == null || market.MaxPrice == null || market.PriceStepSize == null)
249+
throw new NotImplementedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderPrice)}() to work");
250+
else return market == null ? outputPrice : CryptoUtility.ClampDecimal(market.MinPrice.Value, market.MaxPrice.Value, market.PriceStepSize, outputPrice);
249251
}
250252

251253
/// <summary>
@@ -257,7 +259,9 @@ protected async Task<decimal> ClampOrderPrice(string marketSymbol, decimal outpu
257259
protected async Task<decimal> ClampOrderQuantity(string marketSymbol, decimal outputQuantity)
258260
{
259261
ExchangeMarket? market = await GetExchangeMarketFromCacheAsync(marketSymbol);
260-
return market == null ? outputQuantity : CryptoUtility.ClampDecimal(market.MinTradeSize, market.MaxTradeSize, market.QuantityStepSize, outputQuantity);
262+
if (market.MinPrice == null || market.MaxPrice == null || market.PriceStepSize == null)
263+
throw new NotImplementedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderQuantity)}() to work");
264+
else return market == null ? outputQuantity : CryptoUtility.ClampDecimal(market.MinTradeSize.Value, market.MaxTradeSize.Value, market.QuantityStepSize, outputQuantity);
261265
}
262266

263267
/// <summary>

src/ExchangeSharp/Model/ExchangeMarket.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ExchangeMarket
2828
public string AltMarketSymbol2 { get; set; }
2929

3030
/// <summary>A value indicating whether the market is active.</summary>
31-
public bool IsActive { get; set; }
31+
public bool? IsActive { get; set; }
3232

3333
/// <summary>In a pair like ZRX/BTC, BTC is the quote currency.</summary>
3434
public string QuoteCurrency { get; set; }
@@ -38,10 +38,10 @@ public class ExchangeMarket
3838

3939
/// <summary>The minimum size of the trade in the unit of "BaseCurrency". For example, in
4040
/// DOGE/BTC the MinTradeSize is currently 423.72881356 DOGE</summary>
41-
public decimal MinTradeSize { get; set; }
41+
public decimal? MinTradeSize { get; set; }
4242

4343
/// <summary>The maximum size of the trade in the unit of "BaseCurrency".</summary>
44-
public decimal MaxTradeSize { get; set; } = decimal.MaxValue;
44+
public decimal? MaxTradeSize { get; set; }
4545

4646
/// <summary>The minimum size of the trade in the unit of "QuoteCurrency". To determine an order's
4747
/// trade size in terms of the Quote Currency, you need to calculate: price * quantity
@@ -54,10 +54,10 @@ public class ExchangeMarket
5454
public decimal? MaxTradeSizeInQuoteCurrency { get; set; }
5555

5656
/// <summary>The minimum price of the pair.</summary>
57-
public decimal MinPrice { get; set; }
57+
public decimal? MinPrice { get; set; }
5858

5959
/// <summary>The maximum price of the pair.</summary>
60-
public decimal MaxPrice { get; set; } = decimal.MaxValue;
60+
public decimal? MaxPrice { get; set; }
6161

6262
/// <summary>Defines the intervals that a price can be increased/decreased by. The following
6363
/// must be true for price: Price % PriceStepSize == 0 Null if unknown or not applicable.</summary>
@@ -71,7 +71,7 @@ public class ExchangeMarket
7171
/// <summary>
7272
/// Margin trading enabled for this market
7373
/// </summary>
74-
public bool MarginEnabled { get; set; }
74+
public bool? MarginEnabled { get; set; }
7575

7676
public override string ToString()
7777
{

0 commit comments

Comments
 (0)