Exemplo n.º 1
0
        public void OpenFile(string path)
        {
            Stream file = null;

            try
            {
                MessagePrinter.ClearMsg();
                PLBPanel.Controls.Clear();
                file        = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                data        = new PLB(new PLBReader(file));
                pathCurrent = path;
                fileCurrent = Path.GetFileName(path);
                SetLoaded();
                SetDirty(false);
                MessagePrinter.ShowMsg("There were some issues while opening:", "Warning!");
                CreateTree();
            }
            catch (Exception ex)
            {
                data = null;

                MessageBox.Show(            //show error message
                    "An error occured while opening:\n" + ex.Message,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            finally
            {
                file?.Close();
            }
        }
Exemplo n.º 2
0
        private void Menu_Tools_Import__Click(object sender, EventArgs e)
        {
            //unsaved changes check
            if (IsDirty())
            {
                DialogResult temp = MessageBox.Show(
                    "Unsaved changes exist. Do you wish to save them?",
                    "Unsaved Changes",
                    MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Warning);
                if (temp == DialogResult.Cancel)
                {
                    return;
                }
                else if (temp == DialogResult.Yes)
                {
                    Menu_File_Save__Click(sender, e);
                }
            }

            using (OpenFileDialog OpenDlg = new OpenFileDialog())
            {
                OpenDlg.Filter = "PMD Placement Data JSON|*.json|PMD Placement Data XML|*.xml";

                if (OpenDlg.ShowDialog() == DialogResult.OK)
                {
                    Stream file = null;
                    try
                    {
                        fileCurrent = OpenDlg.SafeFileName + " (Imported)";
                        file        = new FileStream(OpenDlg.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                        DeserializePLB(file, ref data, OpenDlg.FilterIndex);

                        pathCurrent = null;
                        SetDirty();
                        SetLoaded();
                        CreateTree();
                    }
                    catch (Exception ex)
                    {
                        data = null;                //release PLB object

                        MessageBox.Show(            //show error message
                            "An error occured while opening:\n" + ex.Message,
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    finally
                    {
                        file?.Close();
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void DeserializePLB(Stream input, ref PLB data, int mode)
 {
     if (mode == 1)
     {
         var ser = new DataContractJsonSerializer(typeof(PLB));
         data = (PLB)ser.ReadObject(input);
     }
     else
     {
         var ser = new DataContractSerializer(typeof(PLB));
         data = (PLB)ser.ReadObject(input);
     }
 }
Exemplo n.º 4
0
 public static void SerializePLB(Stream output, PLB data, int mode)
 {
     if (mode == 1)
     {
         var ser = new DataContractJsonSerializer(typeof(PLB));
         using (var jsn = JsonReaderWriterFactory.CreateJsonWriter(output, System.Text.Encoding.UTF8, true, true))
         {
             ser.WriteObject(jsn, data);
         }
     }
     else
     {
         var ser = new DataContractSerializer(typeof(PLB));
         using (XmlWriter xw = XmlWriter.Create(output, new XmlWriterSettings {
             Indent = true
         }))
         {
             ser.WriteObject(xw, data);
         }
     }
 }
Exemplo n.º 5
0
        static void ParseArgs(string[] args)
        {
            int mode = 0;

            if (args[0].Equals("/wj") || args[0].Equals("/writeJson", StringComparison.OrdinalIgnoreCase))
            {
                mode = 1;
            }
            else if (args[0].Equals("/wx") || args[0].Equals("/writeXml", StringComparison.OrdinalIgnoreCase))
            {
                mode = 2;
            }
            else if (args[0].Equals("/rj") || args[0].Equals("/readJson", StringComparison.OrdinalIgnoreCase))
            {
                mode = 3;
            }
            else if (args[0].Equals("/rx") || args[0].Equals("/readXml", StringComparison.OrdinalIgnoreCase))
            {
                mode = 4;
            }
            else if (args[0].Equals("/t") || args[0].Equals("/test", StringComparison.OrdinalIgnoreCase))
            {
                mode = 5;
            }
            else
            {
                Console.WriteLine("ERROR: Invalid Argument(s)\n");
                ShowHelp();
                return;
            }

            if (args.Length < 3)
            {
                Console.WriteLine("ERROR: Missing File Argument(s)\n");
                return;
            }
            else if (args.Length > 3)
            {
                Console.WriteLine("ERROR: Unexpected File Argument(s)\n");
                return;
            }

            try
            {
                //open files
                Stream fileIn  = new FileStream(args[1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                Stream fileOut = new FileStream(args[2], FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                PLB    data    = null;

                //select action based on mode
                if (mode < 3)   //write json/xml
                {
                    data = new PLB(new PLBReader(fileIn));
                    PlbEdit.SerializePLB(fileOut, data, mode);
                }
                else if (mode < 5)  //read json/xml
                {
                    PlbEdit.DeserializePLB(fileIn, ref data, mode - 2);
                    data.Build(new PLBWriter(fileOut));
                }
                else
                {
                    data = new PLB(new PLBReader(fileIn));
                    data.Build(new PLBWriter(fileOut));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR: {e.Message}\n");
            }
        }
Exemplo n.º 6
0
        protected void ProcessFinCandle(Candle candle)
        {
            if (ProcessState == ProcessStates.Stopping)
            {
                // отменяем активные заявки
                CancelActiveOrders();
                return;
            }

            //this.AddInfoLog("Новая свеча {0}: {1};{2};{3};{4}; объем {5}".Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume));

            // добавляем новую свечку
            LongATR.Process(candle);
            ShortATR.Process(candle);
            PLB.Process(candle);
            int tt = PLB.GetCurrentValue <int>();

            if ((double)candle.ClosePrice < buyprice - deflevel && buyprice > 0)
            {
            }
            //+! костыльная проверка что индикатор заполнен.
            // нужно всегда заполнять перед торговлей
            if (LongATR.Container.Count >= LongATR.Length)
            {
                if (LongATR.GetCurrentValue <int>() > ShortATR.GetCurrentValue <int>() && this.Position == 0)
                {
                    var direction = OrderDirections.Buy;
                    buyprice = (double)candle.ClosePrice;
                    //спизжено из стоп лос стретеджи
                    //var longPos = this.BuyAtMarket();

                    //// регистрируем правило, отслеживающее появление новых сделок по заявке
                    //longPos
                    //    .WhenNewTrades()
                    //    .Do(OnNewOrderTrades)
                    //    .Apply(this);

                    //// отправляем заявку на регистрацию
                    //RegisterOrder(longPos);

                    double dl = 2.5 * ShortATR.GetCurrentValue <int>();
                    deflevel = (int)(dl + 0.5);
                    Order longPos;
                    if (!((EmulationTrader)Trader).MarketEmulator.Settings.UseMarketDepth)
                    {
                        // регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение.
                        longPos = this.CreateOrder(direction, Security.GetMarketPrice(direction), Volume);
                        RegisterOrder(longPos);
                    }
                    else
                    {
                        // переворачиваем позицию через котирование
                        var strategy = new MarketQuotingStrategy(direction, Volume)
                        {
                            WaitAllTrades = true,
                        };
                        ChildStrategies.Add(strategy);
                    }

                    // если произошло пересечение
                    //if (_isShortLessThenLong != isShortLessThenLong)
                    //{
                    //     если короткая меньше чем длинная, то продажа, иначе, покупка.
                    //    var direction = isShortLessThenLong ? OrderDirections.Sell : OrderDirections.Buy;

                    //    if (!((EmulationTrader)Trader).MarketEmulator.Settings.UseMarketDepth)
                    //    {
                    //         регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение.
                    //        RegisterOrder(this.CreateOrder(direction, Security.GetMarketPrice(direction), Volume));
                    //    }
                    //    else
                    //    {
                    //         переворачиваем позицию через котирование
                    //        var strategy = new MarketQuotingStrategy(direction, Volume)
                    //        {
                    //            WaitAllTrades = true,
                    //        };
                    //        ChildStrategies.Add(strategy);
                    //    }

                    //     запоминаем текущее положение относительно друг друга
                    //    _isShortLessThenLong = isShortLessThenLong;
                    //}

                    //+! щас будет костыльный параметр 2.5 на ATR  в стопах
                }
            }
        }