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(); }
private void readTrackFile(TradeMaster master) { if (trackFileList != null && trackFileList.Count > 0) { string trackFileName = "Track_" + master.Now.Year + "_" + master.Now.Month + "_" + master.NowDay + ".txt"; ConfigFile trackFile = trackFileList[trackFileList.Count - 1]; List<string> contextList = new List<string>(); if (trackFile != null) { tradeCodeLastDay = trackFile.readConfig("TradeCode"); textBox_tradeCodeLastDay.Text = tradeCodeLastDay; if (tradeCode != null && tradeCodeLastDay != null && !tradeCodeLastDay.Trim().Equals("")) { if (!tradeCode.Trim().Equals(tradeCodeLastDay))//交易月份不同 { return; } else//交易月份相同 { master.Stage = TradeMaster.Stage_Last_Day; } } if (!trackFileName.Trim().Equals(trackFile.getFileName().Trim()))//不是今天的檔案 { if (!trackFile.isEndTrade()) { List<string> trackLines = new List<string>(); String tmpStr = ""; while (trackFile.hasNext()) {//把上一個交易日的軌跡檔寫進今天的軌跡檔內 tmpStr = trackFile.getLine().Trim(); if (null != tmpStr) { trackLines.Add(tmpStr); if (tmpStr.Equals("EndTrade")) { trackLines.Clear(); } } } for (int i = 0; i < trackLines.Count; i++) { master.trackMsg(trackLines[i]); } } } contextList = trackFile.readMultiLineConfig("NewTrade", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.IsStartOrderLastDay = true; contextList.Clear(); } contextList = trackFile.readMultiLineConfig("OrderPrice", "EndTrade"); if (contextList != null && contextList.Count >= 1) { for (int i = 0; i < contextList.Count; i++) { //orderPriceList.Add(Convert.ToDouble(contexList[i])); if (i == 0) { master.OrderPrice = Convert.ToInt16(contextList[0]); } master.OrderNewPriceList.Add(Convert.ToInt16(contextList[i])); master.OrderNewPrice = Convert.ToInt16(contextList[i]); } contextList.Clear(); } contextList = trackFile.readMultiLineConfig("BuyOrSell", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.OrderDircetion = contextList[contextList.Count - 1]; master.NowTradeType = contextList[contextList.Count - 1]; contextList.Clear(); } contextList = trackFile.readMultiLineConfig("MaxPrice", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.MaxTradePointLastDay = Convert.ToInt16(contextList[contextList.Count - 1]); contextList.Clear(); } contextList = trackFile.readMultiLineConfig("MinPrice", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.MinTradePointLastDay = Convert.ToInt16(contextList[contextList.Count - 1]); contextList.Clear(); } contextList = trackFile.readMultiLineConfig("PrevStopPrice", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.PrevStopPrice = Convert.ToInt16(contextList[contextList.Count - 1]); contextList.Clear(); } contextList = trackFile.readMultiLineConfig("StopPrice", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.StopPrice = Convert.ToInt16(contextList[contextList.Count - 1]); contextList.Clear(); } contextList = trackFile.readMultiLineConfig("ContinueLoseTimes", "EndTrade"); if (contextList != null && contextList.Count >= 1) { master.ContinueLoseTimes = Convert.ToInt16(contextList[contextList.Count - 1]); contextList.Clear(); } trackFile.close(); trackFile = null; } } }