Skip to content

Commit 7fcff44

Browse files
authored
Fixed setting Order.AveragePrice to null when Quantity is zero (DigitalRuby#646)
- also fixed Binance statii: PendingCancel and Error - also fixed fetching only Open orders on Coinbase OnGetOpenOrderDetailsAsync()
1 parent 64df0ee commit 7fcff44

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
335335
Price = result.Price.Value,
336336
Result = result.Status.ToResult(result.TotalAmount),
337337
AmountFilled = result.TotalAmount.Value,
338-
AveragePrice = result.AverageCost?.Value ?? 0M,
338+
AveragePrice = result.AverageCost?.Value,
339339
FeesCurrency = result.TotalFee.Currency,
340340
FillDate = result.DateClosed ?? DateTime.MinValue,
341341
IsBuy = result.Type == BL3POrderType.Bid,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ protected override async Task<IWebSocket> OnGetDeltaOrderBookWebSocketAsync(Acti
318318
});
319319
}
320320

321-
322321
protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100)
323322
{
324323
JToken obj = await MakeJsonRequestAsync<JToken>("/depth?symbol=" + marketSymbol + "&limit=" + maxCount);
@@ -952,7 +951,9 @@ private ExchangeAPIOrderResult ParseExchangeAPIOrderResult(string status, decima
952951
case "CANCELED":
953952
return amountFilled > 0 ? ExchangeAPIOrderResult.FilledPartiallyAndCancelled : ExchangeAPIOrderResult.Canceled;
954953
case "PENDING_CANCEL":
954+
return ExchangeAPIOrderResult.PendingCancel;
955955
case "EXPIRED":
956+
return ExchangeAPIOrderResult.Error;
956957
case "REJECTED":
957958
return ExchangeAPIOrderResult.Canceled;
958959
default:
@@ -1022,7 +1023,7 @@ private void ParseAveragePriceAndFeesFromFills(ExchangeOrderResult result, JToke
10221023
}
10231024
}
10241025

1025-
result.AveragePrice = (totalQuantity == 0 ? 0 : totalCost / totalQuantity);
1026+
result.AveragePrice = (totalQuantity == 0 ? null : (decimal?)(totalCost / totalQuantity));
10261027
}
10271028

10281029
protected override Task ProcessRequestAsync(IHttpWebRequest request, Dictionary<string, object>? payload)

src/ExchangeSharp/API/Exchanges/BinanceGroup/Models/UserDataStream.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace ExchangeSharp.BinanceGroup
99
{
10-
internal class ExecutionReport
10+
public class ExecutionReport
1111
{
1212
[JsonProperty("e")]
1313
public string EventType { get; set; }
@@ -75,7 +75,7 @@ public override string ToString()
7575

7676
}
7777

78-
internal class Order
78+
public class Order
7979
{
8080
[JsonProperty("s")]
8181
public string Symbol { get; set; }
@@ -90,7 +90,7 @@ public override string ToString()
9090
}
9191
}
9292

93-
internal class ListStatus
93+
public class ListStatus
9494
{
9595
[JsonProperty("e")]
9696
public string EventType { get; set; }
@@ -121,7 +121,7 @@ public override string ToString()
121121
}
122122
}
123123

124-
internal class Balance
124+
public class Balance
125125
{
126126
[JsonProperty("a")]
127127
public string Asset { get; set; }
@@ -136,7 +136,7 @@ public override string ToString()
136136
}
137137
}
138138

139-
internal class OutboundAccount
139+
public class OutboundAccount
140140
{
141141
[JsonProperty("e")]
142142
public string EventType { get; set; }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private ExchangeOrderResult ParseOrder(JToken result)
8080
decimal amount = result["size"].ConvertInvariant<decimal>(amountFilled);
8181
decimal price = result["price"].ConvertInvariant<decimal>();
8282
decimal stop_price = result["stop_price"].ConvertInvariant<decimal>();
83-
decimal averagePrice = (amountFilled <= 0m ? 0m : executedValue / amountFilled);
83+
decimal? averagePrice = (amountFilled <= 0m ? null : (decimal?)(executedValue / amountFilled));
8484
decimal fees = result["fill_fees"].ConvertInvariant<decimal>();
8585
string marketSymbol = result["product_id"].ToStringInvariant(result["id"].ToStringInvariant());
8686

@@ -603,7 +603,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
603603
protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
604604
{
605605
List<ExchangeOrderResult> orders = new List<ExchangeOrderResult>();
606-
JArray array = await MakeJsonRequestAsync<JArray>("orders?status=all" + (string.IsNullOrWhiteSpace(marketSymbol) ? string.Empty : "&product_id=" + marketSymbol), null, await GetNoncePayloadAsync(), "GET");
606+
JArray array = await MakeJsonRequestAsync<JArray>("orders?status=open,pending,active" + (string.IsNullOrWhiteSpace(marketSymbol) ? string.Empty : "&product_id=" + marketSymbol), null, await GetNoncePayloadAsync(), "GET");
607607
foreach (JToken token in array)
608608
{
609609
orders.Add(ParseOrder(token));

src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private ExchangeOrderResult ParseOrder(JToken order)
341341
{
342342
decimal amount = order["amount"].ConvertInvariant<decimal>();
343343
decimal amountFilled = amount - order["left"].ConvertInvariant<decimal>();
344-
decimal fillPrice = amountFilled == 0 ? 0 : order["filled_total"].ConvertInvariant<decimal>() / amountFilled;
344+
decimal? fillPrice = amountFilled == 0 ? null : (decimal?)(order["filled_total"].ConvertInvariant<decimal>() / amountFilled);
345345
decimal price = order["price"].ConvertInvariant<decimal>();
346346
var result = new ExchangeOrderResult
347347
{

src/ExchangeSharp/API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private void ParseAveragePriceAndFeesFromFills(ExchangeOrderResult result, JToke
375375
}
376376
}
377377

378-
result.AveragePrice = (totalQuantity == 0 ? 0 : totalCost / totalQuantity);
378+
result.AveragePrice = (totalQuantity == 0 ? null : (decimal?)(totalCost / totalQuantity));
379379
}
380380

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

0 commit comments

Comments
 (0)