Skip to content

Commit

Permalink
Create empty result packet for live trading
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Jul 8, 2020
1 parent aa0dfc7 commit bab6358
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 15 additions & 0 deletions Common/Packets/LiveResultPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using QuantConnect.Logging;
using QuantConnect.Orders;
using QuantConnect.Securities;

namespace QuantConnect.Packets
Expand Down Expand Up @@ -124,6 +125,20 @@ public LiveResultPacket(LiveNodePacket job, LiveResult results)
Log.Error(err);
}
}

/// <summary>
/// Creates an empty result packet, useful when the algorithm fails to initialize
/// </summary>
/// <param name="job">The associated job packet</param>
/// <returns>An empty result packet</returns>
public static LiveResultPacket CreateEmpty(LiveNodePacket job)
{
return new LiveResultPacket(job, new LiveResult(new LiveResultParameters(
new Dictionary<string, Chart>(), new Dictionary<int, Order>(), new Dictionary<DateTime, decimal>(),
new Dictionary<string, Holding>(), new CashBook(), new Dictionary<string, string>(),
new Dictionary<string, string>(), new List<OrderEvent>(), new Dictionary<string, string>(),
new AlphaRuntimeStatistics())));
}
} // End Queue Packet:


Expand Down
11 changes: 3 additions & 8 deletions Engine/Results/LiveTradingResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,18 +785,13 @@ protected void SendFinalResult()

//Create a packet:
result = new LiveResultPacket(_job,
new LiveResult(new LiveResultParameters(charts, orders, profitLoss, holdings, Algorithm.Portfolio.CashBook, statisticsResults.Summary, runtime, GetOrderEventsToStore())))
{
ProcessingTime = (DateTime.UtcNow - StartTime).TotalSeconds
};
new LiveResult(new LiveResultParameters(charts, orders, profitLoss, holdings, Algorithm.Portfolio.CashBook, statisticsResults.Summary, runtime, GetOrderEventsToStore())));
}
else
{
result = new LiveResultPacket(_job, new LiveResult())
{
ProcessingTime = (DateTime.UtcNow - StartTime).TotalSeconds
};
result = LiveResultPacket.CreateEmpty(_job);
}
result.ProcessingTime = (DateTime.UtcNow - StartTime).TotalSeconds;

//Store to S3:
StoreResult(result);
Expand Down

0 comments on commit bab6358

Please sign in to comment.