Skip to content

Commit 7816c3b

Browse files
authored
[Binance] Allow market order without price (#653)
Set order CesultCode
1 parent b0a35c5 commit 7816c3b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
547547

548548
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order)
549549
{
550-
if (order.Price == null) throw new ArgumentNullException(nameof(order.Price));
550+
if (order.Price == null && order.OrderType != OrderType.Market) throw new ArgumentNullException(nameof(order.Price));
551+
551552
Dictionary<string, object> payload = await GetNoncePayloadAsync();
552553
payload["symbol"] = order.MarketSymbol;
553554
payload["newClientOrderId"] = order.ClientOrderId;
@@ -564,14 +565,14 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
564565

565566
// Binance has strict rules on which prices and quantities are allowed. They have to match the rules defined in the market definition.
566567
decimal outputQuantity = await ClampOrderQuantity(order.MarketSymbol, order.Amount);
567-
decimal outputPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
568568

569569
// Binance does not accept quantities with more than 20 decimal places.
570570
payload["quantity"] = Math.Round(outputQuantity, 20);
571571
payload["newOrderRespType"] = "FULL";
572572

573573
if (order.OrderType != OrderType.Market)
574574
{
575+
decimal outputPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value);
575576
payload["timeInForce"] = "GTC";
576577
payload["price"] = outputPrice;
577578
}
@@ -942,7 +943,8 @@ private ExchangeOrderResult ParseOrder(JToken token)
942943
ClientOrderId = token["clientOrderId"].ToStringInvariant()
943944
};
944945

945-
result.Result = ParseExchangeAPIOrderResult(token["status"].ToStringInvariant(), result.AmountFilled);
946+
result.ResultCode = token["status"].ToStringInvariant();
947+
result.Result = ParseExchangeAPIOrderResult(result.ResultCode, result.AmountFilled);
946948
ParseAveragePriceAndFeesFromFills(result, token["fills"]);
947949

948950
return result;

0 commit comments

Comments
 (0)