임시로 Buyer 개발

This commit is contained in:
kyh
2024-10-17 13:13:54 +09:00
parent bf0e2ce980
commit 581fb7cf78

View File

@@ -15,6 +15,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static BitgetAPI.CommonProperty;
using static DevExpress.Utils.Drawing.Helpers.NativeMethods;
namespace BitgetAPI.IndicatorConditionSetup
@@ -69,6 +70,13 @@ namespace BitgetAPI.IndicatorConditionSetup
public Dictionary<string, bool> DownList = new Dictionary<string, bool>();
public Dictionary<string, double> DownBuyValue = new Dictionary<string, double>();
public int LongCount = 0;
public int ShortCount = 0;
public List<Dictionary<string, object>> BuyLongList = new List<Dictionary<string, object>>();
public List<Dictionary<string, object>> BuyShortList = new List<Dictionary<string, object>>();
public List<Dictionary<string, object>> ResultList = new List<Dictionary<string, object>>();
// 전봉이 구름떼 돌파후 시가가 구름떼 위에서 시작하는 것
// 전봉이 구름떼 하락후 시가가 구름떼 밑에서 시작하는 것
@@ -86,8 +94,13 @@ namespace BitgetAPI.IndicatorConditionSetup
ChangeFuturePositionMode(FuturePositionMode.hedge_mode);
GetFutureAccountList();
//order 로직
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");
//var orderData = FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, (double)0.541, FutureSide.BuyShort, OrderType.limit, 10);
//var orderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(orderData["data"]));
//var orderValue = new Dictionary<string, object>();
//orderValue.Add("orderId", orderDic["orderId"]);
//var sellData = FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, 0, FutureSide.SellShort, OrderType.market, 10, orderDic["orderId"]);
@@ -695,6 +708,28 @@ namespace BitgetAPI.IndicatorConditionSetup
전고점Data["flag"] = false;
전고점Data["clearFlag"] = false;
if (LongCount < 3)
{
double size = 50 / price;
var orderData = FutureOrder(market, FutureMarginMode.isolated, size, price, FutureSide.BuyLong, OrderType.limit, 10);
var orderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(orderData["data"]));
var orderDataDic = new Dictionary<string, object>
{
{ "MarketName", market },
{ "BuyDate", nowTime },
{ "Price", price },
{ "MCandleTimeType", (int)interval },
{ "Candle", candleData },
{ "Size", size },
{ "orderId", orderDic["orderId"] }
};
BuyLongList.Add(orderDataDic);
LongCount++;
}
}
}
//파는 시점
@@ -739,6 +774,40 @@ namespace BitgetAPI.IndicatorConditionSetup
UpResultList.Add(result);
UpBuyList.Remove(market + interval);
var orderDic = BuyLongList.FirstOrDefault(t => t["MarketName"].ToString() == market);
if (orderDic != null)
{
double.TryParse(orderDic["Size"].ToString(), out var size);
var sellOrder = FutureOrder(market, FutureMarginMode.isolated, size, 0, FutureSide.SellLong, OrderType.market, 10, orderDic["orderId"].ToString());
var sellOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(sellOrder["data"]));
var detail = GetFutureOrderDetail(market, sellOrderDic["orderId"]);
var detailOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(detail["data"]));
double.TryParse(detailOrderDic["price"].ToString(), out var sellPriceValue);
double.TryParse(orderDic["Price"].ToString(), out var buyPriceValue);
var resultRateData = ((sellPriceValue - buyPriceValue) / buyPriceValue) * 100;
var orderResult = new Dictionary<string, object>()
{
{ "MarketName", market },
{ "BuyDate", orderDic["BuyDate"]},
{ "BuyPrice", orderDic["Price"] },
{ "Type", "상향"},
{ "MCandleTimeType", (int)interval },
{ "BuyCandle", buyItem["Candle"] },
{ "SellDate", nowTime},
{ "SellPrice", detailOrderDic["price"] },
{ "SellCandle", candleData },
{ "Rate", resultRateData }
};
ResultList.Add(orderResult);
BuyLongList.Remove(orderDic);
LongCount--;
}
}
}
@@ -943,8 +1012,27 @@ namespace BitgetAPI.IndicatorConditionSetup
전저점Data["flag"] = false;
전저점Data["clearFlag"] = false;
}
if(ShortCount < 3)
{
double size = 50 / price;
var orderData = FutureOrder(market, FutureMarginMode.isolated, size, price, FutureSide.BuyShort, OrderType.limit, 10);
var orderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(orderData["data"]));
var orderDataDic = new Dictionary<string, object>
{
{ "MarketName", market },
{ "BuyDate", nowTime },
{ "Price", price },
{ "MCandleTimeType", (int)interval },
{ "Candle", candleData },
{ "Size", size },
{ "orderId", orderDic["orderId"] }
};
BuyShortList.Add(orderDataDic);
ShortCount++;
}
}
}
//파는 시점
else
@@ -989,6 +1077,39 @@ namespace BitgetAPI.IndicatorConditionSetup
DownResultList.Add(result);
DownBuyList.Remove(market + interval);
var orderDic = BuyShortList.FirstOrDefault(t => t["MarketName"].ToString() == market);
if (orderDic != null)
{
double.TryParse(orderDic["Size"].ToString(), out var size);
var sellOrder = FutureOrder(market, FutureMarginMode.isolated, size, 0, FutureSide.SellShort, OrderType.market, 10, orderDic["orderId"].ToString());
var sellOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(sellOrder["data"]));
var detail = GetFutureOrderDetail(market, sellOrderDic["orderId"]);
var detailOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(detail["data"]));
double.TryParse(detailOrderDic["price"].ToString(), out var sellPriceValue);
double.TryParse(orderDic["Price"].ToString(), out var buyPriceValue);
var resultRateData = ((sellPriceValue - buyPriceValue) / buyPriceValue) * 100;
var orderResult = new Dictionary<string, object>()
{
{ "MarketName", market },
{ "BuyDate", orderDic["BuyDate"]},
{ "BuyPrice", orderDic["Price"] },
{ "Type", "하향"},
{ "MCandleTimeType", (int)interval },
{ "BuyCandle", buyItem["Candle"] },
{ "SellDate", nowTime},
{ "SellPrice", detailOrderDic["price"] },
{ "SellCandle", candleData },
{ "Rate", resultRateData }
};
ResultList.Add(orderResult);
BuyShortList.Remove(orderDic);
ShortCount--;
}
}
}
}
@@ -1082,6 +1203,25 @@ namespace BitgetAPI.IndicatorConditionSetup
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetChangePositionMode_Future, BitgetURL_ChangePositionMode_Future, null, MCandleTimeType.M1, postStr, "", nvc);
}
public Dictionary<string, object> GetFutureOrderDetail(string symbol, string orderId)
{
var timeSpan = DateTime.Now;
var timestamp = (((DateTimeOffset)timeSpan).ToUnixTimeSeconds() * 1000).ToString();
// 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="+orderId.ToString()+"&productType=USDT-FUTURES", null, YHKIM_SecreteKey) },
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
{"ACCESS-TIMESTAMP",timestamp}
};
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetOrderDetail_Future, BitgetURL_OrderDetail_Future + "?symbol=" + symbol.ToString() + "&orderId=" + id.ToString() + "&productType=USDT-FUTURES", null, MCandleTimeType.M1, "", "", orderDetailnvc);
}
public Dictionary<string, object> FutureOrder(string symbol, FutureMarginMode marginMode, double size, double price, FutureSide futureSide, OrderType orderType, double leverage, string id = "")
{
@@ -1150,25 +1290,7 @@ 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-FUTURES", null, YHKIM_SecreteKey) },
// {"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
// {"ACCESS-TIMESTAMP",timestamp}
// };
// var orderDetail = (Dictionary<string, object>)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<Dictionary<string, object>>(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)