using Million.Data; using Million.Manager; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows.Forms; using DocumentFormat.OpenXml; using DevExpress.XtraCharts; using static Million.CommonProperty; using Million.IndicatorConditionSetup; using System.Drawing; using Million.SubForm; using Million; using System.IO; using Million.FileDBManagement; using Million.SaveData; using Million.DbManagement; namespace Million_Prototype { public partial class Form1 : Form { //public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; //public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; //UpbitAPI uApi = new UpbitAPI(accessKey,secretKey); Stopwatch sw = new Stopwatch(); public Form1() { InitializeComponent(); var startDate = new DateTime(2022, 1, 1, 0, 0, 0); var endDate = new DateTime(2022, 1, 2, 0, 0, 0); var tableList = UpbitApi.GetMarketDatas(); //전체 목록 var market = tableList.FirstOrDefault(t => t.CodeFullName == "KRW-BTC"); var datas = IndicatorSetupManager.GetCalculateCandleData(new List(), startDate, endDate, market); //ChartViewerForm chartViewerForm = new ChartViewerForm(); //chartViewerForm.setting(datas[MCandleTimeType.M1]); //chartViewerForm.Show(); } /// /// 1. 데이터 저장 /// 2. 조건식 검색 /// 3. 도출 /// /// /// private void button1_Click(object sender, EventArgs e) { sw.Restart(); var data = UpbitApi.GetMarketDatas(); //전체 목록 var krwList = data.FindAll(x => x.Payment.Contains("KRW")); //한화 목록 List dataList = new List(); setCandleDataList(dataList, krwList); //최초 데이터 전체 저장 //4시간, 1분 var dateTime = DateTime.Now; //4시간 가져오기 foreach (var krw in dataList) { krw.CandleDataLists_Im = UpbitApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.H4, dateTime); } /* //1분 가져오기 foreach (var krw in dataList) { var startDateTime = dateTime; var endDateTime = krw.CandleDataLists_4H.Last().DateTime; do { krw.CandleDataLists_Im.AddRange(uApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.M1, dateTime)); dateTime = krw.CandleDataLists_Im.Last().DateTime; } while (endDateTime < dateTime); }*/ //볼린저 계산 //일목균형표 계산 var test = krwList.Select(t => t.CodeFullName).ToList(); //var 현재가 = uApi.GetOrderBookList(test);GetTickerList var 현재가 = UpbitApi.GetTickerList(test); foreach (var krw in krwList) { //candledataList.Add(uApi.GetCandleStics(krw.CodeFullName, Million.CommonProperty.MCandleTimeType.D1, DateTime.Now, 50)); } sw.Stop(); listBox1.Items.Add("시간 : " + sw.ElapsedMilliseconds); 현재가.ToString(); } public void setCandleDataList(List dataList, List marketDataList) { foreach (var marketData in marketDataList) { dataList.Add(new CandleDataList() { ConGoodsData = marketData, }); } } //DB데이터 불러오기 private void button2_Click(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { var dataList = new Dictionary>(); var candleTypeList = new List(); candleTypeList.Add(MCandleTimeType.M1); candleTypeList.Add(MCandleTimeType.H1); RealtimeDataSettingManager realTimeMsg = null; int firstFlag = 0; //파일에서 데이터 가져와서 처리 해야하는 부분 Indicator List(임시 데이터) var savedResultDatas = new List(); foreach (var filePath in Directory.GetFiles(CommonProperty.SaveProgramDirecotryPath).ToList() .FindAll(item => item.Contains(CommonProperty.InfoExtend))) { var savedResult = FileManager.LoadResultDataInfoFromFile(filePath); savedResultDatas.Add(savedResult); } var savedResultData = savedResultDatas[0]; var sellIndicator = savedResultData.SellSetupList.OfType().ToList(); var buyIndicator = savedResultData.BuySetupList.OfType().ToList(); var totalIndicatorList = new List(); totalIndicatorList.AddRange(sellIndicator); totalIndicatorList.AddRange(buyIndicator); //사고 파는 rex 데이터 가져오는 부분 var buyRex = savedResultData.BuyRegularExpression; var sellRex = savedResultData.SellRegularExpression; var buyScript = new InteratorScripter(); buyScript.regularExpressionString = buyRex; var sellScript = new InteratorScripter(); sellScript.regularExpressionString = sellRex; //save 데이터 savedResultData.StartDateTime = DateTime.Now; //결과 데이터 var resultDataList = new List(); //구매 데이터 var buyList = new List(); var saveFlag = true; //구매 후 데이터 여러개 계속 겹치는 경우 제외하기 위한 List var overlapBuyManagementList = new Dictionary(); for (; ; ) { if (firstFlag == 0) { realTimeMsg = new RealtimeDataSettingManager(null, PaymentType.KRW); dataList = realTimeMsg.GetRealTimeCandleData(candleTypeList, 200); foreach (var item in realTimeMsg.codeFullNameList) { overlapBuyManagementList[item] = true; } firstFlag = 1; } else { if (firstFlag == 1) { dataList = realTimeMsg.ProcessRecentlyCandleDatas(dataList, candleTypeList); } } if (DateTime.Now.Minute == 0 && saveFlag) { realTimeMsg.ClearTicker(); if (resultDataList.Count > 0) { savedResultData.EndDateTime = DateTime.Now; savedResultData.SavedDateTime = DateTime.Now; savedResultData.SearchResultList = resultDataList; //수익 률 계산 로직 -> 이거는 추후 빼도 될듯 double totalVal = 0; double win = 0; double lose = 0; double firstProfitRate = 0; double firstWin = 0; //승률, 수익률 계산 foreach (var item in resultDataList) { if (item.FirstWinFlag) firstWin++; firstProfitRate += item.FirstEarningRate; win += item.WinCount; lose += item.LoseCount; totalVal += item.TotalEarningRate; } var winRate = 0.0; if (win == 0) { winRate = 0; } else if (lose == 0) { winRate = 100; } else { winRate = (win * 100 / (win + lose)); } double tt = 0; double t1 = 0; foreach (var item in resultDataList) { var buy = item.BuyList.CandleDataLists_Im[0]; var sell = item.SellData; tt += ((sell.SellValue - buy.BuyValue) / buy.BuyValue) * 100; if (buy.BuyValue < sell.SellValue) t1++; } tt /= resultDataList.Count; savedResultData.ResultDataCount = resultDataList.Count; savedResultData.FirstWinRate = (firstWin * 100) / resultDataList.Count; savedResultData.FirstProfitRate = firstProfitRate; savedResultData.WinRate = winRate; savedResultData.ProfitRate = totalVal / resultDataList.Count; savedResultData.SearchResultList = resultDataList; FileManager.SaveResultDataToFile(savedResultData); savedResultData.StartDateTime = DateTime.Now; resultDataList.Clear(); saveFlag = false; } } else if (DateTime.Now.Minute > 1) saveFlag = true; //Indicator 계산 -> Code full name 으로 for문 돌면서 계산 처리 foreach (var item in realTimeMsg.codeFullNameList) { //1차 execute var dic = new Dictionary>(); var distinctIndicator = IndicatorSetupManager.Distinct(totalIndicatorList); foreach (var key in dataList.Keys) { var candleDataList = dataList[key].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item); dic[key] = candleDataList.CandleDataLists_Im; var indicatorSetUpList = distinctIndicator.Where(t => t.MCandleTimeType == key).ToList(); foreach (var setup in indicatorSetUpList) { setup.excute(dic[key], true); } } var minDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min(); var maxDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max().AddHours(1); //2차 data calculate 처리 dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, true); #region 사고 파는 로직 //최신 데이터 가져오기 var recentlyData = dic[MCandleTimeType.M1][dic[MCandleTimeType.M1].Count - 1]; if (recentlyData == null) continue; /* * 로직 설명 * 1. Buy List에 있는지 확인 * 2. 없을 경우 추가(Buy Script 처리) * 3. Buy List에 있을 경우 Sell Script 확인 * 4. Sell 처리 후 결과 처리 */ //없을 시 -> BUY if (!buyList.Any(t => t.ConGoodsData.CodeFullName == item)) { var flag = buyScript.DicExcuteScript(recentlyData.CalculateFlag); if (flag) { if (overlapBuyManagementList[item]) { //if (resultDataList.Select(t => t.MarketData).ToList().Any(t => t.CodeFullName == item)) continue; var buyData = new CandleDataList(); buyData.CandleDataLists_Im.Add(recentlyData); var valDic = ResultLogicManager.GetIndicateValue(recentlyData.CalculateFlag, totalIndicatorList, recentlyData); recentlyData.BuyValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(buyRex, valDic, recentlyData.CalculateFlag)); buyData.ConGoodsData = dataList[MCandleTimeType.M1].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item).ConGoodsData; buyList.Add(buyData); overlapBuyManagementList[item] = false; } } else { overlapBuyManagementList[item] = true; } } else { var flag = sellScript.DicExcuteScript(recentlyData.CalculateFlag); if (flag) { var buyItem = buyList.FirstOrDefault(t => t.ConGoodsData.CodeFullName == item); var sellItem = recentlyData; var valDic = ResultLogicManager.GetIndicateValue(sellItem.CalculateFlag, totalIndicatorList, sellItem); sellItem.SellValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(sellRex, valDic, sellItem.CalculateFlag)); var buyVal = buyItem.CandleDataLists_Im[0].BuyValue; var sellVal = sellItem.SellValue; var result = new SearchResult(); var rate = ((sellVal - buyVal) / buyVal) * 100; result.FirstEarningRate = rate; result.EndDate = sellItem.DateTime; result.CodeFullName = buyItem.ConGoodsData.CodeFullName; result.MarketData = buyItem.ConGoodsData; result.BuyEarningRate.Add(rate); result.BuyValueList.Add(buyVal); result.BuyList.ConGoodsData = buyItem.ConGoodsData; result.BuyList.CandleDataLists_Im.Add(buyItem.CandleDataLists_Im[0]); result.StartDate = buyItem.CandleDataLists_Im[0].DateTime; result.SellData = sellItem; result.SellValue = sellVal; result.TotalEarningRate = rate; result.WinCount = rate > 0 ? 1 : 0; result.LoseCount = rate < 0 ? 1 : 0; result.FirstWinFlag = rate > 0 ? true : false; resultDataList.Add(result); //처리한 buyList는 삭제 buyList.Remove(buyItem); } } #endregion } } } /// /// File 에서 DB로 데이터 입력 /// /// /// private void button11_Click(object sender, EventArgs e) { //1회용임 Class 변경 때문에 //// Result Data DB에 생성 //Million.DbManagement.DBConnection.QueryUpdateExcuter // (CommonProperty.DbConnectionResultData, DbServiceFunctions.CreateSavedAnalysisDataTableQuery()); //Million.DbManagement.DBConnection.QueryUpdateExcuter // (CommonProperty.DbConnectionResultData, DbServiceFunctions.CreateSavedResultDataTableQuery()); ////file Data전체 불러와서 처리 //var savedResultDatas = new List(); //foreach (var filePath in Directory.GetFiles(CommonProperty.SaveProgramDirecotryPath).ToList() // .FindAll(item => item.Contains(CommonProperty.InfoExtend))) //{ // var savedResult = FileManager.LoadResultDataInfoFromFile(filePath); // savedResult.SavedInfoDataPath = filePath; // savedResult.SavedResultDataPath = // filePath.Replace(CommonProperty.InfoExtend, CommonProperty.DataExtend); // savedResult.SavedResultAnalysisDataPath = // filePath.Replace(CommonProperty.InfoExtend, CommonProperty.AnalysisExtendFolder); // savedResult.SearchResultList = FileManager.LoadResultDataFromFile(savedResult.SavedResultDataPath); // savedResultDatas.Add(savedResult); //} ////saved result for문 돌면서 데이터 처리 //foreach(var item in savedResultDatas) //{ // var savedAnalysisDataList = new List(); // if (Directory.Exists(item.SavedResultAnalysisDataPath)) // { // var fileList = Directory.GetFiles(item.SavedResultAnalysisDataPath, "*info"); // foreach (var filePath in fileList) // { // var savedSnalysisData = FileManager.LoadResultAnalysisDataInfoFromFile(filePath); // savedSnalysisData.SavedInfoDataPath = filePath; // savedSnalysisData.SavedResultDataPath = filePath.Replace("info", "data"); // savedSnalysisData.AnalysisDataList = FileManager.LoadResultAnalysisDataFromFile(savedSnalysisData.SavedResultDataPath); // savedAnalysisDataList.Add(savedSnalysisData); // } // } // //SavedResultData 먼저 DB에 Insert 후 SavedAnalysisData 처리 // Million.DbManagement.DBConnection.QueryUpdateExcuter_SavedResultData(item); // foreach(var analysis in savedAnalysisDataList) // { // Million.DbManagement.DBConnection.QueryUpdateExcuter_SavedAnalysisData(analysis, item); // } //} } private void button4_Click(object sender, EventArgs e) { //DbServiceFunctions.GetMarketTable_FromDB("Upbit"); //var tableList = CommonProperty.selectedMarketOfPlaceList; //var resultList = new List(); //var errorResultList = new List(); //var win = 0; //var lose = 0; //foreach (var marketData in tableList) //{ // var buyCandleList = new List(); // var sellList = new List(); // if (marketData != null) // { // //사는 로직 // var candleDataH1 = new CandleDataList(); // var candleDataM1 = new CandleDataList(); // var splitDataM = new List>(); // var splitData = ValidationCheckManager.GetValidationCandleDatas(marketData, ref splitDataM, ref candleDataH1, ref candleDataM1, new DateTime(2022, 1, 1), DateTime.Now); // var buyData = new CandleDataList(); // buyData.ConGoodsData = marketData; // buyData.CandleDataLists_Im = new List(); // foreach (var split in splitData) // { // var overData = split.FindAll(x => (int)x.IndicatorDic["Bol401"].overStatus >= -2 && x.IndicatorDic["Bol401"].overStatus != OverStatus.None // && ((IchimokData)x.IndicatorDic["Ich"]).value < x.StartValue && ((IchimokData)x.IndicatorDic["Ich"]).value2 < x.StartValue); // buyData = BuyLogicManager.GetBuyLogicByBol401Upper(overData, candleDataM1); // if (buyData.CandleDataLists_Im != null && buyData.CandleDataLists_Im.Count > 0) // buyCandleList.Add(buyData); // } // //파는 로직 // foreach (var item in splitDataM) // { // var sell1 = SellLogicManager.GetSellLogicOverUnderIch(item); // var sell2 = SellLogicManager.GetSellLogicOVerUnderBol(item, 40, 1); // var sell3 = SellLogicManager.GetSellLogicOVerUnderBol(item, 40, 2); // sell1.AddRange(sell2); // sell1.AddRange(sell3); // var dateTimeList = sell1.Select(t => t.DateTime).Distinct().ToList(); // foreach (var date in dateTimeList) // { // sellList.Add(sell1.FirstOrDefault(t => t.DateTime == date)); // } // } // var result = new SearchResult(); // var sellData = new CandleData(); // //Result 계산 // foreach (var item in buyCandleList) // { // result.BuyList.ConGoodsData = marketData; // if (item.CandleDataLists_Im.Count > 0) // { // sellData = sellList.FirstOrDefault(t => t.DateTime > item.CandleDataLists_Im[0].DateTime); // if (sellData == null) continue; // foreach (var buy in item.CandleDataLists_Im) // { // if (buy.DateTime < sellData.DateTime) // { // result.BuyList.CandleDataLists_Im.Add(buy); // } // else // { // var sDate = result.BuyList.CandleDataLists_Im[0].DateTime; // var eDate = sellData.DateTime; // //Result Data Setting // result.TermCandleDataList = candleDataM1.CandleDataLists_Im.Where(x => x.DateTime >= sDate && x.DateTime <= eDate).ToList(); // result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName; // result.StartDate = sDate; // result.EndDate = eDate; // result.SellData = sellData; // var sellLogicKeys = result.SellData.SellLogicFlag.Keys; // double sellValue = 0; // #region 파는 값 계산(파는 로직 중 제일 높은 값) // var key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.IchMok); // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue()) // { // sellValue = ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue(); // } // } // key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"; // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < result.SellData.IndicatorDic[key].overlapValue) // { // sellValue = result.SellData.IndicatorDic[key].overlapValue; // } // } // key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "402"; // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < result.SellData.IndicatorDic[key].overlapValue) // { // sellValue = result.SellData.IndicatorDic[key].overlapValue; // } // } // result.SellValue = sellValue; // #endregion // #region Rating 계산 // double totalVal = 0; // foreach (var x in result.BuyList.CandleDataLists_Im) // { // var dateTime = x.DateTime.AddMinutes(x.DateTime.Minute * -1); // var hCandle = candleDataH1.CandleDataLists_Im.FirstOrDefault(t => t.DateTime == dateTime); // var buyValue = hCandle.IndicatorDic[Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"].overlapValue; // var rate = ((sellValue - buyValue) / buyValue) * 100; // result.BuyEarningRate.Add(rate); // result.BuyValueList.Add(buyValue); // if (rate >= 0) win++; // else lose++; // totalVal += rate; // } // result.TotalEarningRate = totalVal / result.BuyValueList.Count; // #endregion // var errorList = ValidationCheckManager.ValidateCandleDataList(result.TermCandleDataList, "", MCandleTimeType.M1); // if (errorList.Count == 0) // { // result.SellData = sellData; // resultList.Add(result); // } // else // { // result.SellData = sellData; // errorResultList.Add(result); // } // result = new SearchResult(); // result.BuyList.CandleDataLists_Im.Add(buy); // result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName; // sellData = sellList.FirstOrDefault(t => t.DateTime > buy.DateTime); // } // } // } // } // //Sell 시점이 더 늦는 경우에 대한 처리(나중에 안에 있는 로직이랑 병합해서 한번에처리해야함 // if (result.BuyList.CandleDataLists_Im.Count > 0) // { // var sDate = result.BuyList.CandleDataLists_Im[0].DateTime; // var eDate = sellData.DateTime; // //Result Data Setting // result.TermCandleDataList = candleDataM1.CandleDataLists_Im.Where(x => x.DateTime >= sDate && x.DateTime <= eDate).ToList(); // result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName; // result.StartDate = sDate; // result.EndDate = eDate; // result.SellData = sellData; // var sellLogicKeys = result.SellData.SellLogicFlag.Keys; // double sellValue = 0; // #region 파는 값 계산(파는 로직 중 제일 높은 값) // var key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.IchMok); // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue()) // { // sellValue = ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue(); // } // } // key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"; // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < result.SellData.IndicatorDic[key].overlapValue) // { // sellValue = result.SellData.IndicatorDic[key].overlapValue; // } // } // key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "402"; // if (result.SellData.SellLogicFlag.ContainsKey(key)) // { // if (sellValue < result.SellData.IndicatorDic[key].overlapValue) // { // sellValue = result.SellData.IndicatorDic[key].overlapValue; // } // } // result.SellValue = sellValue; // #endregion // #region Rating 계산 // double totalVal = 0; // foreach (var x in result.BuyList.CandleDataLists_Im) // { // var dateTime = x.DateTime.AddMinutes(x.DateTime.Minute * -1); // var hCandle = candleDataH1.CandleDataLists_Im.FirstOrDefault(t => t.DateTime == dateTime); // var buyValue = hCandle.IndicatorDic[Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"].overlapValue; // var rate = ((sellValue - buyValue) / buyValue) * 100; // result.BuyEarningRate.Add(rate); // result.BuyValueList.Add(buyValue); // if (rate >= 0) win++; // else lose++; // totalVal += rate; // } // result.TotalEarningRate = totalVal / result.BuyValueList.Count; // #endregion // var errorList = ValidationCheckManager.ValidateCandleDataList(result.TermCandleDataList, "", MCandleTimeType.M1); // if (errorList.Count == 0) // { // result.SellData = sellData; // resultList.Add(result); // } // else // { // result.SellData = sellData; // errorResultList.Add(result); // } // } // } //} //double total = 0; //foreach (var item in resultList) //{ // Console.WriteLine(item.CodeFullName); // Console.WriteLine(item.TotalEarningRate); // total += item.TotalEarningRate; //} //Console.WriteLine("Total 수익률 : " + total / resultList.Count); //Console.WriteLine("Win : " + win); //Console.WriteLine("Lose : " + lose); //Console.WriteLine("승률 : " + win * 100 / (win + lose)); //resultList.ToString(); } private void button5_Click(object sender, EventArgs e) { try { var ask_price = double.Parse(textBoxAskInput.Text); textBoxAskOutput.Text = OrderbookManager.GetAskPrice(ask_price).ToString(); } catch (Exception ex) { ex.ToString(); } } private void button6_Click(object sender, EventArgs e) { var s = new BolingerConditionSetup(); s.IndicatorType = IndicatorType.볼린저밴드; s.MCandleTimeType = MCandleTimeType.D1; s.Period = 30; s.Squared = 2; var d = new BolingerConditionSetup(); d.IndicatorType = IndicatorType.볼린저밴드; d.MCandleTimeType = MCandleTimeType.D1; d.Period = 30; d.Squared = 1; s.Equals(d).ToString(); } /// /// /// /// /// true인 경우 큰값 가져옴 /// /// public string exeStit(string aaa, bool select = true, bool bracket = true) { if (bracket) { if (aaa.First().CompareTo('(') == 0 && aaa.Last().CompareTo(')') == 0) { aaa = aaa.Substring(1, aaa.Length - 2); } } aaa = aaa.Replace("&&", "&"); aaa = aaa.Replace("||", "|"); do { var orIndex = aaa.IndexOf('|'); var andIndex = aaa.IndexOf('&'); if (orIndex < 0 && andIndex < 0) break; orIndex = orIndex == -1 ? 100000 : orIndex; andIndex = andIndex == -1 ? 100000 : andIndex; var splitKey = orIndex > andIndex ? '&' : '|'; var splitOtherKey = orIndex < andIndex ? '&' : '|'; var splitStr1 = aaa.Split(splitKey).ToList(); var before = splitStr1[0]; var after = splitStr1[1].Split(splitOtherKey).First(); var selectOper = splitKey.CompareTo('&') == 0 ? select : !select; var resultStr = "(" + before + (selectOper ? ">" : "<") + after + "?" + before + ":" + after + ")"; aaa = aaa.Replace(before + splitKey + after, resultStr); } while (true); return aaa; } private void button7_Click(object sender, EventArgs e) { try { InteratorScripter.ScriptExcute("true&&true"); List keyList = new List() { '(','&','|' }; var sss = keyList.FirstOrDefault(x => x == '+'); var werwerewr = $"a a " + " a"; werwerewr = werwerewr.Replace(" ", ""); //string qwer = "(1||2&&3)"; //exeStit(qwer); var bb = 100 > 60 ? 100 : 60; bb.ToString(); string aa = "(1 && 2)||(11 && (22 || 33))"; aa = "(111 && 112)||(11 &&12)||(22 || 33)"; //aa = "(99&&2&&3||4)||((111&&6)||7)"; aa = aa.Replace(" ", ""); Dictionary indicateFlagDic = new Dictionary() { {"111",true }, {"112",true }, {"11",false }, {"12",false }, {"22",true }, {"33",true }, }; Dictionary conditionDic = new Dictionary() { {"111",90 }, {"112",100 }, {"11",200 }, {"12",400 }, {"22",92 }, {"33",96 }, }; var result123123 = CalculateManager.GetConditionValue(aa, conditionDic, indicateFlagDic); var index = aa.LastIndexOf('('); Dictionary substitution = new Dictionary(); var count = 1; //-1이면 못찾았다는 뜻 while (index != -1) { var countName = "S" + count.ToString(); var lastindex = aa.Substring(index + 1).IndexOf(')') + 1; var dd = aa.Substring(index, lastindex + 1); substitution.Add(countName, exeStit(dd)); aa = aa.Replace(dd, countName); count++; index = aa.LastIndexOf('('); } var ss123123 = substitution.Keys.FirstOrDefault(x => aa.Contains(x)); while (ss123123 != null) { aa = aa.Replace(ss123123, substitution[ss123123]); ss123123 = substitution.Keys.FirstOrDefault(x => aa.Contains(x)); } aa = exeStit(aa, true, false); Dictionary aa1 = new Dictionary(); aa1["1"] = true; aa1["22"] = true; aa1["11"] = false; aa1["2"] = true; Dictionary aa2 = new Dictionary(); aa2["1"] = true; aa2["2"] = true; aa2["11"] = true; aa2["22"] = true; Dictionary aa3 = new Dictionary(); aa3["1"] = true; aa3["2"] = true; aa3["11"] = false; aa3["22"] = true; Dictionary aa4 = new Dictionary(); aa4["1"] = true; aa4["2"] = true; var returnvalue = aa1.Except(aa3).Any(); returnvalue = aa1.Except(aa2).Any(); returnvalue = aa1.Except(aa4).Any(); var ss123 = aa1.Except(aa3); ss123 = aa1.Except(aa2); ss123 = aa1.Except(aa4); InteratorScripter ss = new InteratorScripter(); ss.regularExpressionString = aa; ss.DicExcuteScript(aa1); ss.DicExcuteScript(aa2); ss.DicExcuteScript(aa3); /* var resultstring = InteratorScripter.ChangeScript(aa, aa1); resultstring.ToString(); var test = CSharpScript.EvaluateAsync("(true && true)||(true && false)"); Console.WriteLine(test.Result);*/ } catch (Exception ex) { ex.ToString(); } } private void button8_Click(object sender, EventArgs e) { Dictionary indicateFlagDic = new Dictionary() { {"111",true }, {"112",true }, {"11",false }, {"12",false }, {"22",true }, {"33",true }, }; Dictionary conditionDic = new Dictionary() { {"111",90 }, {"112",100 }, {"11",200 }, {"12",400 }, {"22",92 }, {"33",96 }, {"44",144 }, {"55",255 }, {"66",366 }, }; var conditionStr = "22|(33)"; conditionStr = "((11&22)|(33|44|55|66))"; List keyList = new List() { '(',')','&','|' }; List keyList2 = new List() { '&','|' }; var keyCount = 0; foreach (var key in keyList) { keyCount += conditionStr.Split(key).Count() - 1; } //22|(33) //22|(33|44|55|66) var splitStr = conditionStr; while (keyCount != 0) { var substitutionStr = splitStr; var noIterChecker = true; var indexDic = new Dictionary(); //괄호가 있다면 if (splitStr.Split('(').Count() > 1) { var index = splitStr.LastIndexOf('('); var lastindex = splitStr.Substring(index + 1).IndexOf(')') + 1; substitutionStr = splitStr.Substring(index + 1, lastindex - 1); } foreach (var key in keyList2) { var temp = substitutionStr.IndexOf(key); if (temp != -1) noIterChecker = false; indexDic.Add(key, substitutionStr.IndexOf(key)); } var sortIndex = indexDic.OrderBy(x => x.Value); //괄호는 있지만 연산자는 없을때 처리 if (noIterChecker) { splitStr = splitStr.Replace("(" + substitutionStr + ")", substitutionStr); keyCount = 0; foreach (var key in keyList) { keyCount += splitStr.Split(key).Count() - 1; } continue; } List tKey = new List(); foreach (var item in sortIndex) { if (item.Value != -1) { tKey.Add(item.Key); } } var beforeStr = ""; var afterStr = ""; if (tKey.Count() >= 2) { var strList = substitutionStr.Split(tKey[0]); beforeStr = strList.First(); afterStr = strList[1].Split(tKey[1]).First(); } else if (tKey.Count() == 1) { var strList = substitutionStr.Split(tKey[0]); beforeStr = strList[0]; afterStr = strList[1]; } if (tKey[0] == '&') { splitStr = splitStr.Replace(beforeStr + "&" + afterStr, conditionDic[beforeStr] > conditionDic[afterStr] ? beforeStr : afterStr); keyCount = 0; foreach (var key in keyList) { keyCount += splitStr.Split(key).Count() - 1; } } else if (tKey[0] == '|') { splitStr = splitStr.Replace(beforeStr + "|" + afterStr, conditionDic[beforeStr] < conditionDic[afterStr] ? beforeStr : afterStr); keyCount = 0; foreach (var key in keyList) { keyCount += splitStr.Split(key).Count() - 1; } } } splitStr.ToString(); } private void button9_Click(object sender, EventArgs e) { List asdf = new List(); asdf.Add(0); asdf.Add(1); asdf.Add(2); asdf.Add(3); asdf.Add(4); asdf.Add(5); asdf.Add(6); asdf.Add(7); asdf.Add(8); asdf.Add(9); asdf.Add(10); asdf.Add(11); asdf.Add(12); asdf.Add(13); int period = 5; List asdf2 = new List(); for (int i = 0; i < asdf.Count; i++) { asdf2.Add(asdf[i]); if (i > period) { asdf2.RemoveAt(0); } } } private void button10_Click(object sender, EventArgs e) { //임의 데이터 생성 List dataPoints = new List { new DataPoint(DateTime.Now.AddDays(-9), 24.00, 25.00, 25.00, 24.875), new DataPoint(DateTime.Now.AddDays(-8), 23.625, 25.125, 24.00, 24.875), new DataPoint(DateTime.Now.AddDays(-7), 26.25, 28.25, 26.75, 27.00), new DataPoint(DateTime.Now.AddDays(-6), 26.50, 27.875, 26.875, 27.25), new DataPoint(DateTime.Now.AddDays(-4), 25.75, 26.875, 26.75, 26.00), new DataPoint(DateTime.Now.AddDays(-3), 25.75, 26.75, 26.125, 26.25), new DataPoint(DateTime.Now.AddDays(-2), 25.75, 26.375, 26.375, 25.875), new DataPoint(DateTime.Now.AddDays(-1), 24.875, 26.125, 26.00, 25.375), new DataPoint(DateTime.Now.AddDays(0), 25.125, 26.00, 25.625, 25.75), }; var datsd = DateTime.Now.AddDays(-9); dataPoints = new List { new DataPoint(datsd, 24.00, 25.00, 25.00, 24.875), new DataPoint(datsd.AddMinutes(1), 23.625, 25.125, 24.00, 24.875), new DataPoint(datsd.AddMinutes(2), 26.25, 28.25, 26.75, 27.00), //new DataPoint(datsd.AddMinutes(3), 26.50, 27.875, 26.875, 27.25), //new DataPoint(datsd.AddMinutes(4), 25.75, 26.875, 26.75, 26.00), new DataPoint(datsd.AddMinutes(5), 25.75, 26.75, 26.125, 26.25), new DataPoint(datsd.AddMinutes(6), 25.75, 26.375, 26.375, 25.875), new DataPoint(datsd.AddMinutes(7), 24.875, 26.125, 26.00, 25.375), new DataPoint(datsd.AddMinutes(8), 25.125, 26.00, 25.625, 25.75), }; var series1 = new Series("candle", ViewType.CandleStick); series1.DataSource = dataPoints; series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close"); series1.ArgumentScaleType = ScaleType.DateTime; chartControl1.Series.Add(series1); CandleStickSeriesView view = (CandleStickSeriesView)series1.View; view.LineThickness = 2; view.LevelLineLength = 0.25; // Specify the series reduction options. view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue; view.ReductionOptions.FillMode = CandleStickFillMode.AlwaysEmpty; view.ReductionOptions.Level = StockLevel.Close; view.ReductionOptions.Visible = true; view.Color = Color.Blue; view.ReductionOptions.Color = Color.Red; // Access the chart's diagram. XYDiagram diagram = (XYDiagram)chartControl1.Diagram; // Exclude empty ranges from the X-axis range // to avoid gaps in the chart's data. //diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = true; // Hide the range without points at the beginning of the y-axis. diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false; diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Minute; diagram.AxisX.DateTimeScaleOptions.MeasureUnitMultiplier = 3; //diagram.AxisX.VisualRange. } } public class DataPoint { public DateTime Argument { get; set; } public double Low { get; set; } public double High { get; set; } public double Open { get; set; } public double Close { get; set; } public DataPoint(DateTime argument, double low, double high, double open, double close) { this.Argument = argument; this.Low = low; this.High = high; this.Open = open; this.Close = close; } } }