Upbit Data Save 관련 로직 개발 완료
This commit is contained in:
3
DataSaver/MainForm.Designer.cs
generated
3
DataSaver/MainForm.Designer.cs
generated
@@ -170,8 +170,7 @@
|
||||
this.comboBoxEdit_MarketInfo.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
|
||||
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
|
||||
this.comboBoxEdit_MarketInfo.Size = new System.Drawing.Size(113, 20);
|
||||
this.comboBoxEdit_MarketInfo.TabIndex = 3;
|
||||
this.comboBoxEdit_MarketInfo.SelectedIndexChanged += new System.EventHandler(this.comboBoxEdit_ExchangePlace_SelectedIndexChanged);
|
||||
this.comboBoxEdit_MarketInfo.TabIndex = 3;
|
||||
//
|
||||
// button_AllMarketDataAcc
|
||||
//
|
||||
|
||||
@@ -57,13 +57,17 @@ namespace DataSaver
|
||||
/// <param name="e"></param>
|
||||
private void comboBoxEdit_ExchangePlace_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
// DB 서버 정보 수정
|
||||
//var strConn = Million.CommonProperty.DbConnectionStr + comboBoxEdit_ExchangePlace.EditValue;
|
||||
//Million.CommonProperty.ConDbConnectionStr = strConn;
|
||||
|
||||
// DB 종목(Market) 정보 가져오기
|
||||
Million.DbManagement.DbServiceFunctions.GetMarketTable_FromDB(comboBoxEdit_ExchangePlace.SelectedItem.ToString());
|
||||
updateMarketTableOfPlace();
|
||||
Million.DbManagement.DbServiceFunctions.GetMarketTable_FromDB(comboBoxEdit_ExchangePlace.SelectedItem.ToString());
|
||||
updateMarketTableOfPlace();
|
||||
|
||||
//초창기 생성시에 데이터가 없음으로 Update이 후 재 처리
|
||||
if(CommonProperty.selectedMarketOfPlaceList == null || CommonProperty.selectedMarketOfPlaceList.Count == 0)
|
||||
Million.DbManagement.DbServiceFunctions.GetMarketTable_FromDB(comboBoxEdit_ExchangePlace.SelectedItem.ToString());
|
||||
|
||||
// 데이터 입력
|
||||
var marketList = CommonProperty.selectedMarketOfPlaceList;
|
||||
comboBoxEdit_MarketInfo.Properties.Items.AddRange(marketList.Select(t => t.CodeName).ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,26 +78,7 @@ namespace DataSaver
|
||||
private void button_AllMarketDataAcc_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dbMarketDataList = CommonProperty.selectedMarketOfPlaceList;
|
||||
|
||||
// table 명으로 사용할 Name List => Primary key
|
||||
var marketNameList = dbMarketDataList.Select(t => t.CodeFullName).ToList();
|
||||
|
||||
string sqlQuery = "";
|
||||
|
||||
// 없는 테이블 먼저 생성
|
||||
foreach (var item in marketNameList)
|
||||
sqlQuery += Million.DbManagement.DbServiceFunctions.CreateMarketTable_ToDB(item);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(sqlQuery))
|
||||
Million.DbManagement.DBConnection.QueryUpdateExcuter(CommonProperty.DbConnectionMarket, sqlQuery);
|
||||
|
||||
//거래소 가져오기
|
||||
var place = comboBoxEdit_ExchangePlace.SelectedItem.ToString();
|
||||
|
||||
var recentlyDbDataList = Million.DbManagement.DbServiceFunctions.GetOldNewDataList_FromDB
|
||||
(dbMarketDataList, comboBoxEdit_ExchangePlace.SelectedItem.ToString());
|
||||
|
||||
Million.DbManagement.DbServiceFunctions.SetCandleData(place, recentlyDbDataList);
|
||||
SetCandleData(comboBoxEdit_ExchangePlace.SelectedItem.ToString(), dbMarketDataList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,10 +88,62 @@ namespace DataSaver
|
||||
/// <param name="e"></param>
|
||||
private void button_SelectedMarketDataAcc_Click(object sender, EventArgs e)
|
||||
{
|
||||
//Create
|
||||
if(!string.IsNullOrWhiteSpace(comboBoxEdit_PaymentType.SelectedItem?.ToString()) &&
|
||||
!string.IsNullOrWhiteSpace(comboBoxEdit_MarketInfo.SelectedItem?.ToString())
|
||||
)
|
||||
{
|
||||
var market = comboBoxEdit_PaymentType.SelectedItem.ToString() + "-" + comboBoxEdit_MarketInfo.SelectedItem.ToString();
|
||||
|
||||
var marketList = new List<MarketData>();
|
||||
marketList.Add(CommonProperty.selectedMarketOfPlaceList.FirstOrDefault(t => t.CodeFullName == market));
|
||||
|
||||
SetCandleData(comboBoxEdit_ExchangePlace.SelectedItem.ToString(), marketList);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Select 하세요
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCandleData(string placeName, List<MarketData> marketList)
|
||||
{
|
||||
//Table생성
|
||||
CreateTableOfMarket(placeName);
|
||||
|
||||
//거래소 가져오기
|
||||
|
||||
var type = CommonProperty.ExchangeWebReqType.UpbitCandleStick;
|
||||
|
||||
if (placeName.Equals("Bithumb"))
|
||||
type = CommonProperty.ExchangeWebReqType.BithumbCandleTicker;
|
||||
|
||||
var recentlyDbDataList = Million.DbManagement.DbServiceFunctions.GetOldNewDataList_FromDB
|
||||
(marketList, placeName);
|
||||
|
||||
Million.DbManagement.DbServiceFunctions.SetCandleData(placeName, type, recentlyDbDataList);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Market 별 Table 생성
|
||||
/// </summary>
|
||||
private void CreateTableOfMarket(string placeName)
|
||||
{
|
||||
var dbMarketDataList = CommonProperty.selectedMarketOfPlaceList;
|
||||
|
||||
// table 명으로 사용할 Name List => Primary key
|
||||
var marketNameList = dbMarketDataList.Select(t => t.CodeFullName).ToList();
|
||||
|
||||
string sqlQuery = "";
|
||||
// 없는 테이블 먼저 생성
|
||||
foreach (var item in marketNameList)
|
||||
sqlQuery += Million.DbManagement.DbServiceFunctions.CreateMarketTable_ToDB(item);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(sqlQuery))
|
||||
Million.DbManagement.DBConnection.QueryUpdateExcuter(CommonProperty.DbConnectionStr + placeName, sqlQuery);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 선택한 거래소의 종목(Market) 업데이트
|
||||
@@ -125,7 +162,6 @@ namespace DataSaver
|
||||
CommonProperty.recentlyMarketOfPlaceList = (List<MarketData>)
|
||||
Million.WebServices.WebConnection.SendWebServer(CommonProperty.ExchangeWebReqType.UpbitMarket,
|
||||
DateTime.Now);
|
||||
|
||||
break;
|
||||
//case (int)CommonProperty.ExchangePlace.Bithumb:
|
||||
// marketList = Million.DbManagement.DbServiceFunctions.GetMarketTable_FromDB(
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Million
|
||||
POST = 0,
|
||||
GET = 1
|
||||
}
|
||||
|
||||
|
||||
// 거래소 타입
|
||||
public enum ExchangePlace
|
||||
{
|
||||
@@ -38,7 +38,7 @@ namespace Million
|
||||
}
|
||||
|
||||
// 최신, 가장오래된, None
|
||||
public enum CandleTimeType
|
||||
public enum CandleType
|
||||
{
|
||||
None = 0,
|
||||
Old = 1,
|
||||
@@ -61,22 +61,31 @@ namespace Million
|
||||
#endregion
|
||||
|
||||
#region 업비트 웹 요청 타입
|
||||
[Description("")]
|
||||
UpbitMarket = 11
|
||||
|
||||
[Description("UpbitCandle")]
|
||||
UpbitCandleStick = 10,
|
||||
[Description("UpbitMarket")]
|
||||
UpbitMarket = 11
|
||||
#endregion
|
||||
}
|
||||
|
||||
// 캔들 데이터 (1분) (3분) (5분) (10분) (30분) (1시간) (6시간) (12시간) (24시간)
|
||||
public enum CanldeTimeType
|
||||
{
|
||||
M1 = 1, M3 = 3, M5= 5, M10 = 10, M30 = 30, H1 = 60, H6 = 360, M12 = 720, D1 = 1440
|
||||
public enum CandleTimeType
|
||||
{
|
||||
M1 = 1,
|
||||
M3 = 3,
|
||||
M5 = 5,
|
||||
M10 = 10,
|
||||
M30 = 30,
|
||||
H1 = 60,
|
||||
H6 = 360,
|
||||
M12 = 720,
|
||||
D1 = 1440
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 빗썸 URL
|
||||
public static string BithumbURL= "https://api.bithumb.com/";
|
||||
public static string BithumbURL = "https://api.bithumb.com/";
|
||||
public static string BithumbURL_CandleStick = "https://api.bithumb.com/public/candlestick/";
|
||||
public static string BithumbURL_CoinGoods = "https://api.bithumb.com/public/orderbook/ALL_KRW";
|
||||
#endregion
|
||||
@@ -84,7 +93,7 @@ namespace Million
|
||||
#region 업비트 URL
|
||||
public static string UpbitURL = "https://api.upbit.com/";
|
||||
public static string UpbitURL_MarketInfo = "https://api.upbit.com/v1/market/all?isDetails=false";
|
||||
public static string upbitURL_CandleStick = "https://api.upbit.com/v1/candles/minutes";
|
||||
public static string upbitURL_CandleStick = "https://api.upbit.com/v1/candles/";
|
||||
|
||||
//"https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=3&to=2019-12-22 01:00:00";
|
||||
#endregion
|
||||
@@ -130,6 +139,20 @@ namespace Million
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create Upbit URI
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="codeFullName"></param>
|
||||
/// <param name="date">null 일경우 현재날짜</param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public static string CreateUpbitUri(CandleTimeType type, string codeFullName, DateTime date, int count = 200)
|
||||
{
|
||||
if (date == null)
|
||||
date = DateTime.Now;
|
||||
|
||||
return string.Format("minutes/{0}?market={1}&count={2}&to={3}", (int)type, codeFullName, count, date.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,21 +20,7 @@ namespace Million.Data
|
||||
|
||||
public int CandleTimeType { get; set; }
|
||||
|
||||
public CandleTimeType CandleType { get; set; }
|
||||
|
||||
public CandleData(string dateTime, float startValue,
|
||||
float endValue, float highValue, float lowValue, float moneyVolume, int candleTimeType)
|
||||
{
|
||||
// Enum.GetName(typeof(CommonProperty.ExchangePlace), exchangePlace);
|
||||
|
||||
DateTime = ChangeBithumbStringToDateTime(dateTime);
|
||||
StartValue = startValue;
|
||||
EndValue = endValue;
|
||||
HighValue = highValue;
|
||||
LowValue = lowValue;
|
||||
MoneyVolume = moneyVolume;
|
||||
CandleTimeType = candleTimeType;
|
||||
}
|
||||
public CandleType CandleType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 빗썸 DateTime 변환 로직
|
||||
|
||||
@@ -102,15 +102,15 @@ namespace Million.DbManagement
|
||||
float.TryParse(rdr["MoneyVolume"]?.ToString(), out var moneyVolume);
|
||||
int.TryParse(rdr["CandleTimeType"]?.ToString(), out var candleTimeType);
|
||||
|
||||
var data = new CandleData(
|
||||
dateTime,
|
||||
startValue,
|
||||
endValue,
|
||||
highValue,
|
||||
lowValue,
|
||||
moneyVolume,
|
||||
candleTimeType
|
||||
);
|
||||
var data = new CandleData();
|
||||
data.DateTime = Convert.ToDateTime(dateTime);
|
||||
data.StartValue = startValue;
|
||||
data.EndValue = endValue;
|
||||
data.HighValue = highValue;
|
||||
data.LowValue = lowValue;
|
||||
data.MoneyVolume = moneyVolume;
|
||||
data.CandleTimeType = candleTimeType;
|
||||
|
||||
returnData.Add(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Million.Data;
|
||||
using static Million.CommonProperty;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Million.DbManagement
|
||||
{
|
||||
@@ -66,9 +69,9 @@ namespace Million.DbManagement
|
||||
var strDbCon = $"{CommonProperty.DbConnectionStr}Market";
|
||||
|
||||
// Query문 만들기
|
||||
var sqlQuery = string.Format("select * from dbo.{0} where IsValid = 1;", TableName);
|
||||
var sqlQuery = string.Format("select * from dbo.{0} where IsValid = 1;", TableName);
|
||||
|
||||
CommonProperty.selectedMarketOfPlaceList = DBConnection.QueryGetExcuter_Market(strDbCon, sqlQuery);
|
||||
selectedMarketOfPlaceList = DBConnection.QueryGetExcuter_Market(strDbCon, sqlQuery);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,10 +96,10 @@ namespace Million.DbManagement
|
||||
") AS RankNo FROM {0}) T WHERE RankNo = 1;", item.CodeFullName);
|
||||
var recentlyDataList = DBConnection.QueryGetExcuter_Candle(strDbCon, sqlQuery);
|
||||
|
||||
if(recentlyDataList.Count > 0)
|
||||
if (recentlyDataList.Count > 0)
|
||||
{
|
||||
recentlyDataList[0].CandleType = CandleTimeType.New;
|
||||
data.CandleDataLists_Im = recentlyDataList;
|
||||
recentlyDataList[0].CandleType = CandleType.New;
|
||||
data.CandleDataLists_Im = recentlyDataList;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,7 +122,7 @@ namespace Million.DbManagement
|
||||
var recentlyDataList = DBConnection.QueryGetExcuter_Candle(strDbCon, sqlQuery);
|
||||
if (recentlyDataList.Count > 0)
|
||||
{
|
||||
recentlyDataList[0].CandleType = CandleTimeType.Old;
|
||||
recentlyDataList[0].CandleType = CandleType.Old;
|
||||
item.CandleDataLists_Im.AddRange(recentlyDataList);
|
||||
}
|
||||
}
|
||||
@@ -132,12 +135,98 @@ namespace Million.DbManagement
|
||||
/// </summary>
|
||||
/// <param name="place"></param>
|
||||
/// <param name="recentlyDbDataList"></param>
|
||||
public static void SetCandleData(string place, List<CandleDataList> recentlyDbDataList)
|
||||
public static void SetCandleData(string placeName, ExchangeWebReqType place, List<CandleDataList> recentlyDbDataList)
|
||||
{
|
||||
var dateTime = DateTime.Now;
|
||||
|
||||
//데이터 쌓는 부분은 재귀로 처리할 예정
|
||||
/**
|
||||
* 단계 조정
|
||||
* 아무것도 없을 경우 0
|
||||
* 있을 경우1
|
||||
* 완료 2
|
||||
*/
|
||||
|
||||
var insertQuery = "";
|
||||
|
||||
foreach (var item in recentlyDbDataList)
|
||||
{
|
||||
var sw = new System.Diagnostics.Stopwatch();
|
||||
sw.Start();
|
||||
var tableName = item.ConGoodsData.CodeFullName;
|
||||
int step = 0;
|
||||
switch (place)
|
||||
{
|
||||
case ExchangeWebReqType.UpbitCandleStick:
|
||||
|
||||
//최신 부터
|
||||
var recentlyDateTime = new DateTime(1970, 1, 1);
|
||||
var oldDateTime = new DateTime(1970, 1, 1);
|
||||
CandleData recentlyData = null;
|
||||
CandleData oldData = null;
|
||||
|
||||
if (item.CandleDataLists_Im.Count > 0)
|
||||
{
|
||||
recentlyData = item.CandleDataLists_Im.Find(t => t.CandleType == CandleType.New);
|
||||
recentlyDateTime = recentlyData.DateTime;
|
||||
oldData = item.CandleDataLists_Im.Find(t => t.CandleType == CandleType.Old);
|
||||
oldDateTime = oldData.DateTime;
|
||||
|
||||
step = 1;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
var webDataList = (List<CandleData>)Million.WebServices.WebConnection.SendWebServer(
|
||||
ExchangeWebReqType.UpbitCandleStick,
|
||||
dateTime,
|
||||
"",
|
||||
CreateUpbitUri(CandleTimeType.M1, item.ConGoodsData.CodeFullName, dateTime)
|
||||
);
|
||||
var insertDataList = new List<CandleData>();
|
||||
|
||||
if (step == 0)
|
||||
{
|
||||
insertDataList = webDataList;
|
||||
}
|
||||
else if (step == 1)
|
||||
{
|
||||
insertDataList.AddRange(webDataList.Where(t => t.DateTime > recentlyDateTime).ToList());
|
||||
insertDataList.AddRange(webDataList.Where(t => t.DateTime < oldDateTime).ToList());
|
||||
}
|
||||
|
||||
insertDataList = insertDataList.OrderBy(t => t.DateTime).ToList();
|
||||
|
||||
//데이터 insert
|
||||
foreach (var data in insertDataList)
|
||||
{
|
||||
insertQuery += string.Format("INSERT INTO [dbo].[{0}]([DateTime],[StartValue], [EndValue], [HighValue], [LowValue], [MoneyValue], [CandleTimeType]) VALUES ('{1}',{2},{3},{4},{5},{6},{7})",
|
||||
tableName, data.DateTime.ToString("yyyy-MM-dd HH:mm:ss"), data.StartValue, data.EndValue, data.HighValue, data.LowValue, data.MoneyVolume, data.CandleTimeType);
|
||||
}
|
||||
|
||||
if (insertDataList.Count == 0)
|
||||
step = 2;
|
||||
else
|
||||
dateTime = insertDataList[0].DateTime;
|
||||
if (step == 2)
|
||||
break;
|
||||
//초당 8회 이상안됨 (0.125초)
|
||||
if (!string.IsNullOrWhiteSpace(insertQuery))
|
||||
DBConnection.QueryUpdateExcuter(DbConnectionStr + placeName, insertQuery);
|
||||
Thread.Sleep(130);
|
||||
insertQuery = "";
|
||||
}
|
||||
|
||||
break;
|
||||
case ExchangeWebReqType.BithumbCandleTicker:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Console.WriteLine("Completed Set Candle Data of Table : " + tableName + ", Times : " + sw.Elapsed.ToString());
|
||||
}
|
||||
MessageBox.Show("Completed Set Candle Data of Place : " + placeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Million.WebServices
|
||||
/// </summary>
|
||||
public class WebConnection
|
||||
{
|
||||
public static object SendWebServer(CommonProperty.ExchangeWebReqType exchangeWebReqType,DateTime dateTime, string postData = "")
|
||||
public static object SendWebServer(CommonProperty.ExchangeWebReqType exchangeWebReqType, DateTime dateTime, string postData = "", string subUri = "")
|
||||
{
|
||||
var returnJsonData = new Dictionary<string, object>();
|
||||
|
||||
@@ -57,7 +57,11 @@ namespace Million.WebServices
|
||||
case CommonProperty.ExchangeWebReqType.UpbitMarket:
|
||||
wReq = (HttpWebRequest)WebRequest.Create(new Uri(CommonProperty.UpbitURL_MarketInfo));
|
||||
break;
|
||||
#endregion
|
||||
|
||||
case CommonProperty.ExchangeWebReqType.UpbitCandleStick:
|
||||
wReq = (HttpWebRequest)WebRequest.Create(new Uri(CommonProperty.upbitURL_CandleStick + subUri));
|
||||
break;
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
@@ -82,78 +86,30 @@ namespace Million.WebServices
|
||||
var respPostStream = wRes.GetResponseStream();
|
||||
var readerPost = new StreamReader(respPostStream, Encoding.UTF8, true);
|
||||
var resResult = readerPost.ReadToEnd();
|
||||
var resultData = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(resResult);
|
||||
|
||||
// 오류 코드 예외처리
|
||||
/*
|
||||
var resultDataList = resultData["status"].ToString().Equals("0000")
|
||||
? resultData["data"]
|
||||
: null;*/
|
||||
|
||||
switch (exchangeWebReqType)
|
||||
{
|
||||
#region MyRegion
|
||||
/*
|
||||
|
||||
// 빗썸 캔들 데이터
|
||||
case CommonProperty.ExchangeWebReqType.BithumbCandleStick:
|
||||
|
||||
var candleResultDataList = JsonConvert.DeserializeObject<List<List<string>>>(resultDataList.ToString());
|
||||
var candleDataList = new CandleDataList();
|
||||
foreach (var data in candleResultDataList)
|
||||
{
|
||||
return WebServiceFunctions.GetBitthumbCandleDatas(resResult);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
// 빗썸 종목
|
||||
|
||||
case CommonProperty.ExchangeWebReqType.BithumbMarket:
|
||||
|
||||
var objectList = JsonConvert.DeserializeObject<Dictionary<string, object>>(resultDataList.ToString());
|
||||
var Payment = objectList["payment_currency"].ToString();
|
||||
objectList.Remove("payment_currency");
|
||||
objectList.Remove("timestamp");
|
||||
|
||||
var conMarketDatas = new List<MarketData>();
|
||||
|
||||
foreach (var item in objectList)
|
||||
{
|
||||
var tempMarketData = new MarketData();
|
||||
tempMarketData.CodeName = item.Key;
|
||||
tempMarketData.ExchangePlace = CommonProperty.ExchangePlace.Bithumb;
|
||||
tempMarketData.KorName = "";
|
||||
tempMarketData.Payment = Payment;
|
||||
|
||||
conMarketDatas.Add(tempMarketData);
|
||||
}
|
||||
|
||||
return conMarketDatas;
|
||||
break;*/
|
||||
return WebServiceFunctions.GetBitthumbMarketDatas(resResult);
|
||||
#endregion
|
||||
|
||||
#region Upbit
|
||||
// UPbit 종목
|
||||
case CommonProperty.ExchangeWebReqType.UpbitMarket:
|
||||
var marKetDataList = new List<MarketData>();
|
||||
foreach (var item in resultData)
|
||||
{
|
||||
var marketData = new MarketData();
|
||||
marketData.CodeFullName = item["market"].ToString();
|
||||
var names = marketData.CodeFullName.Split('-');
|
||||
marketData.CodeName = names[1];
|
||||
marketData.KorName = item["korean_name"].ToString();
|
||||
marketData.Payment = names[0];
|
||||
marketData.ExchangePlace =
|
||||
marketData.ExchangePlace = Enum.GetName(typeof(CommonProperty.ExchangePlace),CommonProperty.ExchangePlace.Upbit);
|
||||
marKetDataList.Add(marketData);
|
||||
}
|
||||
return marKetDataList;
|
||||
#endregion
|
||||
|
||||
return WebServiceFunctions.GetUpbitMarketDatas(resResult);
|
||||
|
||||
case CommonProperty.ExchangeWebReqType.UpbitCandleStick:
|
||||
return WebServiceFunctions.GetUpbitCandleDatas(resResult);
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (WebException webEx)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Million.Data;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -6,8 +8,120 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Million.WebServices
|
||||
{
|
||||
class WebServiceFunctions
|
||||
/// <summary>
|
||||
/// Web Service관련 비즈니스 로직
|
||||
/// </summary>
|
||||
public class WebServiceFunctions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 빗썸 캔들 가져오는 함수
|
||||
/// </summary>
|
||||
/// <param name="resResult"></param>
|
||||
/// <returns></returns>
|
||||
public static CandleDataList GetBitthumbCandleDatas(string resResult)
|
||||
{
|
||||
var candleResultDataList = JsonConvert.DeserializeObject<List<List<string>>>(resResult.ToString());
|
||||
var candleDataList = new CandleDataList();
|
||||
foreach (var data in candleResultDataList)
|
||||
{
|
||||
|
||||
}
|
||||
return candleDataList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 빗썸 마켓 리스트 가져오는 함수
|
||||
/// </summary>
|
||||
/// <param name="resResult"></param>
|
||||
/// <returns></returns>
|
||||
public static object GetBitthumbMarketDatas(string resResult)
|
||||
{
|
||||
var objectList = JsonConvert.DeserializeObject<Dictionary<string, object>>(resResult.ToString());
|
||||
var Payment = objectList["payment_currency"].ToString();
|
||||
objectList.Remove("payment_currency");
|
||||
objectList.Remove("timestamp");
|
||||
|
||||
var conMarketDatas = new List<MarketData>();
|
||||
//TODO 추후 개발
|
||||
|
||||
foreach (var item in objectList)
|
||||
{
|
||||
var tempMarketData = new MarketData();
|
||||
tempMarketData.CodeName = item.Key;
|
||||
//tempMarketData.ExchangePlace = CommonProperty.ExchangePlace.Bithumb;
|
||||
tempMarketData.KorName = "";
|
||||
tempMarketData.Payment = Payment;
|
||||
|
||||
conMarketDatas.Add(tempMarketData);
|
||||
}
|
||||
|
||||
return conMarketDatas;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Upbit Martket Data List
|
||||
/// </summary>
|
||||
/// <param name="resResult"></param>
|
||||
/// <returns></returns>
|
||||
public static List<MarketData> GetUpbitMarketDatas(string resResult)
|
||||
{
|
||||
var objectList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(resResult.ToString());
|
||||
var marKetDataList = new List<MarketData>();
|
||||
foreach (var item in objectList)
|
||||
{
|
||||
var marketData = new MarketData();
|
||||
marketData.CodeFullName = item["market"].ToString();
|
||||
var names = marketData.CodeFullName.Split('-');
|
||||
marketData.CodeName = names[1];
|
||||
marketData.KorName = item["korean_name"].ToString();
|
||||
marketData.Payment = names[0];
|
||||
marketData.ExchangePlace =
|
||||
marketData.ExchangePlace = Enum.GetName(typeof(CommonProperty.ExchangePlace), CommonProperty.ExchangePlace.Upbit);
|
||||
marKetDataList.Add(marketData);
|
||||
}
|
||||
return marKetDataList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Upbit Candle Data List
|
||||
/// </summary>
|
||||
/// <param name="resResult"></param>
|
||||
/// <returns></returns>
|
||||
public static List<CandleData> GetUpbitCandleDatas(string resResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
var objectList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(resResult.ToString());
|
||||
|
||||
var candleList = new List<CandleData>();
|
||||
|
||||
foreach (var item in objectList)
|
||||
{
|
||||
float.TryParse(item["opening_price"]?.ToString(), out var startValue);
|
||||
float.TryParse(item["trade_price"]?.ToString(), out var endValue);
|
||||
float.TryParse(item["high_price"]?.ToString(), out var highValue);
|
||||
float.TryParse(item["low_price"]?.ToString(), out var lowValue);
|
||||
//이거는 확인 필요
|
||||
float.TryParse(item["candle_acc_trade_price"]?.ToString(), out var moneyVolume);
|
||||
int.TryParse(item["unit"]?.ToString(), out var candleTimeType);
|
||||
candleList.Add(new CandleData()
|
||||
{
|
||||
DateTime = Convert.ToDateTime(item["candle_date_time_utc"]?.ToString()),
|
||||
StartValue = startValue,
|
||||
EndValue = endValue,
|
||||
HighValue = highValue,
|
||||
LowValue = lowValue,
|
||||
MoneyVolume = moneyVolume,
|
||||
CandleTimeType = candleTimeType
|
||||
});
|
||||
}
|
||||
return candleList;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Get Upbit Stick data Error : " + e.Message);
|
||||
return new List<CandleData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user