Exemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {


            this.yuantaOrderAPI = new YuantaOrdClass();

            try
            {
                yuantaOrderAPI.OnLogonS += new _DYuantaOrdEvents_OnLogonSEventHandler(yuantaOrderAPI_OnLogonS);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            timer1.Enabled = false;

            label_Version.Text = TradeUtility.TradeUtility.version;

            appDir = System.Windows.Forms.Application.StartupPath;

            trackFileDir = appDir + "\\" + Track_Dir + "\\";

            FileManager fm = new FileManager();

            trackFileList = fm.getConfigFileList(trackFileDir);

            configFilePath = appDir + "\\" + Config_Dir + "\\" + Config_File_Name;

            try
            {

                configFile = new ConfigFile(configFilePath);

            }
            catch (Exception ex)
            {
                MessageBox.Show("讀取  設定檔  失敗。原因 : " + ex.Message);

                return;
            }

            tradeCode = configFile.readConfig("Trade_Code");

            string tradeMonth = configFile.readConfig("Trade_Month");

            string tradeYear = configFile.readConfig("Trade_Year");

            string tradeMonthFilePath = appDir + "\\" + Config_Dir + "\\" + Month_File_Name;

            try
            {

                tradeCode = TradeUtility.TradeUtility.getInstance().dealTradeCode(tradeMonthFilePath, tradeCode, tradeMonth, tradeYear);

            }
            catch (Exception ex)
            {

                MessageBox.Show("讀取  月份代碼檔  失敗。原因 : " + ex.Message);

                return;
            }

            ipQuote = configFile.readConfig("IP_Quote");

            id = configFile.readConfig("ID");

            password = configFile.readConfig("Password");

            ipAPI = configFile.readConfig("IP_API");

            port = configFile.readConfig("Port");

            lots = configFile.readConfig("Lots");

            maxLoss = configFile.readConfig("Max_Loss");

            branchCode = configFile.readConfig("Branch_Code");

            account = configFile.readConfig("Account_Code");

            futuresCode = configFile.readConfig("Futures_Code");

            lotLimit = configFile.readConfig("Lot_Limit");

            try
            {

                master = new TradeMaster(this);

                master.setLotLimit(Convert.ToInt16(lotLimit));

                master.setFuturesCode(futuresCode);

                master.setMaxLoss(Convert.ToInt32(maxLoss));

                master.setID(id);

                master.setPassword(password);

                master.setBranchCode(branchCode);

                master.setAccount(account);

                master.setLots(lots);

                master.setIpAPI(ipAPI);

                master.setOrderAPI(yuantaOrderAPI);

                master.setTradeCode(tradeCode);

                master.prepareFirst();

                master.prepareTrackFile();

                readTrackFile(master);

                master.prepareDataFromLastTradeDay();

            }
            catch (Exception ez)
            {
                MessageBox.Show(ez.Message + "--" + ez.StackTrace);

                return;
            }

            textBox_loseLine.Text = Convert.ToString(master.getLoseLine()[1]);

            textBox1_winLine.Text = Convert.ToString(master.getWinLine()[1]);

            textBox_reverseLine.Text = Convert.ToString(master.getReverseLine()[1]);

            textBox_B_S.Text = master.OrderDircetion;

            textBox_MaxPrice.Text = Convert.ToString(master.MaxTradePointLastDay);

            textBox_MinPrice.Text = Convert.ToString(master.MinTradePointLastDay);

            textBox_OrderPrice.Text = Convert.ToString(master.OrderPrice);

            textBox_OrderStart.Text = Convert.ToString(master.IsStartOrder);

            textBox_NowTradeType.Text = master.NowTradeType;

            if (master.OrderNewPriceList != null)
            {
                for (int i = 0; i < master.OrderNewPriceList.Count; i++)
                {
                    textBox_OrderNewPriceList.Text += master.OrderNewPriceList[i] + Environment.NewLine;
                }
            }



            loginQuote();

            loginOrder();

        }