Exemple #1
0
        /// <summary>
        /// Send a generic base packet without processing
        /// </summary>
        public void Send(Packet packet)
        {
            switch (packet.Type)
            {
            case PacketType.Debug:
                var debug = (DebugPacket)packet;
                Log.Trace("Debug: " + debug.Message);
                break;

            case PacketType.SystemDebug:
                var systemDebug = (SystemDebugPacket)packet;
                Log.Trace("Debug: " + systemDebug.Message);
                break;

            case PacketType.Log:
                var log = (LogPacket)packet;
                Log.Trace("Log: " + log.Message);
                break;

            case PacketType.RuntimeError:
                var runtime = (RuntimeErrorPacket)packet;
                var rstack  = (!string.IsNullOrEmpty(runtime.StackTrace) ? (Environment.NewLine + " " + runtime.StackTrace) : string.Empty);
                Log.Error(runtime.Message + rstack);
                break;

            case PacketType.HandledError:
                var handled = (HandledErrorPacket)packet;
                var hstack  = (!string.IsNullOrEmpty(handled.StackTrace) ? (Environment.NewLine + " " + handled.StackTrace) : string.Empty);
                Log.Error(handled.Message + hstack);
                break;

            case PacketType.AlphaResult:
                // spams the logs
                //var insights = ((AlphaResultPacket) packet).Insights;
                //foreach (var insight in insights)
                //{
                //    Log.Trace("Insight: " + insight);
                //}
                break;

            case PacketType.BacktestResult:
                var result = (BacktestResultPacket)packet;

                if (result.Progress == 1)
                {
                    // inject alpha statistics into backtesting result statistics
                    // this is primarily so we can easily regression test these values
                    var alphaStatistics = result.Results.AlphaRuntimeStatistics?.ToDictionary().ToList() ?? new List <KeyValuePair <string, string> >();
                    alphaStatistics.ForEach(kvp => result.Results.Statistics.Add(kvp));

                    var orderHash = result.Results.Orders.GetHash();
                    result.Results.Statistics.Add("OrderListHash", orderHash.ToString(CultureInfo.InvariantCulture));

                    if (UpdateRegressionStatistics && _job.Language == Language.CSharp)
                    {
                        UpdateRegressionStatisticsInSourceFile(result);
                    }

                    var statisticsStr = $"{Environment.NewLine}" +
                                        $"{string.Join(Environment.NewLine,result.Results.Statistics.Select(x => $"STATISTICS:: {x.Key} {x.Value}"))}";
                    Log.Trace(statisticsStr);
                }
                break;
            }


            if (StreamingApi.IsEnabled)
            {
                StreamingApi.Transmit(_job.UserId, _job.Channel, packet);
            }
        }
Exemple #2
0
        /// <summary>
        /// Send a generic base packet without processing
        /// </summary>
        public void Send(Packet packet)
        {
            switch (packet.Type)
            {
            case PacketType.Debug:
                var debug = (DebugPacket)packet;
                Log.Trace("Debug: " + debug.Message);
                break;

            case PacketType.SystemDebug:
                var systemDebug = (SystemDebugPacket)packet;
                Log.Trace("Debug: " + systemDebug.Message);
                break;

            case PacketType.Log:
                var log = (LogPacket)packet;
                Log.Trace("Log: " + log.Message);
                break;

            case PacketType.RuntimeError:
                var runtime = (RuntimeErrorPacket)packet;
                var rstack  = (!string.IsNullOrEmpty(runtime.StackTrace) ? (Environment.NewLine + " " + runtime.StackTrace) : string.Empty);
                Log.Error(runtime.Message + rstack);
                break;

            case PacketType.HandledError:
                var handled = (HandledErrorPacket)packet;
                var hstack  = (!string.IsNullOrEmpty(handled.StackTrace) ? (Environment.NewLine + " " + handled.StackTrace) : string.Empty);
                Log.Error(handled.Message + hstack);
                break;

            case PacketType.AlphaResult:
                // spams the logs
                //var insights = ((AlphaResultPacket) packet).Insights;
                //foreach (var insight in insights)
                //{
                //    Log.Trace("Insight: " + insight);
                //}
                break;

            case PacketType.BacktestResult:
                var result = (BacktestResultPacket)packet;

                if (result.Progress == 1)
                {
                    // uncomment these code traces to help write regression tests
                    //Console.WriteLine("new Dictionary<string, string>");
                    //Console.WriteLine("\t\t\t{");

                    // inject alpha statistics into backtesting result statistics
                    // this is primarily so we can easily regression test these values
                    var alphaStatistics = result.Results.AlphaRuntimeStatistics?.ToDictionary().ToList() ?? new List <KeyValuePair <string, string> >();
                    alphaStatistics.ForEach(kvp => result.Results.Statistics.Add(kvp));

                    foreach (var pair in result.Results.Statistics)
                    {
                        Log.Trace($"STATISTICS:: {pair.Key} {pair.Value}");
                        //Console.WriteLine("\t\t\t\t{{\"{0}\",\"{1}\"}},", pair.Key, pair.Value);
                    }
                    //Console.WriteLine("\t\t\t};");

                    //foreach (var pair in statisticsResults.RollingPerformances)
                    //{
                    //    Log.Trace("ROLLINGSTATS:: " + pair.Key + " SharpeRatio: " + Math.Round(pair.Value.PortfolioStatistics.SharpeRatio, 3));
                    //}
                }
                break;
            }


            if (StreamingApi.IsEnabled)
            {
                StreamingApi.Transmit(_job.UserId, _job.Channel, packet);
            }
        }