Skip to content

Commit 2acf765

Browse files
authored
add Exchangeor.exchangeOrderResult.TradeDate (#678)
- nullable value to hold the DateTime of the trade/execution - set value for exchanges that currently have trades implemented
1 parent efe0582 commit 2acf765

File tree

9 files changed

+26
-12
lines changed

9 files changed

+26
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
339339
AmountFilled = result.TotalAmount.Value,
340340
AveragePrice = result.AverageCost?.Value,
341341
FeesCurrency = result.TotalFee.Currency,
342-
CompletedDate = result.DateClosed ?? DateTime.MinValue,
342+
CompletedDate = result.DateClosed,
343+
TradeDate = result.Date,
343344
IsBuy = result.Type == BL3POrderType.Bid,
344345
MarketSymbol = marketSymbol,
345346
OrderDate = result.Date,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ private static ExchangeOrderResult ParseTrade(JToken token, string symbol)
924924
Price = token["price"].ConvertInvariant<decimal>(),
925925
AveragePrice = token["price"].ConvertInvariant<decimal>(),
926926
IsBuy = token["isBuyer"].ConvertInvariant<bool>() == true,
927-
OrderDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["time"].ConvertInvariant<long>()),
927+
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
928+
CompletedDate = null, // order not necessarily fullly filled at this point
929+
TradeDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["time"].ConvertInvariant<long>()),
928930
OrderId = token["orderId"].ToStringInvariant(),
929931
TradeId = token["id"].ToStringInvariant(),
930932
Fees = token["commission"].ConvertInvariant<decimal>(),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class ExecutionReport
5454
[JsonProperty("N")]
5555
public string CommissionAsset { get; set; }
5656
[JsonProperty("T")]
57-
public string TransactionTime { get; set; }
57+
public long TransactionTime { get; set; }
5858
[JsonProperty("t")]
5959
public string TradeId { get; set; }
6060
[JsonProperty("w")]
@@ -92,7 +92,8 @@ public ExchangeOrderResult ExchangeOrderResult
9292
Price = OrderPrice,
9393
AveragePrice = CumulativeQuoteAssetTransactedQuantity / CumulativeFilledQuantity, // Average price can be found by doing Z divided by z.
9494
OrderDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(OrderCreationTime),
95-
CompletedDate = status.IsCompleted() ? (DateTime?)CryptoUtility.UnixTimeStampToDateTimeMilliseconds(EventTime) : null,
95+
CompletedDate = status.IsCompleted() ? (DateTime?)CryptoUtility.UnixTimeStampToDateTimeMilliseconds(TransactionTime) : null,
96+
TradeDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(TransactionTime),
9697
MarketSymbol = Symbol,
9798
// IsBuy is not provided here
9899
Fees = CommissionAmount,

src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ private ExchangeOrderResult TradeHistoryToExchangeOrderResult(JToken token)
385385
{
386386
var res = ParseOrderCore(token);
387387
res.TradeId = token["trade_id"].ToStringInvariant();
388+
res.TradeDate = token["executed_at"].ConvertInvariant<double>().UnixTimeStampToDateTimeMilliseconds();
388389
res.Amount = token["amount"].ConvertInvariant<decimal>();
389390
res.AmountFilled = res.Amount;
390391
res.Fees = token["fee_amount_base"].ConvertInvariant<decimal>();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ private ExchangeOrderResult ParseFill(JToken result)
6565
Fees = fees,
6666
AveragePrice = price,
6767
IsBuy = (result["side"].ToStringInvariant() == "buy"),
68-
OrderDate = result["created_at"].ToDateTimeInvariant(),
68+
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
69+
CompletedDate = null, // order not necessarily fully filled at this point
70+
TradeDate = result["created_at"].ToDateTimeInvariant(), // even though it is named "created_at", the documentation says that it is the: timestamp of fill
6971
MarketSymbol = symbol,
7072
OrderId = result["order_id"].ToStringInvariant(),
7173
};

src/ExchangeSharp/API/Exchanges/Coinbase/Models/Response/Messages.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ internal class Match : BaseMessage
182182
IsAmountFilledReversed = false, // the size here appears to be amount filled, no no need to reverse
183183
Price = Price,
184184
AveragePrice = Price, // not specified here
185-
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate
185+
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
186186
CompletedDate = null, // order not necessarily fullly filled at this point
187+
TradeDate = Time.ToDateTimeInvariant(),
187188
MarketSymbol = ProductId,
188189
IsBuy = Side == OrderSide.Buy,
189190
Fees = (MakerFeeRate ?? TakerFeeRate) * Price * Size,

src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetCompletedOr
356356
AmountFilled = x["amount"].ConvertInvariant<decimal>(),
357357
Fees = x["fee"].ConvertInvariant<decimal>(),
358358
FeesCurrency = x["fee_currency"].ToStringInvariant(),
359-
CompletedDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(x["timestamp"].ConvertInvariant<long>()),
359+
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
360+
CompletedDate = null, // order not necessarily fully filled at this point
361+
TradeDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(x["timestamp"].ConvertInvariant<long>()),
360362
IsBuy = x["side"].ToStringLowerInvariant() == "buy",
361363
Result = ExchangeAPIOrderResult.Unknown,
362364
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ private async Task<ExchangeOrderResult> ParseHistoryOrder(string orderId, JToken
239239
ExchangeOrderResult orderResult = new ExchangeOrderResult { OrderId = orderId };
240240
orderResult.Result = ExchangeAPIOrderResult.Filled;
241241
orderResult.Message = "";
242-
orderResult.OrderDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());
243242
orderResult.MarketSymbol = order["pair"].ToStringInvariant();
244243
orderResult.IsBuy = (order["type"].ToStringInvariant() == "buy");
245244
orderResult.Amount = order["vol"].ConvertInvariant<decimal>();
@@ -249,7 +248,9 @@ private async Task<ExchangeOrderResult> ParseHistoryOrder(string orderId, JToken
249248
orderResult.TradeId = order["postxid"].ToStringInvariant(); //verify which is orderid & tradeid
250249
orderResult.OrderId = order["ordertxid"].ToStringInvariant(); //verify which is orderid & tradeid
251250
orderResult.AmountFilled = order["vol"].ConvertInvariant<decimal>();
252-
orderResult.CompletedDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());
251+
// orderResult.OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
252+
orderResult.CompletedDate = null; // order not necessarily fully filled at this point
253+
orderResult.TradeDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());
253254

254255
string[] pairs = (await ExchangeMarketSymbolToGlobalMarketSymbolAsync(order["pair"].ToStringInvariant())).Split('-');
255256
orderResult.FeesCurrency = pairs[1];

src/ExchangeSharp/Model/ExchangeOrderResult.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ public sealed class ExchangeOrderResult
8888
/// <summary>The id of the trade if this is only one trade out of the order.</summary>
8989
public string TradeId { get; set; }
9090

91-
/// <summary>Append another order to this order - order id and type must match</summary>
92-
/// <param name="other">Order to append</param>
93-
public void AppendOrderWithOrder(ExchangeOrderResult other)
91+
/// <summary>datetime in UTC of the trade. Null if not a trade.</summary>
92+
public DateTime? TradeDate { get; set; }
93+
94+
/// <summary>Append another order to this order - order id and type must match</summary>
95+
/// <param name="other">Order to append</param>
96+
public void AppendOrderWithOrder(ExchangeOrderResult other)
9497
{
9598
if ((OrderId != null) && (MarketSymbol != null) && ((OrderId != other.OrderId) || (IsBuy != other.IsBuy) || (MarketSymbol != other.MarketSymbol)))
9699
{

0 commit comments

Comments
 (0)