Exemplo n.º 1
0
        private void BtnExportStatClick(object sender, EventArgs e)
        {
            if (robotContext.dailyEquityExposure.Count == 0) return;
            var setupForm = new ExportSetupForm();
            if (setupForm.ShowDialog() != DialogResult.OK) return;
            // выбрать файл
            if (saveFileDialog.ShowDialog() != DialogResult.OK) return;

            // сохранить кривую доходности и плечо
            using (var sw = new StreamWriterLog(saveFileDialog.FileName, false, setupForm.ExportEncoding))
            {
                sw.WriteLine(string.Join(new string(setupForm.ColumnSeparator, 1), "Time", "Equity", "Leverage"));
                foreach (var rec in robotContext.dailyEquityExposure)
                {
                    var timeStr = rec.a.ToString(setupForm.DateTimeFormat);
                    var strEq = rec.b.ToStringUniform();
                    var strLev = rec.b.ToStringUniform();
                    if (setupForm.FloatSeparator == ',')
                    {
                        strEq = strEq.Replace('.', ',');
                        strLev = strLev.Replace('.', ',');
                    }
                    var line = string.Join(new string(setupForm.ColumnSeparator, 1),
                                           timeStr, strEq, strLev);
                    sw.WriteLine(line);
                }
            }
        }
Exemplo n.º 2
0
 public void SaveSettings()
 {
     var doc = new XmlDocument();
     doc.AppendChild(doc.CreateElement("settings"));
     PropertyXMLTagAttribute.SaveObjectProperties(this, doc.DocumentElement);
     using (var sw = new StreamWriterLog(fileName, false, Encoding.Unicode))
     {
         using (var xw = new XmlTextWriter(sw) { Formatting = Formatting.Indented })
         {
             doc.Save(xw);
         }
     }
 }
Exemplo n.º 3
0
        public void SaveSettings()
        {
            var doc = new XmlDocument();
            var docNode = (XmlElement)doc.AppendChild(doc.CreateElement("settings"));
            try
            {
                lock (this)
                {
                    PropertyXMLTagAttribute.SaveObjectProperties(this, docNode);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка преобразования настроек в формат XML", ex);
                return;
            }

            try
            {
                using (var sw = new StreamWriterLog(filePath, false, Encoding.Unicode))
                {
                    using (var xw = new XmlTextWriter(sw) {Formatting = Formatting.Indented})
                    {
                        lock (this)
                        {
                            doc.Save(xw);
                            Logger.Info("Файл настроек сохранен (" + filePath + ")");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Ошибка сохранения файла настроек {0}: {1}",
                    filePath, ex);
            }
        }
Exemplo n.º 4
0
 public static void SaveRobots(List<BaseRobot> robots, string path)
 {
     var doc = new XmlDocument();
     var xmlNode = (XmlElement)doc.AppendChild(doc.CreateElement("RobotsPortfolio"));
     foreach (var robot in robots)
     {
         var xmlChild = (XmlElement)xmlNode.AppendChild(doc.CreateElement("robot"));
         PropertyXMLTagAttribute.SaveObjectProperties(robot, xmlChild);
     }
     using (var sw = new StreamWriterLog(path, false))
     {
         using (var xw = new XmlTextWriter(sw) { Formatting = Formatting.Indented })
         {
             doc.Save(xw);
         }
     }
 }