コード例 #1
0
        private void HandleBacktestResultPacket(Packet packet)
        {
            var backtestResultEventModel = (BacktestResultPacket)packet;
            var backtestResultUpdate     = _resultFactory.FromBacktestResult(backtestResultEventModel.Results);

            _result.Add(backtestResultUpdate);
            _syncContext.Send(o => _sessionHandler.HandleResult(_result), null);
        }
コード例 #2
0
        private void ReadFromFile()
        {
            if (!File.Exists(Name))
            {
                throw new Exception($"File '{Name}' does not exist");
            }

            var file = File.ReadAllText(Name);
            var json = JObject.Parse(file);

            // First we try to get thre sults part from a bigger JSON.
            // This can be the case when downloaded from QC.
            try
            {
                JToken resultToken;
                if (json.TryGetValue("results", out resultToken))
                {
                    // Remove the profit-loss part. This is causing problems when downloaded from QC.
                    // TODO: Investigate the problem with the ProfitLoss entry
                    var pl = resultToken.Children().FirstOrDefault(c => c.Path == "results.ProfitLoss");
                    pl?.Remove();

                    // Convert back to string. Our deserializer will get the results part.
                    file = resultToken.ToString();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // We could not parse results from the JSON. Continue and try to parse normally
            }

            Result result;

            try
            {
                var backtestResult = JsonConvert.DeserializeObject <BacktestResult>(file);
                result = _resultFactory.FromBacktestResult(backtestResult);
            }
            catch (Exception ex)
            {
                throw new Exception("The file is no valid Backtest result", ex);
            }

            _resultHandler.HandleResult(result);
        }