From 88d27e78d70bdd19d93780126226e69619ebf134 Mon Sep 17 00:00:00 2001 From: Youngho Kim <1> Date: Sat, 9 Apr 2022 15:05:25 +0900 Subject: [PATCH] =?UTF-8?q?1.=20=EC=B5=9C=EC=8B=A0=20Ticker=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=ED=95=A8=EC=88=98=202.=20DB=20Data=20Saver=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=203.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataSaver/MainForm.cs | 6 +- Million Prototype/Form1.cs | 15 ++-- Million/CommonProperty.cs | 7 +- Million/DbMangement/DBServiceFunctions.cs | 34 +++++++-- Million/Manager/DataSettingManager.cs | 84 +++++++++++++++++++++++ Million/Million Core.csproj | 1 + 6 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 Million/Manager/DataSettingManager.cs diff --git a/DataSaver/MainForm.cs b/DataSaver/MainForm.cs index af54f3b..6dbf1be 100644 --- a/DataSaver/MainForm.cs +++ b/DataSaver/MainForm.cs @@ -11,14 +11,14 @@ namespace DataSaver public partial class MainForm : Form { // Key(임시) - public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; - public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; + //public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; + //public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; public MainForm() { InitializeComponent(); - CommonProperty.UpbitApi = new Million.WebMangement.Upbit.UpbitAPI(accessKey, secretKey); + //CommonProperty.UpbitApi = new Million.WebMangement.Upbit.UpbitAPI(accessKey, secretKey); InitForm(); } diff --git a/Million Prototype/Form1.cs b/Million Prototype/Form1.cs index 613db94..6b58e7b 100644 --- a/Million Prototype/Form1.cs +++ b/Million Prototype/Form1.cs @@ -3,6 +3,7 @@ using Million.Data; using Million.DbManagement; using Million.Indicators; +using Million.Manager; using Million.WebMangement.Upbit; using System; using System.Collections.Generic; @@ -20,9 +21,9 @@ namespace Million_Prototype { public partial class Form1 : Form { - public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; - public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; - UpbitAPI uApi = new UpbitAPI(accessKey,secretKey); + //public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; + //public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; + //UpbitAPI uApi = new UpbitAPI(accessKey,secretKey); Stopwatch sw = new Stopwatch(); public Form1() { @@ -39,7 +40,7 @@ namespace Million_Prototype private void button1_Click(object sender, EventArgs e) { sw.Restart(); - var data = uApi.GetMarketDatas(); //전체 목록 + var data = UpbitApi.GetMarketDatas(); //전체 목록 var krwList = data.FindAll(x => x.Payment.Contains("KRW")); //한화 목록 List dataList = new List(); @@ -53,7 +54,7 @@ namespace Million_Prototype //4시간 가져오기 foreach(var krw in dataList) { - krw.CandleDataLists_Im= uApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.H4, dateTime); + krw.CandleDataLists_Im= UpbitApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.H4, dateTime); } /* @@ -80,7 +81,7 @@ namespace Million_Prototype var test = krwList.Select(t => t.CodeFullName).ToList(); //var 현재가 = uApi.GetOrderBookList(test);GetTickerList - var 현재가 = uApi.GetTickerList(test); + var 현재가 = UpbitApi.GetTickerList(test); foreach (var krw in krwList) { @@ -126,6 +127,8 @@ namespace Million_Prototype candleData.CandleDataLists_Im.ToString(); } + //var datas = DataSettingManager.GetBasicDataSetting(PaymentType.KRW, MCandleTimeType.M1, 100001); + } } } diff --git a/Million/CommonProperty.cs b/Million/CommonProperty.cs index 30446b2..3605891 100644 --- a/Million/CommonProperty.cs +++ b/Million/CommonProperty.cs @@ -17,7 +17,9 @@ namespace Million { #region default로 가지고 있어야하는 데이터 - public static UpbitAPI UpbitApi = null; + public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb"; + public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz"; + public static UpbitAPI UpbitApi = new UpbitAPI(accessKey, secretKey); #endregion #region Enumable @@ -165,8 +167,9 @@ namespace Million // 현재 시점에서 사용되고 있는 Place의 Market List 정보 public static List selectedMarketOfPlaceList = null; - public static List recentlyMarketOfPlaceList = null; + public static List recentlyMarketOfPlaceList = null; #endregion + } } diff --git a/Million/DbMangement/DBServiceFunctions.cs b/Million/DbMangement/DBServiceFunctions.cs index 5ebfb62..bf38abb 100644 --- a/Million/DbMangement/DBServiceFunctions.cs +++ b/Million/DbMangement/DBServiceFunctions.cs @@ -60,18 +60,34 @@ namespace Million.DbManagement } /// - /// DB로부터 코인(Market) 정보 가져오기 + /// DB로부터 코인(Market) 정보 가져오기(Data Saver 전용) /// /// /// - public static void GetMarketTable_FromDB(string TableName) + public static void GetMarketTable_FromDB(string tableName) + { + selectedMarketOfPlaceList = GetMarketDatas(tableName); + } + + /// + /// DB에서 Market Data 정보 가져오는 함수 + /// + /// + /// + public static List GetMarketDatas(string tableName, string payment = null) { var strDbCon = $"{CommonProperty.DbConnectionStr}Market"; - // Query문 만들기 - var sqlQuery = string.Format("select * from dbo.{0} where IsValid = 1;", TableName); + var subSql = ""; + if(payment != null) + { + subSql = string.Format("AND [Payment] = '{0}'", payment); + } - selectedMarketOfPlaceList = DBConnection.QueryGetExcuter_Market(strDbCon, sqlQuery); + // Query문 만들기 + var sqlQuery = string.Format("select * from dbo.{0} where IsValid = 1 {1};", tableName, subSql); + + return DBConnection.QueryGetExcuter_Market(strDbCon, sqlQuery); } /// @@ -243,6 +259,7 @@ namespace Million.DbManagement var dateTime = DateTime.Now; var tableName = item.ConGoodsData.CodeFullName; int step = 0; + bool firstFlag = true; var recentlyFlag = true; switch (place) { @@ -282,6 +299,13 @@ namespace Million.DbManagement insertDataList = insertDataList.OrderBy(t => t.DateTime).ToList(); + if (firstFlag) { + if(insertDataList.Count > 0) { + insertDataList.Remove(insertDataList[insertDataList.Count - 1]); + firstFlag = false; + } + } + //데이터 insert foreach (var data in insertDataList) { diff --git a/Million/Manager/DataSettingManager.cs b/Million/Manager/DataSettingManager.cs new file mode 100644 index 0000000..90c3914 --- /dev/null +++ b/Million/Manager/DataSettingManager.cs @@ -0,0 +1,84 @@ +using Million.Data; +using Million.Data.Upbit; +using Million.DbManagement; +using Million.WebMangement.Upbit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using static Million.CommonProperty; + +namespace Million.Manager +{ + /// + /// Data Setting하는 Manager Class + /// + public static class DataSettingManager + { + /// + /// 실시간 데이터 가져오는 함수(Ticker와 CandleDataList두개를 Return 할 수 있도록 구성) + /// + /// + /// + /// + /// + public static List GetRecentlyCandleData(List codeFullNameList = null, string tableName = "Upbit") + { + var dateTime = DateTime.Now; + var resultList = new List(); + var marketList = DbServiceFunctions.GetMarketDatas(tableName); + + //null일경우 전체가 가져옴 + if (codeFullNameList == null) + { + //Upbit로 임시 + codeFullNameList = marketList.Select(t => t.CodeFullName).ToList(); + } + + var tickerList = CommonProperty.UpbitApi.GetTickerList(codeFullNameList); + + return tickerList; + } + + + + ///// + ///// 기본 시작시 필요한 Data Setting + ///// + ///// + ///// + ///// + ///// + //public static List GetBasicDataSetting(PaymentType buyType, MCandleTimeType timeType, int count = 100000, List codeFullNameList = null, string tableName = "Upbit") + //{ + // var returnData = new List(); + + // var dateTime = DateTime.Now; + // var resultList = new List(); + + + // var marketList = DbServiceFunctions.GetMarketDatas(tableName, Enum.GetName(typeof(PaymentType), buyType)); + + // //null일경우 전체가 가져옴 + // if (codeFullNameList == null) + // { + // //Upbit로 임시 + // codeFullNameList = marketList.Select(t => t.CodeFullName).ToList(); + // } + + // Parallel.For(0, codeFullNameList.Count, i => + // { + // var val = new CandleDataList(); + // val.ConGoodsData = marketList.FirstOrDefault(t => t.CodeFullName == codeFullNameList[i]); + // val.CandleDataLists_Im = CommonProperty.UpbitApi.GetCandleStics(codeFullNameList[i], timeType, dateTime, count); + + // returnData.Add(val); + // }); + + + // return returnData; + //} + } +} diff --git a/Million/Million Core.csproj b/Million/Million Core.csproj index 522526b..6c2d23c 100644 --- a/Million/Million Core.csproj +++ b/Million/Million Core.csproj @@ -127,6 +127,7 @@ MainForm.cs +