수정!!!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BitgetAPI.Data;
|
||||
using BitgetAPI.WebService;
|
||||
using DevExpress.XtraEditors;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@@ -13,9 +14,9 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static BitgetApi.CommonProperty;
|
||||
using static BitgetAPI.CommonProperty;
|
||||
|
||||
namespace BitgetApi
|
||||
namespace BitgetAPI
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
@@ -31,11 +32,15 @@ namespace BitgetApi
|
||||
// 폼 초기화 작업
|
||||
public void init()
|
||||
{
|
||||
commonProperty.mainform = this;
|
||||
|
||||
// 거래소 항목 추가 및 설정하기
|
||||
comboBoxEdit_ExchangePlace.Properties.Items.AddRange(Enum.GetNames(typeof(CommonProperty.ExchangePlace)));
|
||||
comboBoxEdit_ExchangePlace.SelectedIndex = (int)CommonProperty.ExchangePlace.Bitget;
|
||||
commonProperty.selectedChangePlace = CommonProperty.ExchangePlace.Bitget;
|
||||
|
||||
treeList_MarketInfo.DataSource = commonProperty.webSocketCandles;
|
||||
|
||||
// API Key 가져오기 및 등록
|
||||
|
||||
// BITGET Raster 소켓 테스트
|
||||
@@ -46,81 +51,36 @@ namespace BitgetApi
|
||||
|
||||
// 구름떼, 볼린저 생성
|
||||
|
||||
//
|
||||
// 마켓정보 가져오기 (25초), Ping 유지용
|
||||
// 트리 현황판 업데이트
|
||||
var marketInfoListUpdateTimer = new Thread(new ThreadStart(MarketInfoListUpdate));
|
||||
marketInfoListUpdateTimer.Start();
|
||||
|
||||
//
|
||||
// 트리 현황판 업데이트
|
||||
var treeListMarketInfoListUpdateTimer = new Thread(new ThreadStart(TreeListMarketInfoListUpdate));
|
||||
treeListMarketInfoListUpdateTimer.Start();
|
||||
}
|
||||
|
||||
public async void webSocektStart()
|
||||
// 마켓정보 가져오기 !!
|
||||
private void MarketInfoListUpdate()
|
||||
{
|
||||
string apiUrl = "https://api.upbit.com/v1/market/all?isDetails=true";
|
||||
Thread.Sleep(25000);
|
||||
// 마켓 정보 가져오기
|
||||
var marketInfos = (List<MarketInfo>)BitgetAPI.WebService.WebConnection.SendWebServer(ExchangeWebReqType.BitgetMarket_Future);
|
||||
}
|
||||
|
||||
// IP당 100개 연결
|
||||
// 시간당 240회 !!!
|
||||
// 타이머 30초 유지 > 30초 이내의 응답 메시지 수신 필요 > 아니면 오류 발생 !! > 재접속 필요 !!
|
||||
// 초당 10개 메시지 허용
|
||||
// 단일 연결로 최대 1000개의 스트림 구독
|
||||
// 단인 IP 최대의 100개 연결
|
||||
|
||||
// *
|
||||
/* timestamp : Unix Epoch 시간
|
||||
* passphrase : APIKey 비밀번호
|
||||
* timestamp : Unix Epoch 시간, 단위는 초(--restAPI의 서명 타임스탬프와 다름--)
|
||||
* secretKey : 사용자가 APIKey를 신청할 때 생성되는 보안 키입니다. 예: 22582BD0CFF14C41EDBF1AB98506286D
|
||||
*/
|
||||
|
||||
|
||||
ClientWebSocket webSocket = new ClientWebSocket();
|
||||
|
||||
string WebSocketUrl = "wss://ws.bitget.com/v2/ws/public";
|
||||
string message = "";
|
||||
|
||||
try
|
||||
private void TreeListMarketInfoListUpdate()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
await webSocket.ConnectAsync(new Uri(WebSocketUrl), CancellationToken.None);
|
||||
// 연결이 성공적으로 이루어지면 처리할 코드 작성
|
||||
Console.WriteLine("WebSocket 연결 성공");
|
||||
Thread.Sleep(2000);
|
||||
|
||||
var jsonDataText = "{\"op\":\"subscribe\",\"args\":[{\"instType\":\"SPOT\",\"channel\":\"ticker\",\"instId\":\"ETHUSDT\"}, {\"instType\":\"SPOT\",\"channel\":\"ticker\",\"instId\":\"BTCUSDT\"}]}";
|
||||
|
||||
// test11 = JsonConvert.SerializeObject(jsonData);
|
||||
|
||||
await SendMessage(webSocket, jsonDataText);
|
||||
|
||||
|
||||
// 데이터 수신을 위한 반복문 시작
|
||||
while (webSocket.State == WebSocketState.Open)
|
||||
Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
message = "";
|
||||
// 수신한 데이터 처리
|
||||
message = System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
|
||||
var testData = JsonConvert.DeserializeObject<TradeData>(message);
|
||||
|
||||
Console.WriteLine("수신한 데이터: " + message);
|
||||
DateTime dt = new DateTime(1970, 01, 01);
|
||||
dt = dt.AddMilliseconds(testData.trade_timestamp).ToLocalTime();
|
||||
}
|
||||
treeList_MarketInfo.RefreshDataSource();
|
||||
treeList_MarketInfo.ClearSelection();
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("WebSocket 연결 중 오류 발생: " + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (webSocket.State == WebSocketState.Open)
|
||||
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "WebSocket 연결 종료", CancellationToken.None);
|
||||
|
||||
webSocket.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task SendMessage(ClientWebSocket webSocket, string message)
|
||||
{
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(message);
|
||||
await webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
Console.WriteLine("메시지 전송: " + message);
|
||||
}
|
||||
|
||||
// 거래소 콤보박스 클릭 시 이벤트 처리
|
||||
@@ -176,8 +136,26 @@ namespace BitgetApi
|
||||
|
||||
var candleCount = 200;
|
||||
|
||||
// 캔들 리스트 생성하기
|
||||
foreach (var item in marketInfos)
|
||||
{
|
||||
MarketCandleDataList candleDataList = new MarketCandleDataList();
|
||||
candleDataList.ConGoodsData = item;
|
||||
foreach (var interval in Enum.GetValues(typeof(CommonProperty.MCandleTimeType)))
|
||||
{
|
||||
candleDataList.candleDataList.Add((MCandleTimeType)interval, new List<CandleData>());
|
||||
}
|
||||
|
||||
candleDataLists.Add(candleDataList);
|
||||
}
|
||||
|
||||
commonProperty.webSocketCandles = new List<BitgetApi.Data.WebSocketCandle>();
|
||||
|
||||
var thread = new Thread(new ThreadStart(ThreadEventAsync));
|
||||
thread.Start();
|
||||
|
||||
// 캔들 데이터 가져오기 : 종목, 개수,
|
||||
foreach(var item in marketInfos)
|
||||
foreach (var item in marketInfos)
|
||||
{
|
||||
MarketCandleDataList candleDataList = new MarketCandleDataList();
|
||||
candleDataList.ConGoodsData = item;
|
||||
@@ -222,20 +200,27 @@ namespace BitgetApi
|
||||
break;
|
||||
}
|
||||
|
||||
var candleList = BitgetAPI.WebService.WebConnection.SendWebServer(exchangeWebReqType, url);
|
||||
List<CandleData> candleList = null;
|
||||
//var candleList = BitgetAPI.WebService.WebConnection.SendWebServer(exchangeWebReqType, url);
|
||||
// 초당 20회 제한 !!!!
|
||||
// Thread.Sleep(50);
|
||||
candleDataList.candleDataList.Add((MCandleTimeType)interval,(List<CandleData>)candleList);
|
||||
//candleDataList.candleDataList.Add((MCandleTimeType)interval,(List<CandleData>)candleList);
|
||||
|
||||
}
|
||||
|
||||
candleDataLists.Add(candleDataList);
|
||||
|
||||
}
|
||||
|
||||
var test = "";
|
||||
test += "1";
|
||||
}
|
||||
|
||||
|
||||
private async void ThreadEventAsync()
|
||||
{
|
||||
// WebSocket 생성
|
||||
commonProperty.webConnection = new WebConnection();
|
||||
commonProperty.webConnection.webSocektStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user