Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed setting Order.AveragePrice to null when Quantity is zero #646

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
Price = result.Price.Value,
Result = result.Status.ToResult(result.TotalAmount),
AmountFilled = result.TotalAmount.Value,
AveragePrice = result.AverageCost?.Value ?? 0M,
AveragePrice = result.AverageCost?.Value,
FeesCurrency = result.TotalFee.Currency,
FillDate = result.DateClosed ?? DateTime.MinValue,
IsBuy = result.Type == BL3POrderType.Bid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ protected override async Task<IWebSocket> OnGetDeltaOrderBookWebSocketAsync(Acti
});
}


protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100)
{
JToken obj = await MakeJsonRequestAsync<JToken>("/depth?symbol=" + marketSymbol + "&limit=" + maxCount);
Expand Down Expand Up @@ -952,7 +951,9 @@ private ExchangeAPIOrderResult ParseExchangeAPIOrderResult(string status, decima
case "CANCELED":
return amountFilled > 0 ? ExchangeAPIOrderResult.FilledPartiallyAndCancelled : ExchangeAPIOrderResult.Canceled;
case "PENDING_CANCEL":
return ExchangeAPIOrderResult.PendingCancel;
case "EXPIRED":
return ExchangeAPIOrderResult.Error;
case "REJECTED":
return ExchangeAPIOrderResult.Canceled;
default:
Expand Down Expand Up @@ -1022,7 +1023,7 @@ private void ParseAveragePriceAndFeesFromFills(ExchangeOrderResult result, JToke
}
}

result.AveragePrice = (totalQuantity == 0 ? 0 : totalCost / totalQuantity);
result.AveragePrice = (totalQuantity == 0 ? null : (decimal?)(totalCost / totalQuantity));
}

protected override Task ProcessRequestAsync(IHttpWebRequest request, Dictionary<string, object>? payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ExchangeSharp.BinanceGroup
{
internal class ExecutionReport
public class ExecutionReport
{
[JsonProperty("e")]
public string EventType { get; set; }
Expand Down Expand Up @@ -75,7 +75,7 @@ public override string ToString()

}

internal class Order
public class Order
{
[JsonProperty("s")]
public string Symbol { get; set; }
Expand All @@ -90,7 +90,7 @@ public override string ToString()
}
}

internal class ListStatus
public class ListStatus
{
[JsonProperty("e")]
public string EventType { get; set; }
Expand Down Expand Up @@ -121,7 +121,7 @@ public override string ToString()
}
}

internal class Balance
public class Balance
{
[JsonProperty("a")]
public string Asset { get; set; }
Expand All @@ -136,7 +136,7 @@ public override string ToString()
}
}

internal class OutboundAccount
public class OutboundAccount
{
[JsonProperty("e")]
public string EventType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private ExchangeOrderResult ParseOrder(JToken result)
decimal amount = result["size"].ConvertInvariant<decimal>(amountFilled);
decimal price = result["price"].ConvertInvariant<decimal>();
decimal stop_price = result["stop_price"].ConvertInvariant<decimal>();
decimal averagePrice = (amountFilled <= 0m ? 0m : executedValue / amountFilled);
decimal? averagePrice = (amountFilled <= 0m ? null : (decimal?)(executedValue / amountFilled));
decimal fees = result["fill_fees"].ConvertInvariant<decimal>();
string marketSymbol = result["product_id"].ToStringInvariant(result["id"].ToStringInvariant());

Expand Down Expand Up @@ -603,7 +603,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
{
List<ExchangeOrderResult> orders = new List<ExchangeOrderResult>();
JArray array = await MakeJsonRequestAsync<JArray>("orders?status=all" + (string.IsNullOrWhiteSpace(marketSymbol) ? string.Empty : "&product_id=" + marketSymbol), null, await GetNoncePayloadAsync(), "GET");
JArray array = await MakeJsonRequestAsync<JArray>("orders?status=open,pending,active" + (string.IsNullOrWhiteSpace(marketSymbol) ? string.Empty : "&product_id=" + marketSymbol), null, await GetNoncePayloadAsync(), "GET");
foreach (JToken token in array)
{
orders.Add(ParseOrder(token));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private ExchangeOrderResult ParseOrder(JToken order)
{
decimal amount = order["amount"].ConvertInvariant<decimal>();
decimal amountFilled = amount - order["left"].ConvertInvariant<decimal>();
decimal fillPrice = amountFilled == 0 ? 0 : order["filled_total"].ConvertInvariant<decimal>() / amountFilled;
decimal? fillPrice = amountFilled == 0 ? null : (decimal?)(order["filled_total"].ConvertInvariant<decimal>() / amountFilled);
decimal price = order["price"].ConvertInvariant<decimal>();
var result = new ExchangeOrderResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private void ParseAveragePriceAndFeesFromFills(ExchangeOrderResult result, JToke
}
}

result.AveragePrice = (totalQuantity == 0 ? 0 : totalCost / totalQuantity);
result.AveragePrice = (totalQuantity == 0 ? null : (decimal?)(totalCost / totalQuantity));
}

protected override async Task<ExchangeDepositDetails> OnGetDepositAddressAsync(string currency, bool forceRegenerate = false)
Expand Down