diff --git a/Million Buyer/MainForm.cs b/Million Buyer/MainForm.cs index 40471dd..fb41239 100644 --- a/Million Buyer/MainForm.cs +++ b/Million Buyer/MainForm.cs @@ -36,6 +36,8 @@ namespace Million_Buyer bool SetIndicator = false; bool ThreadFlag = false; + bool AliveCheckor = false; + private Thread thread = null; private Thread orderThread = null; private List accounts = null; @@ -188,8 +190,8 @@ namespace Million_Buyer private void bt_Stop_Click(object sender, EventArgs e) { ThreadFlag = false; - if (!RealTimeMode && thread != null) thread.Abort(); - if (!RealTimeMode && orderThread != null) orderThread.Abort(); + //if (!RealTimeMode && thread != null) thread.Abort(); + //if (!RealTimeMode && orderThread != null) orderThread.Abort(); bt_Start.Enabled = true; rd_buyer.Enabled = true; @@ -284,9 +286,9 @@ namespace Million_Buyer var buyRex = _saveResultData.BuyRegularExpression; var sellRex = _saveResultData.SellRegularExpression; - var buyScript = new InteratorScripter(); + var buyScript = new InteratorScripter("Buy Script"); buyScript.regularExpressionString = buyRex; - var sellScript = new InteratorScripter(); + var sellScript = new InteratorScripter("Sell Script"); sellScript.regularExpressionString = sellRex; var scriptDic = new Dictionary(); @@ -294,11 +296,7 @@ namespace Million_Buyer //TODO 모든 조건 데이터 미리 계산 필요 //save 데이터 - _saveResultData.StartDateTime = DateTime.Now; - - //구매 데이터 - - var saveFlag = true; + _saveResultData.StartDateTime = DateTime.Now; //구매 후 데이터 여러개 계속 겹치는 경우 제외하기 위한 List var overlapBuyManagementList = new Dictionary(); @@ -327,6 +325,13 @@ namespace Million_Buyer { try { + if (AliveCheckor) + { + AliveCheckor = false; + InsertLog("Alive"); + } + + #region 기본 데이터 Setting if (firstFlag == 0) { @@ -352,15 +357,23 @@ namespace Million_Buyer dic[codeFullname] = true; } CommonProperty.subIndicatorStateManagement[item.IndexString] = dic; + } + #region TODO 이미 구매되어 있는 종목에 대한 기본 데이터 Setting 필요 + if (RealTimeMode) + { + } + else + { - // TODO 이미 구매되어 있는 종목에 대한 기본 데이터 Setting 필요 - + } + #endregion firstFlag = 1; InsertLog("Deafult Data Setting 완료.."); sw.Stop(); InsertLog("Default 계산 시간 : " + sw.Elapsed.ToString()); + LogManager.WriteLog("Default 계산 시간 : " + sw.Elapsed.ToString()); } else { @@ -373,14 +386,7 @@ namespace Million_Buyer InsertLog("Ticker 계산 시간 : " + sw.Elapsed.ToString()); } } - #endregion - - //Ticker 초기화 - if (DateTime.Now.Minute == 0 && saveFlag) - { - saveFlag = false; - } - else if (DateTime.Now.Minute > 1) saveFlag = true; + #endregion foreach (var item in realTimeMsg.coinFullNameList) { @@ -468,6 +474,10 @@ namespace Million_Buyer } buyList.Add(buyData); + + string str = "Buy : " + item + ",\r\n Buy Candle Data : " + JsonConvert.SerializeObject(recentlyData) + "\r\n"; + LogManager.WriteLog(str, item); + overlapBuyManagementList[item] = false; InsertLog(buyData.ConGoodsData.CoinFullName + " Market Data 구입 DateTime : " + time.ToString("yyyy-MM-dd HH:mm:ss")); //grid 처리 구매항목, 구매 가격, 구매 개수, 구매시점 @@ -531,10 +541,9 @@ namespace Million_Buyer result.WinCount = rate > 0 ? 1 : 0; result.LoseCount = rate < 0 ? 1 : 0; result.FirstWinFlag = rate > 0 ? true : false; - result.BuyCount = buyItem.CandleDataLists_Im[0].BuyCount; - result.SellCount = buyItem.CandleDataLists_Im[0].BuyCount; + result.SellCount = sellItem.BuyCount; // buycount 에서 sell count를 제외한 양이 미체결 량 if (!RealTimeMode) @@ -545,6 +554,10 @@ namespace Million_Buyer } resultDataList.Add(result); + + string str = "Sell : " + item + ",\r\n Sell Candle Data : " + JsonConvert.SerializeObject(recentlyData) + "\r\n"; + LogManager.WriteLog(str, item); + //처리한 buyList는 삭제 buyList.Remove(buyItem); InsertLog(buyItem.ConGoodsData.CoinFullName + " Market Data 판매 DateTime : " + time.ToString("yyyy-MM-dd HH:mm:ss")); @@ -743,6 +756,8 @@ namespace Million_Buyer InsertLog("Order List Thread Alive."); else InsertLog("Order List Thread Death."); + + AliveCheckor = true; } /// diff --git a/Million/Manager/CalculateManager.cs b/Million/Manager/CalculateManager.cs index fead813..b7687fe 100644 --- a/Million/Manager/CalculateManager.cs +++ b/Million/Manager/CalculateManager.cs @@ -15,7 +15,7 @@ namespace Million.Manager /// public static class CalculateManager { - public static InteratorScripter subScript = new InteratorScripter(); + public static InteratorScripter subScript = new InteratorScripter("최초 돌파 Sub Script"); /// /// /// @@ -608,12 +608,27 @@ namespace Million.Manager { subFlag = false; - if (recentlyDataFlag) - subManagement[coinFullName] = true; - else - firstFlag = false; + if(!(subManagement[coinFullName] || !firstFlag)) + { + var str = ""; + if (recentlyDataFlag) + { + subManagement[coinFullName] = true; + str = "Buyer(Realtime) Mode\r\n"; + } + + else + { + firstFlag = false; + str = "Hunter Mode\r\n"; + } + str += coinFullName + " 최초 돌파 Sub조건 초기화 됨\r\n"; + + LogManager.WriteLog(str, coinFullName); + } } + //sub 조건이 만족할 경우 if (subFlag) { @@ -624,21 +639,17 @@ namespace Million.Manager if (overlapData == 0) continue; + var valDic = ResultLogicManager.GetIndicateValue(dic, totalIndicators, parent); + var subVal = GetConditionValue(subScript.regularExpressionString, valDic, dic); + if (subVal == 0) continue; + if (upperMainIndicatorFlag) - { - var valDic = ResultLogicManager.GetIndicateValue(dic, totalIndicators, parent); - var subVal = GetConditionValue(subScript.regularExpressionString, valDic, dic); - if (subVal == 0) continue; if (overlapData < subVal) continue; - } //TODO Tick 차이 관련 조건 식 추가 예정 //최초로 매수, 매도 진행 시 사전 조건과의 Tick거리를 예외할 수 있어야 함 //OverlapValue는 사야할 데이터, beforeIndiValue는 사전 데이터 - var beforeIndiValue = parent.IndicatorDic[subKey].value; - if (beforeIndiValue == 0) continue; - - if (!GetTickDifferenceCount(overlapData, beforeIndiValue, 3)) continue; + if (!GetTickDifferenceCount(overlapData, subVal, 3)) continue; //최초 시점이 아닐 경우 if ((subManagement != null && subManagement[coinFullName]) || !firstFlag) @@ -647,7 +658,7 @@ namespace Million.Manager var enumList = setUp.OverStatusEnumList; if (setUp.SubIndicatorSetupType == SubIndicatorSetupType.최초돌파) enumList = setUp.OverStatusEnumListFirstOver; - + if (enumList.Any(t => t == parent.IndicatorDic[key].overStatus)) { GetTranspierceData(parent, childrenCandleDataList, setUp, overlapData, key, true); @@ -681,7 +692,7 @@ namespace Million.Manager { if (calBigData <= calSamllData) break; - calSamllData += 0.000001; + calSamllData += 0.0001; calSamllData = OrderbookManager.GetAskPrice(calSamllData); count++; } diff --git a/Million/Manager/InteratorScripter.cs b/Million/Manager/InteratorScripter.cs index 05acacf..1161cdf 100644 --- a/Million/Manager/InteratorScripter.cs +++ b/Million/Manager/InteratorScripter.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis.CSharp.Scripting; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +14,7 @@ namespace Million.Manager /// C# 코드기준으로 스크립팅 해줌 /// public string regularExpressionString; + public string Name; /// /// 캐쉬 Dictionary @@ -22,9 +24,10 @@ namespace Million.Manager /// /// 생성자 /// - public InteratorScripter() + public InteratorScripter(string Name) { rememberDic = new Dictionary, bool>(); + this.Name = Name; } /// @@ -34,6 +37,8 @@ namespace Million.Manager /// public bool DicExcuteScript(Dictionary RegularExpression) { + var cloneRex = RegularExpression.ToDictionary(x => x.Key, x => x.Value); + try { //중복 검사 @@ -42,13 +47,13 @@ namespace Million.Manager foreach(var key in rememberDic.Keys) { bool checker = true; - if(key.Count == RegularExpression.Count) + if(key.Count == cloneRex.Count) { foreach(var keyStr in key.Keys) { - if(RegularExpression.ContainsKey(keyStr)) + if(cloneRex.ContainsKey(keyStr)) { - if (key[keyStr] != RegularExpression[keyStr]) + if (key[keyStr] != cloneRex[keyStr]) checker = false; } else @@ -74,7 +79,16 @@ namespace Million.Manager } else { - return rememberDic[RegularExpression] = ScriptExcute(ChangeScript(regularExpressionString, RegularExpression)); + var returnData = ScriptExcute(ChangeScript(regularExpressionString, cloneRex)); + rememberDic[cloneRex] = returnData; + + var str = "Name : " + Name +",\r\nregularExpressionString : " + regularExpressionString + ",\r\n RegularExpression : " + + JsonConvert.SerializeObject(cloneRex) + ",\r\n Result : " + returnData.ToString() + + ",\r\n RememberDic : " + JsonConvert.SerializeObject(rememberDic) + "\r\n"; + + LogManager.WriteLog(str); + + return returnData; } } catch (Exception e) diff --git a/Million/Manager/LogManager.cs b/Million/Manager/LogManager.cs new file mode 100644 index 0000000..d1d617f --- /dev/null +++ b/Million/Manager/LogManager.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Million.Manager +{ + /// + /// Log Manager + /// + public static class LogManager + { + /// + /// Lock 관련 Field + /// + private static readonly object padlock = new object(); + + /// + /// Insert Log + /// + /// + /// + /// + public static bool WriteLog(string message, string coinFullName = "") + { + if (coinFullName == "") coinFullName = "common"; + var returnData = true; + var defaultMesage = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "=>" + message +"\r\n"; + var dirPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\")); + dirPath = dirPath + "\\Log"; + var filePath = dirPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "_" + coinFullName + ".txt"; + lock (padlock) + { + try + { + if (!System.IO.Directory.Exists(dirPath)) + { + System.IO.Directory.CreateDirectory(dirPath); + } + + if (!System.IO.File.Exists(filePath)) + { + System.IO.File.Create(filePath); + } + + System.IO.File.AppendAllText(filePath, defaultMesage); + } + catch (Exception e) + { + returnData = false; + } + } + + return returnData; + } + } +} diff --git a/Million/Manager/ResultLogicManager.cs b/Million/Manager/ResultLogicManager.cs index 0f631c0..2db16b8 100644 --- a/Million/Manager/ResultLogicManager.cs +++ b/Million/Manager/ResultLogicManager.cs @@ -68,9 +68,9 @@ namespace Million.Manager string buyRegularExpression, string sellRegularExpression, MarketData market, List totalIndicator, bool insertTermCandleData = false) { //buy, sell script 선언 - var buyScript = new InteratorScripter(); + var buyScript = new InteratorScripter("Buy Script"); buyScript.regularExpressionString = buyRegularExpression; - var sellScript = new InteratorScripter(); + var sellScript = new InteratorScripter("Sell Script"); sellScript.regularExpressionString = sellRegularExpression; diff --git a/Million/Million Core.csproj b/Million/Million Core.csproj index 6b0ebf5..5493499 100644 --- a/Million/Million Core.csproj +++ b/Million/Million Core.csproj @@ -194,6 +194,7 @@ +