diff --git a/ULBalanceDlg.cs b/ULBalanceDlg.cs index ee6289b..73ee389 100644 --- a/ULBalanceDlg.cs +++ b/ULBalanceDlg.cs @@ -225,18 +225,21 @@ namespace upper_limit_crawler if (iCurPrice <= OwnItem.m_iUnitBEP * (1.0f - m_DataMgr.m_Setting.m_fLossCut)) { m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance); - m_OwnList.Remove(OwnItem); + m_OwnList.Remove(OwnItem); m_DataMgr.RemoveWatch(strCode); m_DataMgr.AddLosscutItem(strCode); - ULUtil.Trace("[{0}] 손절 {1}원 ({2}) {3}", OwnItem.m_strCodeName, iCurPrice, (iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f).ToString("0.00%"), WatchItem.m_iHighestPrice); - ULUtil.TraceCSV("손절", OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%"), WatchItem.m_iHighestPrice); - + int iProfit = iCurPrice-(int)OwnItem.m_iUnitBEP; + float fProfitRate = iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f; - // own에서 삭제하고 미체결 리스트에 넣고, watch에서도 뺀다 + ULUtil.Trace("[{0}] 손절 {1}원 ({2}) {3}", OwnItem.m_strCodeName, iCurPrice, fProfitRate.ToString("0.00%"), WatchItem.m_iHighestPrice); + ULUtil.TraceCSV("손절", OwnItem.m_strCodeName, iCurPrice, fProfitRate.ToString("0.00%"), WatchItem.m_iHighestPrice); + m_DataMgr.AddAskLog(strCode, WatchItem.m_strCodeName, iTime, iCurPrice, float.NaN, true, iProfit, fProfitRate); - // 미체결 잔량 취소 - } + // own에서 삭제하고 미체결 리스트에 넣고, watch에서도 뺀다 + + // 미체결 잔량 취소 + } // trailing else if (iCurPrice <= OwnItem.m_iMaxPrice - OwnItem.m_iUnitBEP * m_DataMgr.m_Setting.m_fTrailing) { @@ -251,15 +254,19 @@ namespace upper_limit_crawler m_OwnList.Remove(OwnItem); m_DataMgr.RemoveWatch(strCode); - ULUtil.Trace("[{0}] 트레일링 매도 {1}원 ({2}:{3}) (5MA slop:{4}) {5}", + int iProfit = iCurPrice-(int)OwnItem.m_iUnitBEP; + float fProfitRate = iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f; + + ULUtil.Trace("[{0}] 트레일링 매도 {1}원 ({2}:{3}) (5MA slop:{4}) {5}", OwnItem.m_strCodeName, iCurPrice, iCurPrice - OwnItem.m_iUnitBEP, (iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f).ToString("0.00%"), f5MASlope.ToString("0.00%"), WatchItem.m_iHighestPrice); - ULUtil.TraceCSV("트레일링 매도", OwnItem.m_strCodeName, iCurPrice, iCurPrice - OwnItem.m_iUnitBEP, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%"), f5MASlope.ToString("0.00%"), WatchItem.m_iHighestPrice); - } + ULUtil.TraceCSV("트레일링 매도", OwnItem.m_strCodeName, iCurPrice, iCurPrice - OwnItem.m_iUnitBEP, fProfitRate.ToString("0.00%"), f5MASlope.ToString("0.00%"), WatchItem.m_iHighestPrice); + m_DataMgr.AddAskLog(strCode, WatchItem.m_strCodeName, iTime, iCurPrice, float.NaN, false, iProfit, fProfitRate); + } } // steadiness diff --git a/ULDB.cs b/ULDB.cs new file mode 100644 index 0000000..3f77493 --- /dev/null +++ b/ULDB.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace upper_limit_crawler +{ + public class ULDB + { + const string DBNAME = "DB"; + + LevelDB.DB m_DB = null; + LevelDB.WriteOptions m_DefaultWriteOption = new LevelDB.WriteOptions(); + LevelDB.ReadOptions m_DefaultReadOption = new LevelDB.ReadOptions(); + + public ULDB() + { + LevelDB.Options OpenOption = new LevelDB.Options(); + OpenOption.CreateIfMissing=true; + m_DB=LevelDB.DB.Open(DBNAME, OpenOption); + } + + public void Put(string strKey, LevelDB.Slice Value) + { + m_DB.Put(m_DefaultWriteOption, strKey, Value); + } + + public LevelDB.Slice Get(string strKey) + { + LevelDB.Slice Value = m_DB.Get(m_DefaultReadOption, strKey); + return Value; + } + } +} diff --git a/ULDataMgr.cs b/ULDataMgr.cs index bb72305..e70141d 100644 --- a/ULDataMgr.cs +++ b/ULDataMgr.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -34,20 +35,27 @@ namespace upper_limit_crawler public class ULDataMgr { public SETTING m_Setting = new SETTING(); + public ULDB m_DB = new ULDB(); - ULTrader m_Trader = new ULTrader(); + ULTrader m_Trader = new ULTrader(); Dictionary m_WatchList = new Dictionary(); List m_PostponeList = new List(); Dictionary m_LossCutList = new Dictionary(); List m_BlackList = new List(); + string m_AvailableListKey; + List m_AvailableList = new List(); + long m_iCacheBalance = 0; long m_iEvalProfit = 0; public ULDataMgr() { - } + m_AvailableListKey= "available-"+ULUtil.GetCurTime().ToString("yyyy-MM-dd"); + string strValue = m_DB.Get(m_AvailableListKey).ToString(); + m_AvailableList=strValue.Split(',').ToList(); + } public void Init() { @@ -167,5 +175,33 @@ namespace upper_limit_crawler { return m_iEvalProfit; } - } + + public ULDB GetDB() + { + return m_DB; + } + + public void AddAvailableItem(string strCode) + { + if(m_AvailableList.Any(r => r==strCode)==false) + { + m_AvailableList.Add(strCode); + m_DB.Put(m_AvailableListKey, string.Join(",", m_AvailableList)); + } + } + + public void AddBidLog(string strCode, string strCodeName, int iTime, int iBidPrice, float f5MAslope) + { + string strKey = string.Format("bid-{0}-{1}-{2}", ULUtil.GetCurTime().ToString("yyyyMMdd"), iTime, strCodeName); + string strValue = string.Format("{0},{1},{2},{3},{4}", strCodeName, strCode, iTime, iBidPrice, f5MAslope); + m_DB.Put(strKey, strValue); + } + + public void AddAskLog(string strCode, string strCodeName, int iTime, int iBidPrice, float f5MAslope, bool bLosscut, int iProfit, float fProfitRate) + { + string strKey = string.Format("ask-{0}-{1}-{2}", ULUtil.GetCurTime().ToString("yyyyMMdd"), iTime, strCodeName); + string strValue = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", strCodeName, strCode, iTime, iBidPrice, f5MAslope, bLosscut?"Losscut":"Trailing", iProfit, fProfitRate); + m_DB.Put(strKey, strValue); + } + } } diff --git a/ULMonitorDlg.cs b/ULMonitorDlg.cs index c54d481..ad29c0d 100644 --- a/ULMonitorDlg.cs +++ b/ULMonitorDlg.cs @@ -159,6 +159,8 @@ namespace upper_limit_crawler if (fCompRate >= m_DataMgr.m_Setting.m_fBidMin && fCompRate <= m_DataMgr.m_Setting.m_fBidMax) { + m_DataMgr.AddAvailableItem(strCode); + int iTime = ULUtil.GetCurTimeInt(); if (m_DataMgr.IsInPostponeList(iTime, strCode) == true) { @@ -179,8 +181,8 @@ namespace upper_limit_crawler // bid and add to black list m_DataMgr.GetTrader().Buy(strCode, item.m_iCurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount); - m_DataMgr.AddPostphoneItem(iTime, strCode); - + m_DataMgr.AddBidLog(strCode, item.m_strCodeName, iTime, item.m_iCurPrice, f5MASlope); + m_DataMgr.AddPostphoneItem(iTime, strCode); ULUtil.Trace("[{0}] 조건 매수 {1}원 ({2}) (5MA slop:{3})", item.m_strCodeName, diff --git a/upper-limit-crawler.csproj b/upper-limit-crawler.csproj index 579ddf2..622c220 100644 --- a/upper-limit-crawler.csproj +++ b/upper-limit-crawler.csproj @@ -12,25 +12,6 @@ v4.5 512 - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false @@ -43,7 +24,30 @@ Properties\app.manifest + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + packages\LevelDB.Net.1.2.1\lib\net40\LevelDB.Net.dll + @@ -56,6 +60,7 @@ + Form diff --git a/upper-limit-crawler.sln b/upper-limit-crawler.sln index e4d8f3a..a647775 100644 --- a/upper-limit-crawler.sln +++ b/upper-limit-crawler.sln @@ -1,20 +1,20 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "upper-limit-crawler", "upper-limit-crawler.csproj", "{591FA710-356A-498A-8133-7E9E60AB4E40}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {591FA710-356A-498A-8133-7E9E60AB4E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {591FA710-356A-498A-8133-7E9E60AB4E40}.Debug|Any CPU.Build.0 = Debug|Any CPU - {591FA710-356A-498A-8133-7E9E60AB4E40}.Release|Any CPU.ActiveCfg = Release|Any CPU - {591FA710-356A-498A-8133-7E9E60AB4E40}.Release|Any CPU.Build.0 = Release|Any CPU + {591FA710-356A-498A-8133-7E9E60AB4E40}.Debug|x64.ActiveCfg = Debug|x64 + {591FA710-356A-498A-8133-7E9E60AB4E40}.Debug|x64.Build.0 = Debug|x64 + {591FA710-356A-498A-8133-7E9E60AB4E40}.Release|x64.ActiveCfg = Release|x64 + {591FA710-356A-498A-8133-7E9E60AB4E40}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE