1. 조건 재시작 및 프로그램 종료 Thread 수정
This commit is contained in:
@@ -32,17 +32,20 @@ namespace BitgetAPI
|
||||
|
||||
#region 폼 내 사용되는 스레드
|
||||
// 트리 현황판 업데이트 스레드 (단순 폼 업데이트)
|
||||
Thread treeListMarketInfoListUpdateTimer = null;
|
||||
// 웹소켓 스레드 (선택된 종목 개수 만큼 가져오기)
|
||||
List<Thread> th_MarketStatusList = null;
|
||||
// WebSocket 내 스레드 관리
|
||||
List<Thread> webSocketThreadList = new List<Thread>();
|
||||
// 종목별 캔들 데이터 스레드 (사용 안함)
|
||||
Thread th_MarketCandeData = null;
|
||||
// 신호검색 스레드 함수
|
||||
Thread th_treeListMarketInfoListUpdateTimer = null;
|
||||
// 신호검색 스레드
|
||||
Thread th_SignalInfo = null;
|
||||
// 현황판 웹서비스 Ticker 스레드 (한번에 전체 종목 종가 받음)
|
||||
Thread th_MarketInfoList = null;
|
||||
Thread th_MarketInfoList_WebService = null;
|
||||
// 웹소켓 스레드
|
||||
Thread th_ticker_Websocket = null;
|
||||
|
||||
|
||||
// 스레드 종료 플래그
|
||||
bool Is_th_SignalInfo = false;
|
||||
bool Is_th_webSocketThread = false;
|
||||
bool Is_th_th_MarketInfoList_WebService = false;
|
||||
bool Is_th_treeListUpdate = false;
|
||||
|
||||
// 신호검색 리스트 작성
|
||||
// 신호 Long 상승 (구매)
|
||||
@@ -102,38 +105,32 @@ namespace BitgetAPI
|
||||
// 웹서비스를 통해 현황판 및 마켓 Ticker 업데이트
|
||||
private void getMarketInfoList_WebService(ExchangeWebReqType exchangeWebReqType)
|
||||
{
|
||||
while(true)
|
||||
Is_th_th_MarketInfoList_WebService = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
if (!Is_th_th_MarketInfoList_WebService) break;
|
||||
// 마켓 모든 종목 캔들 정보 Web Service로 가져오기
|
||||
commonProperty.marketInfoList = (List<MarketInfo>)BitgetAPI.WebService.WebConnection.SendWebServer(exchangeWebReqType);
|
||||
|
||||
// 현황판에 최신 정보 업데이트 하기
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
try
|
||||
{
|
||||
var scrollPoint = treeList_MarketInfo.TopVisibleNodeIndex;
|
||||
treeList_MarketInfo.DataSource = commonProperty.marketInfoList;
|
||||
treeList_MarketInfo.RefreshDataSource();
|
||||
treeList_MarketInfo.TopVisibleNodeIndex = scrollPoint;
|
||||
}));
|
||||
// 현황판에 최신 정보 업데이트 하기
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
var scrollPoint = treeList_MarketInfo.TopVisibleNodeIndex;
|
||||
treeList_MarketInfo.DataSource = commonProperty.marketInfoList;
|
||||
treeList_MarketInfo.RefreshDataSource();
|
||||
treeList_MarketInfo.TopVisibleNodeIndex = scrollPoint;
|
||||
|
||||
}));
|
||||
}catch (Exception ex) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 웹소켓 생성 관련 함수 스레드 => Thread
|
||||
private async void ThreadEventAsync(BitgetWebSocketType bitgetWebSocketType, Dictionary<string, object> dic)
|
||||
{
|
||||
// WebSocket 생성
|
||||
WebConnection webConnection = new WebConnection();
|
||||
|
||||
webConnection.BitGetWebSocektStart(bitgetWebSocketType, dic);
|
||||
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
// WebSocket 내 스레드 관리
|
||||
webSocketThreadList.Add(webConnection.th_PingTimer);
|
||||
}));
|
||||
}
|
||||
|
||||
// 마켓 현황판 업데이트 (1) => Thread
|
||||
// 지표 생성 및 신호 검색 (2)
|
||||
private void TreeListMarketInfoListUpdate( )
|
||||
@@ -141,22 +138,28 @@ namespace BitgetAPI
|
||||
// 마켓 현황판 업데이트
|
||||
while(true)
|
||||
{
|
||||
if (!Is_th_treeListUpdate) break;
|
||||
|
||||
Thread.Sleep(300);
|
||||
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
try
|
||||
{
|
||||
var scrollPoint = treeList_MarketInfo.TopVisibleNodeIndex;
|
||||
var scrollPoint_LU = treeList_LongUp.TopVisibleNodeIndex;
|
||||
var scrollPoint_SD = treeList_ShortDown.TopVisibleNodeIndex;
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
var scrollPoint = treeList_MarketInfo.TopVisibleNodeIndex;
|
||||
var scrollPoint_LU = treeList_LongUp.TopVisibleNodeIndex;
|
||||
var scrollPoint_SD = treeList_ShortDown.TopVisibleNodeIndex;
|
||||
|
||||
treeList_MarketInfo.RefreshDataSource();
|
||||
treeList_LongUp.RefreshDataSource();
|
||||
treeList_ShortDown.RefreshDataSource();
|
||||
treeList_MarketInfo.RefreshDataSource();
|
||||
treeList_LongUp.RefreshDataSource();
|
||||
treeList_ShortDown.RefreshDataSource();
|
||||
|
||||
treeList_MarketInfo.TopVisibleNodeIndex = scrollPoint;
|
||||
treeList_LongUp.TopVisibleNodeIndex = scrollPoint_LU;
|
||||
treeList_ShortDown.TopVisibleNodeIndex = scrollPoint_SD;
|
||||
}));
|
||||
treeList_MarketInfo.TopVisibleNodeIndex = scrollPoint;
|
||||
treeList_LongUp.TopVisibleNodeIndex = scrollPoint_LU;
|
||||
treeList_ShortDown.TopVisibleNodeIndex = scrollPoint_SD;
|
||||
|
||||
}));
|
||||
}catch(Exception ex) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,10 +182,11 @@ namespace BitgetAPI
|
||||
var checkedMarkets = checkedComboBoxEdit_MarketInfoList.Properties.Items.GetCheckedValues();
|
||||
var intervalList = checkedComboBoxEdit_TimeInterval.Properties.Items.GetCheckedValues();
|
||||
|
||||
Is_th_SignalInfo = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
//if (!xtraTabPage_Searcher.PageEnabled) continue;
|
||||
|
||||
if (!Is_th_SignalInfo) break;
|
||||
//Thread.Sleep(200);
|
||||
var nowTime = DateTime.Now;
|
||||
|
||||
@@ -203,7 +207,6 @@ namespace BitgetAPI
|
||||
{
|
||||
item.Price = lastCandleData.Close;
|
||||
item.Rate = (lastCandleData.Close / lastCandleData.Open) * 100 - 100;
|
||||
item.IndicatorPrice = lastCandleData.IchimokData.상한선;
|
||||
item.IndicatorRate = (lastCandleData.Close / item.IndicatorPrice) * 100 - 100;
|
||||
}
|
||||
|
||||
@@ -223,9 +226,7 @@ namespace BitgetAPI
|
||||
if (lastCandleData.IchimokData != null)
|
||||
{
|
||||
item.Price = lastCandleData.Close;
|
||||
if (lastCandleData.Open == 0) { }
|
||||
item.Rate = (lastCandleData.Close / lastCandleData.Open) * 100 - 100;
|
||||
item.IndicatorPrice = lastCandleData.IchimokData.하한선;
|
||||
item.IndicatorRate = (lastCandleData.Close / item.IndicatorPrice) * 100 - 100;
|
||||
}
|
||||
}
|
||||
@@ -259,12 +260,13 @@ namespace BitgetAPI
|
||||
var candleData_전봉 = candleDatas.Find(i => i.Argument == candleDatas_정렬.Last().Argument);
|
||||
|
||||
ichimokuConditionSetup.calIchimokuData(candleDatas_정렬, candleData_전봉);
|
||||
|
||||
if (candleData_전봉.Open < candleData_전봉.IchimokData.상한선 && candleData.Open > candleData.IchimokData.상한선 && candleData.Low > candleData.IchimokData.상한선)
|
||||
|
||||
if (candleData_전봉.Open < candleData_전봉.IchimokData.상한선 && candleData.Open > candleData.IchimokData.상한선 && candleData.Low > candleData.IchimokData.상한선
|
||||
&& candleData.Close > candleData.IchimokData.상한선)
|
||||
{
|
||||
var price = candleData.Close;
|
||||
var rate = (candleData.Close / candleData.Open) * 100 - 100;
|
||||
var indicatorPrice = candleData.IchimokData.상한선;
|
||||
var indicatorPrice = candleData.Open;
|
||||
var indicatorRate = (candleData.Close / indicatorPrice) * 100 - 100;
|
||||
|
||||
var signalData = signals_LU.Find(i => i.MarketName.Equals(market));
|
||||
@@ -285,11 +287,12 @@ namespace BitgetAPI
|
||||
signals_LU.Add(signalInfoData);
|
||||
}
|
||||
}
|
||||
else if (candleData_전봉.Open > candleData_전봉.IchimokData.하한선 && candleData.Open < candleData.IchimokData.하한선 && candleData.High < candleData.IchimokData.하한선)
|
||||
else if (candleData_전봉.Open > candleData_전봉.IchimokData.하한선 && candleData.Open < candleData.IchimokData.하한선 && candleData.High < candleData.IchimokData.하한선
|
||||
&& candleData.Close < candleData.IchimokData.하한선)
|
||||
{
|
||||
var price = candleData.Close;
|
||||
var rate = (candleData.Close / candleData.Open) * 100 - 100;
|
||||
var indicatorPrice = candleData.IchimokData.하한선;
|
||||
var indicatorPrice = candleData.Open;
|
||||
var indicatorRate = (candleData.Close / indicatorPrice) * 100 - 100;
|
||||
|
||||
var signalData = signals_SD.Find(i => i.MarketName.Equals(market));
|
||||
@@ -481,8 +484,8 @@ namespace BitgetAPI
|
||||
}
|
||||
|
||||
// 마켓정보(WebService Ticker) => 0.5초당 1번으로 업데이트 하기 (현황판)
|
||||
th_MarketInfoList = new Thread(() => getMarketInfoList_WebService(exchangeWebReqType));
|
||||
th_MarketInfoList.Start();
|
||||
th_MarketInfoList_WebService = new Thread(() => getMarketInfoList_WebService(exchangeWebReqType));
|
||||
th_MarketInfoList_WebService.Start();
|
||||
|
||||
#region 캔들 웹소켓 : 종목 50, 캔들 1 개만 해도 뒤지려고 함 !! (일딴 패스)
|
||||
/*
|
||||
@@ -497,53 +500,50 @@ namespace BitgetAPI
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void ticker_WebSocket(List<object> marketList, int count)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 폼 닫기 시 처리 이벤트
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (th_MarketStatusList != null)
|
||||
if (th_SignalInfo != 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 (th_MarketInfoList != null)
|
||||
{
|
||||
th_MarketInfoList.Abort();
|
||||
th_MarketInfoList = null;
|
||||
}
|
||||
|
||||
if (treeListMarketInfoListUpdateTimer != null)
|
||||
{
|
||||
treeListMarketInfoListUpdateTimer.Abort();
|
||||
treeListMarketInfoListUpdateTimer = null;
|
||||
}
|
||||
|
||||
if (th_MarketCandeData != null)
|
||||
{
|
||||
th_MarketCandeData.Abort();
|
||||
th_MarketCandeData = null;
|
||||
}
|
||||
|
||||
if(th_SignalInfo != null)
|
||||
{
|
||||
th_SignalInfo.Abort();
|
||||
Is_th_SignalInfo = false;
|
||||
th_SignalInfo.Join();
|
||||
th_SignalInfo = null;
|
||||
}
|
||||
|
||||
for(var cnt = 0; cnt < webSocketThreadList.Count; cnt++)
|
||||
|
||||
if (commonProperty.webConnection != null)
|
||||
{
|
||||
if(webSocketThreadList[cnt] != null && webSocketThreadList[cnt].ThreadState != ThreadState.Running)
|
||||
commonProperty.webConnection.Is_th_webSocketThread = false;
|
||||
commonProperty.webConnection.closeWebSocket();
|
||||
}
|
||||
|
||||
if (th_MarketInfoList_WebService != null)
|
||||
{
|
||||
Is_th_th_MarketInfoList_WebService = false;
|
||||
|
||||
if (th_MarketInfoList_WebService.ThreadState == ThreadState.Running)
|
||||
{
|
||||
webSocketThreadList[cnt].Abort();
|
||||
webSocketThreadList[cnt] = null;
|
||||
th_MarketInfoList_WebService.Join();
|
||||
th_MarketInfoList_WebService = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (th_treeListMarketInfoListUpdateTimer != null)
|
||||
{
|
||||
Is_th_treeListUpdate = false;
|
||||
|
||||
if (th_treeListMarketInfoListUpdateTimer.ThreadState == ThreadState.Running)
|
||||
{
|
||||
th_treeListMarketInfoListUpdateTimer.Join();
|
||||
th_treeListMarketInfoListUpdateTimer = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -560,47 +560,38 @@ namespace BitgetAPI
|
||||
|
||||
// 신호 검색 시작
|
||||
private void simpleButton_SignalStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
{
|
||||
if(th_SignalInfo != null)
|
||||
{
|
||||
Is_th_SignalInfo = false;
|
||||
if (th_SignalInfo.ThreadState == ThreadState.Running)
|
||||
th_SignalInfo.Join();
|
||||
th_SignalInfo = null;
|
||||
}
|
||||
|
||||
foreach(var candleList in commonProperty.candleDataLists)
|
||||
if (commonProperty.webConnection != null)
|
||||
{
|
||||
commonProperty.webConnection.Is_th_webSocketThread = false;
|
||||
commonProperty.webConnection.closeWebSocket();
|
||||
}
|
||||
|
||||
if(th_treeListMarketInfoListUpdateTimer != null)
|
||||
{
|
||||
Is_th_treeListUpdate = false;
|
||||
|
||||
if (th_treeListMarketInfoListUpdateTimer.ThreadState == ThreadState.Running)
|
||||
{
|
||||
th_treeListMarketInfoListUpdateTimer.Join();
|
||||
th_treeListMarketInfoListUpdateTimer = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (var candleList in commonProperty.candleDataLists)
|
||||
{
|
||||
foreach (var interval in candleList.candleDataList)
|
||||
interval.Value.Clear();
|
||||
}
|
||||
|
||||
|
||||
if(th_SignalInfo != null)
|
||||
{
|
||||
if (th_SignalInfo.ThreadState == ThreadState.Running)
|
||||
th_SignalInfo.Abort();
|
||||
th_SignalInfo = null;
|
||||
}
|
||||
|
||||
if (th_MarketCandeData != null)
|
||||
{
|
||||
if (th_MarketCandeData.ThreadState == ThreadState.Running)
|
||||
th_MarketCandeData.Abort();
|
||||
th_MarketCandeData = null;
|
||||
}
|
||||
if(treeListMarketInfoListUpdateTimer != null)
|
||||
{
|
||||
if (treeListMarketInfoListUpdateTimer.ThreadState == ThreadState.Running)
|
||||
treeListMarketInfoListUpdateTimer.Abort();
|
||||
treeListMarketInfoListUpdateTimer = null;
|
||||
}
|
||||
if (th_MarketStatusList != 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var count = 0;
|
||||
|
||||
@@ -617,7 +608,6 @@ namespace BitgetAPI
|
||||
marketList = checkedComboBoxEdit_MarketInfoList.Properties.Items.GetCheckedValues();
|
||||
}
|
||||
|
||||
th_MarketStatusList = new List<Thread>();
|
||||
var dic = new Dictionary<string, object>();
|
||||
dic.Add("op", "subscribe");
|
||||
|
||||
@@ -640,20 +630,26 @@ namespace BitgetAPI
|
||||
dic.Add("args", argsList);
|
||||
|
||||
// 웹소켓으로 캔들 쌓기
|
||||
var th_MarketStatus = new Thread(() => ThreadEventAsync(BitgetWebSocketType.현황정보_전체종목, dic));
|
||||
th_MarketStatus.Start();
|
||||
th_MarketStatusList.Add(th_MarketStatus);
|
||||
// WebSocket 생성
|
||||
WebConnection webConnection = new WebConnection();
|
||||
commonProperty.webConnection = webConnection;
|
||||
webConnection.Is_th_webSocketThread = true;
|
||||
webConnection.BitGetWebSocektStart(BitgetWebSocketType.현황정보_전체종목, dic);
|
||||
|
||||
|
||||
//th_webSocketThread = new Thread(() => TheadWebSocketRecieve(BitgetWebSocketType.현황정보_전체종목, dic));
|
||||
//th_webSocketThread.Start();
|
||||
|
||||
// WebServicee 초기 캔들 데이터 가져오기 : 종목, 개수
|
||||
// 종목별 캔들 데이터 가져오기 (WebService)
|
||||
// 선택된 타입에 따라서 종목 정보 가져오기
|
||||
var exchangeWebReqType = ExchangeWebReqType.BitgetMarket_Future;
|
||||
th_MarketCandeData = new Thread(() => getMarketCandleData_WebService(exchangeWebReqType, marketList));
|
||||
th_MarketCandeData.Start();
|
||||
th_MarketInfoList_WebService = new Thread(() => getMarketCandleData_WebService(exchangeWebReqType, marketList));
|
||||
th_MarketInfoList_WebService.Start();
|
||||
|
||||
// 트리 현황판 업데이트
|
||||
treeListMarketInfoListUpdateTimer = new Thread(new ThreadStart(TreeListMarketInfoListUpdate));
|
||||
treeListMarketInfoListUpdateTimer.Start();
|
||||
th_treeListMarketInfoListUpdateTimer = new Thread(new ThreadStart(TreeListMarketInfoListUpdate));
|
||||
th_treeListMarketInfoListUpdateTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user