Ejemplo n.º 1
0
        private void initOrderButton_Click(object sender, EventArgs e)
        {
            //保存设置数据
            PlatformInfo platformInfo = new PlatformInfo();

            platformInfo.Tcp_ip_quote = textBox1.Text.ToString();
            platformInfo.Tcp_ip_trade = textBox2.Text.ToString();
            platformInfo.Sub          = symbolTextBox.Text.ToString();

            platformInfo.Sell_nums   = initialShortOrderCountTextBox.Text.ToString();
            platformInfo.First_price = middlePriceTextBox.Text.ToString();
            platformInfo.Buy_nums    = initialLongOrderCountTextBox.Text.ToString();

            platformInfo.Investor     = textBox3.Text.ToString();
            platformInfo.Investorpass = textBox4.Text.ToString();
            platformInfo.Broker       = textBox9.Text.ToString();

            Boolean task = fileAction.Write(root_dir, platformInfo);

            if (task)
            {
                this.fileLog.log("数据保存成功!");
                Console.WriteLine("数据保存成功!");
            }
            middlePrice = middlePriceTextBox.Text;
            int price_first_int = int.Parse(middlePrice); //设定中间价

            sell_nums = initialShortOrderCountTextBox.Text;
            buy_nums  = initialLongOrderCountTextBox.Text;

            int sell_nums_ar = int.Parse(sell_nums); //卖单挂单数
            int buy_nums_ar  = int.Parse(buy_nums);  //买单挂单数

            IList <OrderField> openOrderList = this.fileAction.ReadOpenOrders(root_dir);

            if (openOrderList != null && openOrderList.Count > 0)
            {
                IEnumerator <OrderField> openOrderEnumerator = openOrderList.GetEnumerator();
                string logMessage;
                while (openOrderEnumerator.MoveNext())
                {
                    OrderField tempOrderField = openOrderEnumerator.Current;
                    if (tempOrderField.Direction == DirectionType.Buy)
                    {
                        if (tempOrderField.Offset == OffsetType.Close)
                        {
                            logMessage = "恢复定单:买平@" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                            ctpTrade.buy_btn_Close(tempOrderField.LimitPrice);
                        }
                        else if (tempOrderField.Offset == OffsetType.Open)
                        {
                            logMessage = "恢复定单:买开@" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                            ctpTrade.buy_btn_Open(tempOrderField.LimitPrice);
                        }
                        else
                        {
                            logMessage = "未知定单:" + tempOrderField.Offset + ",价格:" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                        }
                    }
                    else
                    {
                        if (tempOrderField.Offset == OffsetType.Close)
                        {
                            logMessage = "恢复定单:卖平@" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                            ctpTrade.sell_btn_Close(tempOrderField.LimitPrice);
                        }
                        else if (tempOrderField.Offset == OffsetType.Open)
                        {
                            logMessage = "恢复定单:卖开@" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                            ctpTrade.sell_btn_Open(tempOrderField.LimitPrice);
                        }
                        else
                        {
                            logMessage = "未知定单:" + tempOrderField.Offset + ",价格:" + tempOrderField.LimitPrice;
                            this.fileLog.log(logMessage);
                            Console.WriteLine(logMessage);
                        }
                    }
                } //while
            }     //if
            else
            {
                for (int i = 0; i < sell_nums_ar; i++)
                {
                    this.fileLog.log("卖单" + i + "..." + (price_first_int + i));
                    Console.WriteLine("卖单" + i + "..." + (price_first_int + i));
                    ctpTrade.sell_btn_Open(price_first_int + i + 1);
                }

                for (int j = 0; j < buy_nums_ar; j++)
                {
                    this.fileLog.log("买单" + j + "..." + (price_first_int - j));
                    Console.WriteLine("买单" + j + "..." + (price_first_int - j));
                    ctpTrade.buy_btn_Open(price_first_int - j - 1);
                    //  Thread.Sleep(20);
                }
            }
            this.timer1.Start();
            this.initOrderButton.Visible = false;
        }