Skip to content

add ExchangeOrderResult.TradeDate #678

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

Merged
merged 1 commit into from
Oct 12, 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
3 changes: 2 additions & 1 deletion src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
AmountFilled = result.TotalAmount.Value,
AveragePrice = result.AverageCost?.Value,
FeesCurrency = result.TotalFee.Currency,
CompletedDate = result.DateClosed ?? DateTime.MinValue,
CompletedDate = result.DateClosed,
TradeDate = result.Date,
IsBuy = result.Type == BL3POrderType.Bid,
MarketSymbol = marketSymbol,
OrderDate = result.Date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ private static ExchangeOrderResult ParseTrade(JToken token, string symbol)
Price = token["price"].ConvertInvariant<decimal>(),
AveragePrice = token["price"].ConvertInvariant<decimal>(),
IsBuy = token["isBuyer"].ConvertInvariant<bool>() == true,
OrderDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["time"].ConvertInvariant<long>()),
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
CompletedDate = null, // order not necessarily fullly filled at this point
TradeDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["time"].ConvertInvariant<long>()),
OrderId = token["orderId"].ToStringInvariant(),
TradeId = token["id"].ToStringInvariant(),
Fees = token["commission"].ConvertInvariant<decimal>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class ExecutionReport
[JsonProperty("N")]
public string CommissionAsset { get; set; }
[JsonProperty("T")]
public string TransactionTime { get; set; }
public long TransactionTime { get; set; }
[JsonProperty("t")]
public string TradeId { get; set; }
[JsonProperty("w")]
Expand Down Expand Up @@ -92,7 +92,8 @@ public ExchangeOrderResult ExchangeOrderResult
Price = OrderPrice,
AveragePrice = CumulativeQuoteAssetTransactedQuantity / CumulativeFilledQuantity, // Average price can be found by doing Z divided by z.
OrderDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(OrderCreationTime),
CompletedDate = status.IsCompleted() ? (DateTime?)CryptoUtility.UnixTimeStampToDateTimeMilliseconds(EventTime) : null,
CompletedDate = status.IsCompleted() ? (DateTime?)CryptoUtility.UnixTimeStampToDateTimeMilliseconds(TransactionTime) : null,
TradeDate = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(TransactionTime),
MarketSymbol = Symbol,
// IsBuy is not provided here
Fees = CommissionAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ private ExchangeOrderResult TradeHistoryToExchangeOrderResult(JToken token)
{
var res = ParseOrderCore(token);
res.TradeId = token["trade_id"].ToStringInvariant();
res.TradeDate = token["executed_at"].ConvertInvariant<double>().UnixTimeStampToDateTimeMilliseconds();
res.Amount = token["amount"].ConvertInvariant<decimal>();
res.AmountFilled = res.Amount;
res.Fees = token["fee_amount_base"].ConvertInvariant<decimal>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private ExchangeOrderResult ParseFill(JToken result)
Fees = fees,
AveragePrice = price,
IsBuy = (result["side"].ToStringInvariant() == "buy"),
OrderDate = result["created_at"].ToDateTimeInvariant(),
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
CompletedDate = null, // order not necessarily fully filled at this point
TradeDate = result["created_at"].ToDateTimeInvariant(), // even though it is named "created_at", the documentation says that it is the: timestamp of fill
MarketSymbol = symbol,
OrderId = result["order_id"].ToStringInvariant(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ internal class Match : BaseMessage
IsAmountFilledReversed = false, // the size here appears to be amount filled, no no need to reverse
Price = Price,
AveragePrice = Price, // not specified here
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
CompletedDate = null, // order not necessarily fullly filled at this point
TradeDate = Time.ToDateTimeInvariant(),
MarketSymbol = ProductId,
IsBuy = Side == OrderSide.Buy,
Fees = (MakerFeeRate ?? TakerFeeRate) * Price * Size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetCompletedOr
AmountFilled = x["amount"].ConvertInvariant<decimal>(),
Fees = x["fee"].ConvertInvariant<decimal>(),
FeesCurrency = x["fee_currency"].ToStringInvariant(),
CompletedDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(x["timestamp"].ConvertInvariant<long>()),
// OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
CompletedDate = null, // order not necessarily fully filled at this point
TradeDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(x["timestamp"].ConvertInvariant<long>()),
IsBuy = x["side"].ToStringLowerInvariant() == "buy",
Result = ExchangeAPIOrderResult.Unknown,
});
Expand Down
5 changes: 3 additions & 2 deletions src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private async Task<ExchangeOrderResult> ParseHistoryOrder(string orderId, JToken
ExchangeOrderResult orderResult = new ExchangeOrderResult { OrderId = orderId };
orderResult.Result = ExchangeAPIOrderResult.Filled;
orderResult.Message = "";
orderResult.OrderDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());
orderResult.MarketSymbol = order["pair"].ToStringInvariant();
orderResult.IsBuy = (order["type"].ToStringInvariant() == "buy");
orderResult.Amount = order["vol"].ConvertInvariant<decimal>();
Expand All @@ -249,7 +248,9 @@ private async Task<ExchangeOrderResult> ParseHistoryOrder(string orderId, JToken
orderResult.TradeId = order["postxid"].ToStringInvariant(); //verify which is orderid & tradeid
orderResult.OrderId = order["ordertxid"].ToStringInvariant(); //verify which is orderid & tradeid
orderResult.AmountFilled = order["vol"].ConvertInvariant<decimal>();
orderResult.CompletedDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());
// orderResult.OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable
orderResult.CompletedDate = null; // order not necessarily fully filled at this point
orderResult.TradeDate = CryptoUtility.UnixTimeStampToDateTimeSeconds(order["time"].ConvertInvariant<double>());

string[] pairs = (await ExchangeMarketSymbolToGlobalMarketSymbolAsync(order["pair"].ToStringInvariant())).Split('-');
orderResult.FeesCurrency = pairs[1];
Expand Down
9 changes: 6 additions & 3 deletions src/ExchangeSharp/Model/ExchangeOrderResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ public sealed class ExchangeOrderResult
/// <summary>The id of the trade if this is only one trade out of the order.</summary>
public string TradeId { get; set; }

/// <summary>Append another order to this order - order id and type must match</summary>
/// <param name="other">Order to append</param>
public void AppendOrderWithOrder(ExchangeOrderResult other)
/// <summary>datetime in UTC of the trade. Null if not a trade.</summary>
public DateTime? TradeDate { get; set; }

/// <summary>Append another order to this order - order id and type must match</summary>
/// <param name="other">Order to append</param>
public void AppendOrderWithOrder(ExchangeOrderResult other)
{
if ((OrderId != null) && (MarketSymbol != null) && ((OrderId != other.OrderId) || (IsBuy != other.IsBuy) || (MarketSymbol != other.MarketSymbol)))
{
Expand Down