From bf0e2ce980ebf7bda01cc57711f926f50ededd12 Mon Sep 17 00:00:00 2001 From: kyh <1329522@naver.com> Date: Thu, 17 Oct 2024 12:40:38 +0900 Subject: [PATCH] =?UTF-8?q?buy=20sell=20=EB=AA=A8=EB=91=90=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BitgetApi/CommonProperty.cs | 4 +- .../IndicatorProcess.cs | 52 +++++++++---------- BitgetApi/WebService/WebConnection.cs | 4 ++ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/BitgetApi/CommonProperty.cs b/BitgetApi/CommonProperty.cs index 390c7a2..1da22ad 100644 --- a/BitgetApi/CommonProperty.cs +++ b/BitgetApi/CommonProperty.cs @@ -159,8 +159,8 @@ namespace BitgetAPI { BuyShort = 0, BuyLong = 1, - SellShort = 0, - SellLong = 1, + SellShort = 2, + SellLong = 3, } #endregion diff --git a/BitgetApi/IndicatorConditionSetup/IndicatorProcess.cs b/BitgetApi/IndicatorConditionSetup/IndicatorProcess.cs index 1800eaf..68cfb9b 100644 --- a/BitgetApi/IndicatorConditionSetup/IndicatorProcess.cs +++ b/BitgetApi/IndicatorConditionSetup/IndicatorProcess.cs @@ -83,14 +83,13 @@ namespace BitgetAPI.IndicatorConditionSetup signals_SU.Clear(); //시작시 한번만 하면됨(양방향) - //ChangeFuturePositionMode(FuturePositionMode.hedge_mode); - + ChangeFuturePositionMode(FuturePositionMode.hedge_mode); + GetFutureAccountList(); //order 로직 - //FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, (double)0.531, FutureSide.BuyShort, OrderType.limit, 10); - - - + var orderData = FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, (double)0.541, FutureSide.BuyShort, OrderType.limit, 10); + var sellData = FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, 0, FutureSide.SellShort, OrderType.market, 10, "1230644068203786241"); + // 추후 공통화 및 소스정리 필요 while (true) @@ -1091,13 +1090,13 @@ namespace BitgetAPI.IndicatorConditionSetup if (futureSide == FutureSide.BuyShort) { - id = new Guid().ToString(); + id = Guid.NewGuid().ToString(); side = "sell"; tradeSide = "open"; } else if (futureSide == FutureSide.BuyLong) { - id = new Guid().ToString(); + id = Guid.NewGuid().ToString(); side = "buy"; tradeSide = "Open"; } @@ -1125,9 +1124,9 @@ namespace BitgetAPI.IndicatorConditionSetup { //change margin mode 이후 leverage 처리 해야 함 var changeMarginModeStr = "{\"symbol\": \"" + symbol + "\", \"productType\": \"usdt-futures\", \"marginCoin\": \"USDT\", \"marginMode\": \"" + Utils.Convertor.GetEnumDescription((Enum)marginMode) + "\"}"; - + var nvcMargin = new NameValueCollection { - {"ACCESS-KEY", YHKIM_AccessKey}, + {"ACCESS-KEY", YHKIM_AccessKey}, {"ACCESS-SIGN", GenerateSignString(timestamp, "POST", "/api/v2/mix/account/set-margin-mode", "", changeMarginModeStr, YHKIM_SecreteKey)}, {"ACCESS-PASSPHRASE", YHKIM_PassphraseKey }, {"ACCESS-TIMESTAMP", timestamp} @@ -1152,23 +1151,24 @@ namespace BitgetAPI.IndicatorConditionSetup return null; } } - else - { - // sell은 ClientOID 가 필요 - var orderDetailStr = "/api/v2/mix/order/detail"; - timestamp = (((DateTimeOffset)timeSpan).ToUnixTimeSeconds() * 1000).ToString(); - var orderDetailnvc = new NameValueCollection { - {"ACCESS-KEY", YHKIM_AccessKey}, - {"ACCESS-SIGN", GenerateSignString(timestamp, "GET", orderDetailStr, "symbol="+symbol.ToString()+"&orderId="+id.ToString()+"&productType=usdt-future", null, YHKIM_SecreteKey) }, - {"ACCESS-PASSPHRASE", YHKIM_PassphraseKey }, - {"ACCESS-TIMESTAMP",timestamp} - }; + //else + //{ + // // sell은 ClientOID 가 필요 + // var orderDetailStr = "/api/v2/mix/order/detail"; + // timestamp = (((DateTimeOffset)timeSpan).ToUnixTimeSeconds() * 1000).ToString(); + // var orderDetailnvc = new NameValueCollection { + // {"ACCESS-KEY", YHKIM_AccessKey}, + // {"ACCESS-SIGN", GenerateSignString(timestamp, "GET", orderDetailStr, "symbol="+symbol.ToString()+"&orderId="+id.ToString()+"&productType=USDT-FUTURES", null, YHKIM_SecreteKey) }, + // {"ACCESS-PASSPHRASE", YHKIM_PassphraseKey }, + // {"ACCESS-TIMESTAMP",timestamp} + // }; - var orderDetail = (Dictionary)WebConnection.SendWebServer(ExchangeWebReqType.BitgetOrderDetail_Future, BitgetURL_OrderDetail_Future, null, MCandleTimeType.M1, "", "", orderDetailnvc); - if (orderDetail["msg"]?.ToString() != "success") return null; - var data = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(orderDetail["data"])); - id = data["clientOid"].ToString(); - } + // var orderDetail = (Dictionary)WebConnection.SendWebServer(ExchangeWebReqType.BitgetOrderDetail_Future, BitgetURL_OrderDetail_Future + "?symbol=" + symbol.ToString() + "&orderId=" + id.ToString() + "&productType=USDT-FUTURES", null, MCandleTimeType.M1, "", "", orderDetailnvc); + // if (orderDetail == null || orderDetail["msg"]?.ToString() != "success") return null; + + // var data = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(orderDetail["data"])); + // //id = data["clientOid"].ToString(); + //} var postStr = "{\"symbol\": \"" + symbol + "\", \"productType\": \"usdt-futures\", \"marginMode\": \"" + Utils.Convertor.GetEnumDescription((Enum)marginMode) + "\", \"marginCoin\": \"USDT\", \"size\": \"" + size.ToString() + "\", \"price\": \"" + price.ToString() + "\", \"side\": \"" + side + "\", " + "\"tradeSide\": \"" + tradeSide + "\", \"orderType\": \"" + Utils.Convertor.GetEnumDescription((Enum)orderType) diff --git a/BitgetApi/WebService/WebConnection.cs b/BitgetApi/WebService/WebConnection.cs index 38600af..01dc50a 100644 --- a/BitgetApi/WebService/WebConnection.cs +++ b/BitgetApi/WebService/WebConnection.cs @@ -284,6 +284,10 @@ namespace BitgetAPI.WebService { return JsonConvert.DeserializeObject>(resResult); } + case ExchangeWebReqType.BitgetOrderDetail_Future: + { + return JsonConvert.DeserializeObject>(resResult); + } #endregion } }