?
This commit is contained in:
@@ -33,7 +33,7 @@ namespace BitgetAPI
|
||||
// 트리 현황판 업데이트 스레드
|
||||
Thread treeListMarketInfoListUpdateTimer = null;
|
||||
// 현황판 웹소켓 스레드
|
||||
Thread th_MarketStatus = null;
|
||||
List<Thread> th_MarketStatusList = null;
|
||||
// WebSocket 내 스레드 관리
|
||||
List<Thread> webSocketThreadList = new List<Thread>();
|
||||
// 종목별 캔들 데이터 스레드
|
||||
@@ -77,11 +77,46 @@ namespace BitgetAPI
|
||||
treeList_MarketInfo.Columns["quoteVolume"].SortOrder = SortOrder.Descending;
|
||||
treeList_MarketInfo.EndSort();
|
||||
|
||||
// Json String 만들기
|
||||
// 종목별 Ticker 구독하기
|
||||
th_MarketStatusList = new List<Thread>();
|
||||
var dic = new Dictionary<string, object>();
|
||||
dic.Add("op", "subscribe");
|
||||
|
||||
var argsList = new List<Dictionary<string, object>>();
|
||||
|
||||
var count = 0;
|
||||
|
||||
foreach (var marketInfo in commonProperty.marketInfoList)
|
||||
{
|
||||
var args = new Dictionary<string, object>();
|
||||
args.Add("instType", "USDT-FUTURES");
|
||||
args.Add("channel", "ticker");
|
||||
args.Add("instId", marketInfo.MarketName);
|
||||
argsList.Add(args);
|
||||
|
||||
count++;
|
||||
|
||||
if (count % 30 == 0 || count == commonProperty.marketInfoList.Count - 1)
|
||||
{
|
||||
dic.Add("args", argsList);
|
||||
|
||||
var th_MarketStatus = new Thread(() => ThreadEventAsync(BitgetWebSocketType.현황정보_전체종목, dic));
|
||||
th_MarketStatus.Start();
|
||||
|
||||
th_MarketStatusList.Add(th_MarketStatus);
|
||||
//break;
|
||||
|
||||
dic = new Dictionary<string, object>();
|
||||
dic.Add("op", "subscribe");
|
||||
argsList = new List<Dictionary<string, object>>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 현황판 웹소켓
|
||||
commonProperty.webSocketCandles = new List<WebSocketTickerInfo>();
|
||||
treeList_MarketInfo.DataSource = commonProperty.webSocketCandles;
|
||||
th_MarketStatus = new Thread(() => ThreadEventAsync(BitgetWebSocketType.현황정보_전체종목, "ticker"));
|
||||
th_MarketStatus.Start();
|
||||
|
||||
// 트리 현황판 업데이트
|
||||
treeListMarketInfoListUpdateTimer = new Thread(new ThreadStart(TreeListMarketInfoListUpdate));
|
||||
@@ -101,20 +136,20 @@ namespace BitgetAPI
|
||||
treeList_ShortDown.DataSource = signals_SD;
|
||||
|
||||
// 신호검색 스레드
|
||||
th_SignalInfo = new Thread(new ThreadStart(Signalnfo));
|
||||
th_SignalInfo.Start();
|
||||
//th_SignalInfo = new Thread(new ThreadStart(Signalnfo));
|
||||
//th_SignalInfo.Start();
|
||||
|
||||
// API Key 가져오기 및 등록
|
||||
|
||||
}
|
||||
|
||||
// 웹소켓 생성 관련 함수 스레드 => Thread
|
||||
private async void ThreadEventAsync(BitgetWebSocketType bitgetWebSocketType, string channel)
|
||||
private async void ThreadEventAsync(BitgetWebSocketType bitgetWebSocketType, Dictionary<string, object> dic)
|
||||
{
|
||||
// WebSocket 생성
|
||||
WebConnection webConnection = new WebConnection();
|
||||
|
||||
webConnection.BitGetWebSocektStart(bitgetWebSocketType, channel);
|
||||
webConnection.BitGetWebSocektStart(bitgetWebSocketType, dic);
|
||||
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
@@ -458,17 +493,23 @@ namespace BitgetAPI
|
||||
|
||||
// WebServicee 초기 캔들 데이터 가져오기 : 종목, 개수
|
||||
// 종목별 캔들 데이터 가져오기 (WebService)
|
||||
th_MarketCandeData = new Thread(() => getMarketCandleData_WebService(exchangeWebReqType));
|
||||
th_MarketCandeData.Start();
|
||||
//th_MarketCandeData = new Thread(() => getMarketCandleData_WebService(exchangeWebReqType));
|
||||
//th_MarketCandeData.Start();
|
||||
}
|
||||
|
||||
// 폼 닫기 시 처리 이벤트
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (th_MarketStatus != null)
|
||||
if (th_MarketStatusList != null)
|
||||
{
|
||||
th_MarketStatus.Abort();
|
||||
th_MarketStatus = null;
|
||||
for (var cnt = 0; cnt < th_MarketStatusList.Count; cnt++)
|
||||
{
|
||||
if (th_MarketStatusList[cnt] != null && th_MarketStatusList[cnt].ThreadState != ThreadState.Running)
|
||||
{
|
||||
th_MarketStatusList[cnt].Abort();
|
||||
th_MarketStatusList[cnt] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (treeListMarketInfoListUpdateTimer != null)
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace BitgetAPI.WebService
|
||||
return returnJsonData;
|
||||
}
|
||||
|
||||
public async void BitGetWebSocektStart(CommonProperty.BitgetWebSocketType bitgetWebSocketType, string chnnelType)
|
||||
public async void BitGetWebSocektStart(CommonProperty.BitgetWebSocketType bitgetWebSocketType, Dictionary<string, object> dic)
|
||||
{
|
||||
string apiUrl = "https://api.upbit.com/v1/market/all?isDetails=true";
|
||||
|
||||
@@ -228,24 +228,6 @@ namespace BitgetAPI.WebService
|
||||
// 연결이 성공적으로 이루어지면 처리할 코드 작성
|
||||
Console.WriteLine("WebSocket 연결 성공");
|
||||
|
||||
// Json String 만들기
|
||||
// 종목별 Ticker 구독하기
|
||||
var dic = new Dictionary<string, object>();
|
||||
dic.Add("op", "subscribe");
|
||||
|
||||
var argsList = new List<Dictionary<string, object>>();
|
||||
|
||||
foreach (var marketInfo in commonProperty.marketInfoList)
|
||||
{
|
||||
var args = new Dictionary<string, object>();
|
||||
args.Add("instType", "USDT-FUTURES");
|
||||
args.Add("channel", chnnelType);
|
||||
args.Add("instId", marketInfo.MarketName);
|
||||
argsList.Add(args);
|
||||
}
|
||||
|
||||
dic.Add("args", argsList)
|
||||
;
|
||||
//var jsonDataText = "{\"op\":\"subscribe\",\"args\":[{\"instType\":\"SPOT\",\"channel\":\"ticker\",\"instId\":\"ETHUSDT\"}, {\"instType\":\"SPOT\",\"channel\":\"ticker\",\"instId\":\"BTCUSDT\"}]}";
|
||||
|
||||
var jsonData = JsonConvert.SerializeObject(dic);
|
||||
@@ -293,6 +275,8 @@ namespace BitgetAPI.WebService
|
||||
DateTime dt = new DateTime(1970, 01, 01);
|
||||
tickerList.reciveTime = dt.AddMilliseconds(Convert.ToDouble(tickerList.ts)).ToLocalTime();
|
||||
|
||||
var test = 0;
|
||||
/*
|
||||
// 웹소켓 티커 리스트에 추가
|
||||
var searchIndex = commonProperty.webSocketCandles.IndexOf(i => i.instId == tickerList.instId);
|
||||
if (searchIndex < 0)
|
||||
@@ -405,6 +389,7 @@ namespace BitgetAPI.WebService
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case CommonProperty.BitgetWebSocketType.캔들정보:
|
||||
@@ -525,11 +510,11 @@ namespace BitgetAPI.WebService
|
||||
finally
|
||||
{
|
||||
//if (webSocket.State == WebSocketState.Open)
|
||||
//await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "WebSocket 연결 종료", CancellationToken.None);
|
||||
//await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "WebSocket 연결 종료", CancellationToken.None);
|
||||
webSocket.Dispose();
|
||||
|
||||
// 웹소켓 재귀
|
||||
BitGetWebSocektStart(bitgetWebSocketType, chnnelType);
|
||||
BitGetWebSocektStart(bitgetWebSocketType, dic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user