public static BacktestTradeModel ToTradeModel(this BacktestTrade trade) { if (trade == null) { return(null); } else { var model = new BacktestTradeModel() { CommissionUsd = trade.CommissionUsd, Cross = trade.Cross, OrderId = trade.OrderId, OrderOrigin = trade.OrderOrigin, Price = FormatUtils.FormatRate(trade.Cross, trade.Price), RealizedPnL = trade.RealizedPnL, RealizedPnlPips = trade.RealizedPnlPips, RealizedPnlUsd = trade.RealizedPnlUsd, Side = trade.Side, Size = trade.Size / 1000, SizeUsd = trade.SizeUsd.HasValue ? trade.SizeUsd.Value / 1000 : (double?)null, Timestamp = trade.Timestamp.ToLocalTime(), TradeId = trade.TradeId }; TimeSpan duration; if (TimeSpan.TryParse(trade.Duration, out duration)) { model.Duration = duration; } return(model); } }
public static bool IsShort(this BacktestTradeModel trade) { if (trade == null) { return(false); } return(trade.Side == ExecutionSide.SOLD); }
public static bool IsLong(this BacktestTradeModel trade) { if (trade == null) { return(false); } return(trade.Side == ExecutionSide.BOUGHT); }
public static bool IsPositionContinuing(this BacktestTradeModel trade) { return(trade != null && OrderOriginUtils.PositionContinueOrigins.Contains(trade.OrderOrigin)); }