Skip to content

Commit 9717725

Browse files
committed
Add null checks for Order.Price
1 parent 1da81ae commit 9717725

File tree

10 files changed

+16
-4
lines changed

10 files changed

+16
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
252252
switch (order.OrderType)
253253
{
254254
case OrderType.Limit:
255+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
255256
data["price_int"] = converterToFive.FromDecimal(order.Price.Value);
256257
break;
257258
case OrderType.Market:
259+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
258260
data["amount_funds_int"] = converterToFive.FromDecimal(roundedAmount * order.Price.Value);
259261
break;
260262
default:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
548548

549549
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order)
550550
{
551+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
551552
Dictionary<string, object> payload = await GetNoncePayloadAsync();
552553
payload["symbol"] = order.MarketSymbol;
553554
payload["newClientOrderId"] = order.ClientOrderId;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
481481

482482
if (order.OrderType != OrderType.Market)
483483
{
484+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
484485
payload["price"] = (await ClampOrderPrice(marketSymbol, order.Price.Value)).ToStringInvariant();
485486
}
486487
else

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
202202

203203
if (order.OrderType != OrderType.Market)
204204
{
205-
payload["price"] = order.Price.ToStringInvariant();
205+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
206+
payload["price"] = order.Price.ToStringInvariant();
206207
}
207208

208209
payload["amount"] = order.RoundAmount().ToStringInvariant();

src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
378378
{
379379

380380
decimal orderAmount = await ClampOrderQuantity(order.MarketSymbol, order.Amount);
381+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
381382
decimal orderPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
382383
string url = "/orders";
383384
Dictionary<string, object> orderParams = await GetNoncePayloadAsync();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,14 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
573573
// set payload["post_only"] to true for default scenario when order.ExtraParameters["post_only"] is not specified
574574
// to place non-post-only limit order one can set and pass order.ExtraParameters["post_only"]="false"
575575
payload["post_only"] = order.ExtraParameters.TryGetValueOrDefault("post_only", "true");
576+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
576577
payload["price"] = order.Price.ToStringInvariant();
577578
break;
578579

579580
case OrderType.Stop:
580581
payload["stop"] = (order.IsBuy ? "entry" : "loss");
581582
payload["stop_price"] = order.StopPrice.ToStringInvariant();
583+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
582584
payload["type"] = order.Price > 0m ? "limit" : "market";
583585
break;
584586

src/ExchangeSharp/API/Exchanges/Huobi/ExchangeHuobiAPI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
693693
else
694694
{
695695
payload["type"] += "-limit";
696-
payload["price"] = outputPrice.ToStringInvariant();
696+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
697+
payload["price"] = outputPrice.ToStringInvariant();
697698
}
698699

699700
order.ExtraParameters.CopyTo(payload);

src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
761761
if (order.OrderType != OrderType.Market)
762762
{
763763
int precision = BitConverter.GetBytes(Decimal.GetBits((decimal)market.PriceStepSize)[3])[2];
764+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
764765
payload.Add("price", Math.Round(order.Price.Value, precision).ToStringInvariant());
765766
}
766767
order.ExtraParameters.CopyTo(payload);

src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
413413

414414
// Okex has strict rules on which prices and quantities are allowed. They have to match the rules defined in the market definition.
415415
decimal outputQuantity = await ClampOrderQuantity(order.MarketSymbol, order.Amount);
416-
decimal outputPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
416+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
417+
decimal outputPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
417418

418419
if (order.OrderType == OrderType.Market)
419420
{

src/ExchangeSharp/API/Exchanges/Poloniex/ExchangePoloniexAPI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,8 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
769769
}
770770

771771
decimal orderAmount = await ClampOrderQuantity(order.MarketSymbol, order.Amount);
772-
decimal orderPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
772+
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
773+
decimal orderPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
773774

774775
List<object> orderParams = new List<object>
775776
{

0 commit comments

Comments
 (0)