1096 lines
62 KiB
C#
1096 lines
62 KiB
C#
|
|
using BitgetApi.Data;
|
|
using BitgetApi.IndicatorConditionSetup;
|
|
using BitgetApi.IndicatorData;
|
|
using BitgetAPI.Data;
|
|
using BitgetAPI.WebService;
|
|
using DevExpress.XtraGrid.Views.Base;
|
|
using Newtonsoft.Json;
|
|
using Serilog;
|
|
using Serilog.Debugging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using static BitgetAPI.CommonProperty;
|
|
|
|
namespace BitgetAPI.IndicatorConditionSetup
|
|
{
|
|
public class IndicatorProcess
|
|
{
|
|
GlobalOptions options = GlobalOptions.Instance;
|
|
CommonProperty commonProperty = CommonProperty.Instance;
|
|
|
|
//영호 Key
|
|
private string YHKIM_AccessKey
|
|
{
|
|
get
|
|
{
|
|
return options.SelectAPI.AccessKey;
|
|
}
|
|
}
|
|
// = "bg_f93aa55288b6ec9d62095994c51972a";
|
|
private string YHKIM_SecreteKey
|
|
{
|
|
get
|
|
{
|
|
return options.SelectAPI.SecretKey;
|
|
}
|
|
}// = "2fce18bcd12ca23a7920c48295a58da031443ea383af8114ed599c1b14ac678e";
|
|
private string YHKIM_PassphraseKey
|
|
{
|
|
get
|
|
{
|
|
return options.SelectAPI.PassphraseKey;
|
|
}
|
|
}// = "dudgh0505";
|
|
|
|
private double YHKIM_Leverage
|
|
{
|
|
get
|
|
{
|
|
return options.Leverage;
|
|
}
|
|
}
|
|
|
|
private double YHKIM_OrderAmount
|
|
{
|
|
get
|
|
{
|
|
return options.OrderAmount;
|
|
}
|
|
}
|
|
|
|
|
|
// 스레드 시작/종료 플래그
|
|
public bool Is_th_SignalInfo;
|
|
public Dictionary<string, Dictionary<string, double>> 전저고점 = new Dictionary<string, Dictionary<string, double>>();
|
|
|
|
public List<object> checkedMarkets;
|
|
public List<object> intervalList;
|
|
|
|
// 신호검색 리스트 작성
|
|
// 신호 Long 상승 (구매)
|
|
public List<SignalInfoData> signals_LU = null;
|
|
// 신호 Short 하락 (구매)
|
|
public List<SignalInfoData> signals_SD = null;
|
|
// 검색현황 Long 하락 (판매)
|
|
public List<SignalInfoData> signals_LD = null;
|
|
// 검색현황 Short 상승 (판매)
|
|
public List<SignalInfoData> signals_SU = null;
|
|
|
|
public TimeSpan sesstionTime;
|
|
|
|
// 조건식 설정 상태
|
|
public bool checked구름떼상향돌파 = false;
|
|
public bool checked구름떼하향돌파 = false;
|
|
public bool 영호조건식_상향돌파 = false;
|
|
public bool 영호조건식_하향돌파 = false;
|
|
|
|
//구매 리스트
|
|
public Dictionary<string, Dictionary<string, object>> UpBuyList = new Dictionary<string, Dictionary<string, object>>();
|
|
//결과 리스트
|
|
public List<Dictionary<string, object>> UpResultList = new List<Dictionary<string, object>>();
|
|
|
|
//구매 리스트
|
|
public Dictionary<string, Dictionary<string, object>> DownBuyList = new Dictionary<string, Dictionary<string, object>>();
|
|
//결과 리스트
|
|
public List<Dictionary<string, object>> DownResultList = new List<Dictionary<string, object>>();
|
|
|
|
public Dictionary<string, bool> UpList = new Dictionary<string, bool>();
|
|
public Dictionary<string, double> UpBuyValue = new Dictionary<string, double>();
|
|
|
|
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>>();
|
|
|
|
public Dictionary<string, Dictionary<int, bool>> SellShortStep = new Dictionary<string, Dictionary<int, bool>>();
|
|
public Dictionary<string, Dictionary<int, bool>> SellLongStep = new Dictionary<string, Dictionary<int, bool>>();
|
|
|
|
//public Dictionary<string, int> BuyShortStep = new Dictionary<string, int>();
|
|
//public Dictionary<string, int> BuyLongStep = new Dictionary<string, int>();
|
|
|
|
//public Dictionary<string, double> BuyShortStepStampData = new Dictionary<string, double>();
|
|
//public Dictionary<string, double> BuyLongStepStampData = new Dictionary<string, double>();
|
|
|
|
public Dictionary<string, bool> FirstFlag = new Dictionary<string, bool>();
|
|
|
|
|
|
|
|
// 전봉이 구름떼 돌파후 시가가 구름떼 위에서 시작하는 것
|
|
// 전봉이 구름떼 하락후 시가가 구름떼 밑에서 시작하는 것
|
|
|
|
public void calProcess()
|
|
{
|
|
var range = 34;
|
|
IchimokuConditionSetup ichimokuConditionSetup = new IchimokuConditionSetup();
|
|
MovingAverageConditionSetup movingAverageConditionSetup = new MovingAverageConditionSetup();
|
|
TradingViewConditionSetup tradingViewConditionSetup = new TradingViewConditionSetup();
|
|
SMABandConditionSetup sMABandConditionSetup = new SMABandConditionSetup();
|
|
signals_LU.Clear();
|
|
signals_SD.Clear();
|
|
signals_LD.Clear();
|
|
signals_SU.Clear();
|
|
|
|
//시작시 한번만 하면됨(양방향)
|
|
ChangeFuturePositionMode(FuturePositionMode.hedge_mode);
|
|
//GetFutureAccountList();
|
|
//order 로직
|
|
//var orderDatas = FutureOrder("XRPUSDT", FutureMarginMode.isolated, 10, (double)0.549, 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"]);
|
|
var totalImperseMACDData = new Dictionary<string, Dictionary<DateTime, ImpulseMacdData>>();
|
|
|
|
|
|
// 추후 공통화 및 소스정리 필요
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
if (!Is_th_SignalInfo) break;
|
|
//Thread.Sleep(200);
|
|
var nowTime = DateTime.Now;
|
|
|
|
// 특정 시간 이후 삭제
|
|
foreach (var item in signals_LU.ToList())
|
|
{
|
|
// 시간 지나면 삭제
|
|
if (item.SignalStart + sesstionTime < nowTime)
|
|
{
|
|
signals_LU.Remove(item);
|
|
continue;
|
|
|
|
}
|
|
|
|
var findedMarket = commonProperty.candleDataLists.Find(i => i.ConGoodsData.MarketName == item.MarketName);
|
|
var lastCandleData = findedMarket.candleDataList[item.MCandleTimeType].OrderBy(i => i.Argument).ToList().Last();
|
|
|
|
if (lastCandleData.IchimokData != null)
|
|
{
|
|
if (checked구름떼상향돌파 || 영호조건식_상향돌파)
|
|
{
|
|
item.Price = lastCandleData.Close;
|
|
item.Rate = (lastCandleData.Close / lastCandleData.Open) * 100 - 100;
|
|
item.IndicatorRate = (lastCandleData.Close / item.IndicatorPrice) * 100 - 100;
|
|
}
|
|
}
|
|
}
|
|
foreach (var item in signals_SD.ToList())
|
|
{
|
|
// 시간 지나면 삭제
|
|
if (item.SignalStart + sesstionTime < nowTime)
|
|
{
|
|
signals_SD.Remove(item);
|
|
continue;
|
|
|
|
}
|
|
|
|
var findedMarket = commonProperty.candleDataLists.Find(i => i.ConGoodsData.MarketName == item.MarketName);
|
|
var candleDataList = findedMarket.candleDataList[item.MCandleTimeType].OrderBy(i => i.Argument).ToList();
|
|
if (candleDataList != null && candleDataList.Count > 0)
|
|
{
|
|
var lastCandleData = candleDataList.Last();
|
|
if (lastCandleData.IchimokData != null)
|
|
{
|
|
if (checked구름떼하향돌파 || 영호조건식_하향돌파)
|
|
{
|
|
item.Price = lastCandleData.Close;
|
|
item.Rate = (lastCandleData.Close / lastCandleData.Open) * 100 - 100;
|
|
item.IndicatorRate = (lastCandleData.Close / item.IndicatorPrice) * 100 - 100;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
foreach (var item in signals_LD.ToList())
|
|
if (item.SignalStart + sesstionTime < nowTime) signals_SU.Remove(item);
|
|
foreach (var item in signals_SU.ToList())
|
|
if (item.SignalStart + sesstionTime < nowTime) signals_SD.Remove(item);
|
|
|
|
// 체크된 마켓 정보
|
|
foreach (string market in checkedMarkets)
|
|
{
|
|
var findedMarket = commonProperty.candleDataLists.Find(i => i.ConGoodsData.MarketName == market);
|
|
var enumList = Enum.GetValues(typeof(CommonProperty.MCandleTimeType));
|
|
Array.Reverse(enumList);
|
|
|
|
foreach (CommonProperty.MCandleTimeType interval in enumList)
|
|
{
|
|
// Description
|
|
var strInterval = Utils.Convertor.GetEnumDescription((Enum)interval);
|
|
if (!intervalList.Contains(strInterval)) continue;
|
|
/*
|
|
if (nowTime.Minute == 0 && nowTime.Hour == 24 && 전저고점Flag)
|
|
{
|
|
전저고점.Clear();
|
|
전저고점Flag = false;
|
|
}
|
|
|
|
if (!전저고점.ContainsKey(market + strInterval))
|
|
{
|
|
FirstFlag.Add(market + strInterval + "Long", false);
|
|
FirstFlag.Add(market + strInterval + "Short", false);
|
|
var dic = new Dictionary<string, double>
|
|
{
|
|
{ "전고가", 0 },
|
|
{ "전저가", 0 },
|
|
{ "전전고가", 0 },
|
|
{ "전전저가", 0 },
|
|
{ "전전전저가", 0 },
|
|
{ "전전전고가", 0 },
|
|
{ "전전전전저가", 0 },
|
|
{ "전전전전고가", 0 },
|
|
{ "tempHighVal", 0 },
|
|
{ "tempLowVal", 0 },
|
|
{ "tempHigh2Val", 0 },
|
|
{ "tempLow2Val", 0 },
|
|
{ "tempHigh3Val", 0 },
|
|
{ "tempLow3Val", 0 },
|
|
{ "tempHigh4Val", 0 },
|
|
{ "tempLow4Val", 0 },
|
|
{ "switchLowVal", 0 },
|
|
{ "switchHighVal", 0 }
|
|
};
|
|
|
|
전저고점.Add(market + strInterval, dic);
|
|
|
|
var candleDatas_Temp = findedMarket.candleDataList[interval];
|
|
var candleDatas_정렬_Temp = candleDatas_Temp.OrderBy(i => i.Argument).ToList();
|
|
var candleDatas_Temp_List = new List<CandleData>();
|
|
|
|
totalImperseMACDData[market + strInterval] = new Dictionary<DateTime, ImpulseMacdData>();
|
|
|
|
|
|
for (var i = 0; i < 199; i++)
|
|
candleDatas_Temp_List.Add(candleDatas_정렬_Temp[i]);
|
|
|
|
for (var i = 199; i < candleDatas_정렬_Temp.Count; i++)
|
|
{
|
|
|
|
var candleData_Main = candleDatas_정렬_Temp[i];
|
|
|
|
if (candleData_Main == null) continue;
|
|
|
|
|
|
candleDatas_Temp_List.Add(candleData_Main);
|
|
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_Temp_List, candleData_Main);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_Temp_List, candleData_Main);
|
|
|
|
if (i > 210)
|
|
{
|
|
var 현재봉4_Temp = candleDatas_Temp_List[i].movingAverageDataList[4].Value;
|
|
var 전봉4_Temp = candleDatas_Temp_List[i - 1].movingAverageDataList[4].Value;
|
|
var 전전봉4_Temp = candleDatas_Temp_List[i - 2].movingAverageDataList[4].Value;
|
|
var 전전전봉4_Temp = candleDatas_Temp_List[i - 3].movingAverageDataList[4].Value;
|
|
|
|
var returnVal = Calculate전고점(market, strInterval, interval, 전봉4_Temp, 전전봉4_Temp, 전전전봉4_Temp, candleDatas_Temp_List[candleDatas_Temp_List.Count - 1]);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(nowTime.Minute > 0 && nowTime.Hour == 24)
|
|
전저고점Flag = true;
|
|
}
|
|
|
|
if (!BuyShortStep.ContainsKey(market))
|
|
{
|
|
BuyShortStep[market] = 0;
|
|
BuyLongStep[market] = 0;
|
|
}
|
|
if (!(전저고점.ContainsKey(market + "30m")))
|
|
continue;
|
|
*/
|
|
#region 30분봉 처리
|
|
|
|
var candleDatas_30 = findedMarket.candleDataList[MCandleTimeType.M30];
|
|
var candleDatas_30_정렬 = candleDatas_30.OrderBy(i => i.Argument).ToList();
|
|
var candleDatas_30_TempList = candleDatas_30.OrderBy(i => i.Argument).ToList();
|
|
var candleData_30 = candleDatas_30.Find(i => i.Argument == candleDatas_30_정렬.Last().Argument);
|
|
|
|
if (candleData_30 == null) continue;
|
|
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_30_정렬, candleData_30);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_30_정렬, candleData_30);
|
|
|
|
candleDatas_30_정렬.RemoveAt(candleDatas_30_정렬.Count - 1);
|
|
var candleData_30_전봉 = candleDatas_30.Find(i => i.Argument == candleDatas_30_정렬.Last().Argument);
|
|
|
|
if (candleData_30_전봉 == null) continue;
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_30_정렬, candleData_30_전봉);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_30_정렬, candleData_30_전봉);
|
|
|
|
candleDatas_30_정렬.RemoveAt(candleDatas_30_정렬.Count - 1);
|
|
var candleData_30_전전봉 = candleDatas_30.Find(i => i.Argument == candleDatas_30_정렬.Last().Argument);
|
|
|
|
if (candleData_30_전전봉 == null) continue;
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_30_정렬, candleData_30_전전봉);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_30_정렬, candleData_30_전전봉);
|
|
|
|
candleDatas_30_정렬.RemoveAt(candleDatas_30_정렬.Count - 1);
|
|
var candleData_30_전전전봉 = candleDatas_30.Find(i => i.Argument == candleDatas_30_정렬.Last().Argument);
|
|
|
|
if (candleData_30_전전전봉 == null) continue;
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_30_정렬, candleData_30_전전전봉);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_30_정렬, candleData_30_전전전봉);
|
|
|
|
|
|
candleDatas_30_정렬.RemoveAt(candleDatas_30_정렬.Count - 1);
|
|
var candleData_30_전전전전봉 = candleDatas_30.Find(i => i.Argument == candleDatas_30_정렬.Last().Argument);
|
|
|
|
if (candleData_30_전전전전봉 == null) continue;
|
|
ichimokuConditionSetup.calIchimokuData(candleDatas_30_정렬, candleData_30_전전전전봉);
|
|
movingAverageConditionSetup.Cal_YHK_Downpublic(candleDatas_30_정렬, candleData_30_전전전전봉);
|
|
#endregion
|
|
//var 저고점 = 전저고점[market + strInterval];
|
|
|
|
|
|
if (영호조건식_상향돌파 || 영호조건식_하향돌파)
|
|
{
|
|
if (영호조건식_상향돌파)
|
|
{
|
|
var price = candleData_30.Close;
|
|
var rate = (candleData_30.Close / candleData_30.Open) * 100 - 100;
|
|
var indicatorPrice = candleData_30.Open;
|
|
var indicatorRate = (candleData_30.Close / indicatorPrice) * 100 - 100;
|
|
|
|
var description = string.Format("{0} 72,24,4 상승", strInterval);
|
|
var signalData = signals_SD.Find(i => i.MarketName.Equals(market) && i.Description.Equals(description));
|
|
|
|
//전 저점 계산
|
|
|
|
try
|
|
{
|
|
//사는 시점
|
|
if (!UpBuyList.ContainsKey(market))
|
|
{
|
|
//if(!FirstFlag[market + strInterval + "Long"])
|
|
//{
|
|
// if(sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.LongSell, true))
|
|
// {
|
|
// FirstFlag[market + strInterval + "Long"] = true;
|
|
// }
|
|
//}
|
|
|
|
if (sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.LongBuy, true) &&
|
|
!sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.LongSell, true)
|
|
//&& FirstFlag[market + strInterval + "Long"]
|
|
|
|
//&& 저고점["전저가"] > 저고점["전전저가"]
|
|
)
|
|
{
|
|
//BuyLongStep[market] = 0;
|
|
// 없으면 생성
|
|
if (signalData == null)
|
|
{
|
|
SignalInfoData signalInfoData = new SignalInfoData();
|
|
signalInfoData.SignalStart = nowTime;
|
|
signalInfoData.MarketName = market;
|
|
signalInfoData.Description = description;
|
|
signalInfoData.Rate = rate;
|
|
signalInfoData.Price = price;
|
|
signalInfoData.IndicatorPrice = indicatorPrice;
|
|
signalInfoData.IndicatorRate = indicatorRate;
|
|
signalInfoData.MCandleTimeType = interval;
|
|
|
|
signals_SD.Add(signalInfoData);
|
|
}
|
|
|
|
var buyDic = new Dictionary<string, object>
|
|
{
|
|
{ "MarketName", market },
|
|
{ "BuyDate", nowTime },
|
|
{ "Price", price },
|
|
//{ "Flag", 저고점["전저가"] > 저고점["전전저가"] },
|
|
{ "MCandleTimeType", (int)interval },
|
|
{ "CandleTime", candleData_30.Argument },
|
|
{ "Candle", candleData_30 }
|
|
};
|
|
|
|
UpBuyList.Add(market, buyDic);
|
|
|
|
var dic = new Dictionary<int, bool>
|
|
{
|
|
[1] = true,
|
|
[2] = false,
|
|
[3] = false,
|
|
[4] = false,
|
|
[5] = false
|
|
};
|
|
SellLongStep.Add(market, dic);
|
|
if (LongCount < 5)
|
|
{
|
|
double size = YHKIM_OrderAmount / price * YHKIM_Leverage;
|
|
var orderData = FutureOrder(market, FutureMarginMode.isolated, size, 0, FutureSide.BuyLong, OrderType.limit, YHKIM_Leverage);
|
|
if (orderData != null)
|
|
{
|
|
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_30 },
|
|
{ "Size", size },
|
|
{ "orderId", orderDic["orderId"] }
|
|
};
|
|
BuyLongList.Add(orderDataDic);
|
|
LongCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//파는 시점
|
|
else
|
|
{
|
|
|
|
var buyItem = UpBuyList[market];
|
|
var flag = (bool)buyItem["Flag"];
|
|
if (interval < MCandleTimeType.H1)
|
|
{
|
|
var buyTime = ((DateTime)buyItem["BuyDate"]).AddMinutes(30);
|
|
if (nowTime < buyTime)
|
|
continue;
|
|
|
|
}
|
|
//임시로 처리
|
|
else
|
|
{
|
|
var buyTime = ((DateTime)buyItem["BuyDate"]).AddHours((int)interval / 60);
|
|
if (nowTime < buyTime)
|
|
continue;
|
|
}
|
|
|
|
var sellFlag = false;
|
|
|
|
//if (!flag)
|
|
//{
|
|
// if (저고점["전저가"] > 저고점["전전저가"])
|
|
// buyItem["Flag"] = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// if (저고점["전저가"] < 저고점["전전저가"] || 저고점["전저가"] > candleData_30_전봉.Close)
|
|
// sellFlag = true;
|
|
//}
|
|
|
|
if (sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.LongSell, true) || sellFlag)
|
|
{
|
|
double.TryParse(buyItem["Price"].ToString(), out var buyPrice);
|
|
var resultRate = ((price - buyPrice) / buyPrice) * 100;
|
|
//BuyLongStep[market] = 0;
|
|
var result = new Dictionary<string, object>()
|
|
{
|
|
{ "MarketName", market },
|
|
{ "BuyDate", buyItem["BuyDate"]},
|
|
{ "Type", "상향"},
|
|
{ "BuyPrice", buyPrice },
|
|
{ "MCandleTimeType", (int)interval },
|
|
{ "BuyCandle", buyItem["Candle"] },
|
|
{ "SellDate", nowTime},
|
|
{ "SellPrice", price },
|
|
{ "SellCandle", candleData_30 },
|
|
{ "Rate", resultRate }
|
|
};
|
|
|
|
UpResultList.Add(result);
|
|
UpBuyList.Remove(market);
|
|
SellLongStep.Remove(market);
|
|
|
|
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, YHKIM_Leverage, orderDic["orderId"].ToString());
|
|
|
|
if (sellOrder != null)
|
|
{
|
|
var sellOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(sellOrder["data"]));
|
|
}
|
|
else
|
|
{
|
|
Log.Error("Sell 안됨 확인 필요");
|
|
}
|
|
double.TryParse(orderDic["Price"].ToString(), out var buyPriceValue);
|
|
//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);
|
|
|
|
var resultRateData = ((price - 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", price},
|
|
{ "SellCandle", candleData_30 },
|
|
{ "Rate", resultRateData }
|
|
};
|
|
ResultList.Add(orderResult);
|
|
BuyLongList.Remove(orderDic);
|
|
LongCount--;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
}
|
|
if (영호조건식_하향돌파)
|
|
{
|
|
var price = candleData_30.Close;
|
|
var rate = (candleData_30.Close / candleData_30.Open) * 100 - 100;
|
|
var indicatorPrice = candleData_30.Open;
|
|
var indicatorRate = (candleData_30.Close / indicatorPrice) * 100 - 100;
|
|
|
|
var description = string.Format("{0} 72,24,4 하락", strInterval);
|
|
var signalData = signals_SD.Find(i => i.MarketName.Equals(market) && i.Description.Equals(description));
|
|
|
|
try
|
|
{
|
|
//사는 시점
|
|
if (!DownBuyList.ContainsKey(market))
|
|
{
|
|
|
|
|
|
if (sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.ShortBuy, true) &&
|
|
!sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.ShortSell, true) &&
|
|
FirstFlag[market + strInterval + "Short"]
|
|
//&& 저고점["전고가"] < 저고점["전전고가"])
|
|
)
|
|
{
|
|
//BuyShortStep[market] = 0;
|
|
// 없으면 생성
|
|
if (signalData == null)
|
|
{
|
|
SignalInfoData signalInfoData = new SignalInfoData();
|
|
signalInfoData.SignalStart = nowTime;
|
|
signalInfoData.MarketName = market;
|
|
signalInfoData.Description = description;
|
|
signalInfoData.Rate = rate;
|
|
signalInfoData.Price = price;
|
|
signalInfoData.IndicatorPrice = indicatorPrice;
|
|
signalInfoData.IndicatorRate = indicatorRate;
|
|
signalInfoData.MCandleTimeType = interval;
|
|
|
|
signals_SD.Add(signalInfoData);
|
|
}
|
|
var buyDic = new Dictionary<string, object>
|
|
{
|
|
{ "MarketName", market },
|
|
{ "BuyDate", nowTime },
|
|
{ "Price", price },
|
|
//{ "Flag", 저고점["전고가"] < 저고점["전전고가"] },
|
|
{ "MCandleTimeType", (int)interval },
|
|
{ "CandleTime", candleData_30.Argument },
|
|
{ "Candle", candleData_30 }
|
|
};
|
|
|
|
DownBuyList.Add(market, buyDic);
|
|
var dic = new Dictionary<int, bool>
|
|
{
|
|
[1] = true,
|
|
[2] = false,
|
|
[3] = false,
|
|
[4] = false,
|
|
[5] = false
|
|
};
|
|
SellShortStep.Add(market, dic);
|
|
|
|
if (ShortCount < 5)
|
|
{
|
|
double size = YHKIM_OrderAmount / price * YHKIM_Leverage;
|
|
var orderData = FutureOrder(market, FutureMarginMode.isolated, size, price, FutureSide.BuyShort, OrderType.limit, YHKIM_Leverage);
|
|
if (orderData != null)
|
|
{
|
|
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_30 },
|
|
{ "Size", size },
|
|
{ "orderId", orderDic["orderId"] }
|
|
};
|
|
BuyShortList.Add(orderDataDic);
|
|
ShortCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//파는 시점
|
|
else
|
|
{
|
|
var buyItem = DownBuyList[market];
|
|
var flag = (bool)buyItem["Flag"];
|
|
if (interval < MCandleTimeType.H1)
|
|
{
|
|
var buyTime = ((DateTime)buyItem["BuyDate"]).AddMinutes(30);
|
|
|
|
if (nowTime < buyTime)
|
|
continue;
|
|
|
|
}
|
|
//임시로 처리
|
|
else
|
|
{
|
|
var buyTime = ((DateTime)buyItem["BuyDate"]).AddHours((int)interval / 60);
|
|
|
|
if (nowTime < buyTime)
|
|
continue;
|
|
|
|
}
|
|
|
|
var sellFlag = false;
|
|
|
|
//if (!flag)
|
|
//{
|
|
// if (저고점["전고가"] < 저고점["전전고가"])
|
|
// buyItem["Flag"] = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// if (저고점["전고가"] > 저고점["전전고가"] || 저고점["전고가"] < candleData_30_전봉.Close)
|
|
// sellFlag = true;
|
|
//}
|
|
|
|
if (sMABandConditionSetup.Calculate(candleDatas_30_TempList, SMABandType.ShortSell, true) || sellFlag)
|
|
{
|
|
//BuyShortStep[market] = 0;
|
|
double.TryParse(buyItem["Price"].ToString(), out var buyPrice);
|
|
var resultRate = ((price - buyPrice) / buyPrice) * 100;
|
|
|
|
var result = new Dictionary<string, object>()
|
|
{
|
|
{ "MarketName", market },
|
|
{ "BuyDate", buyItem["BuyDate"]},
|
|
{ "BuyPrice", buyPrice },
|
|
{ "Type", "하향"},
|
|
{ "MCandleTimeType", (int)interval },
|
|
{ "BuyCandle", buyItem["Candle"] },
|
|
{ "SellDate", nowTime},
|
|
{ "SellPrice", price },
|
|
{ "SellCandle", candleData_30 },
|
|
{ "Rate", resultRate }
|
|
};
|
|
|
|
DownResultList.Add(result);
|
|
DownBuyList.Remove(market);
|
|
SellShortStep.Remove(market);
|
|
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, YHKIM_Leverage, orderDic["orderId"].ToString());
|
|
|
|
if (sellOrder != null)
|
|
{
|
|
var sellOrderDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(sellOrder["data"]));
|
|
}
|
|
else
|
|
{
|
|
Log.Error("Sell 안됨 확인 필요");
|
|
}
|
|
|
|
|
|
double.TryParse(orderDic["Price"].ToString(), out var buyPriceValue);
|
|
//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);
|
|
|
|
var resultRateData = ((price - 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", price },
|
|
{ "SellCandle", candleData_30 },
|
|
{ "Rate", resultRateData }
|
|
};
|
|
ResultList.Add(orderResult);
|
|
BuyShortList.Remove(orderDic);
|
|
ShortCount--;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Calculate전고점(string market, string strInterval, MCandleTimeType type, double 전봉, double 전전봉, double 전전전봉, CandleData candleData)
|
|
{
|
|
|
|
var 저고점 = 전저고점[market + strInterval];
|
|
|
|
//전저가
|
|
if (전봉 > 전전봉 && 전전봉 < 전전전봉 && 저고점["tempHighVal"] >= 저고점["tempLowVal"] &&
|
|
저고점["tempLowVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempHighVal"] >= 120 * (int)type)
|
|
{
|
|
저고점["tempLow4Val"] = 저고점["tempLowVal"];
|
|
저고점["tempLowVal"] = 저고점["tempLow2Val"];
|
|
저고점["tempLow2Val"] = 저고점["tempLowVal"];
|
|
저고점["tempLowVal"] = ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds();
|
|
저고점["switchLowVal"] = 저고점["전전전전저가"];
|
|
저고점["전전전전저가"] = 저고점["전전저가"];
|
|
저고점["전전전저가"] = 저고점["전전저가"];
|
|
저고점["전전저가"] = 저고점["전저가"];
|
|
저고점["전저가"] = 전전봉;
|
|
저고점["Type"] = 0;
|
|
|
|
}
|
|
else if (전봉 > 전전봉 && 전전봉 < 전전전봉 && 저고점["tempHighVal"] < 저고점["tempLowVal"] &&
|
|
저고점["tempLowVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempHighVal"] >= 120 * (int)type)
|
|
{
|
|
if (저고점["전저가"] > 전전봉)
|
|
{
|
|
저고점["tempLowVal"] = ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds();
|
|
저고점["전저가"] = 전전봉;
|
|
}
|
|
|
|
저고점["Type"] = 0;
|
|
}
|
|
else if (전봉 > 전전봉 && 전전봉 < 전전전봉 &&
|
|
저고점["tempLowVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempHighVal"] < 120 * (int)type)
|
|
{
|
|
//이전으로 초기화 작업(High)
|
|
저고점["전고가"] = 저고점["전전고가"];
|
|
저고점["전전고가"] = 저고점["전전전고가"];
|
|
저고점["전전전고가"] = 저고점["전전전전고가"];
|
|
저고점["Type"] = 0;
|
|
저고점["전전전전고가"] = 저고점["switchLowVal"];
|
|
저고점["tempHighVal"] = 저고점["tempHigh2Val"];
|
|
저고점["tempHigh2Val"] = 저고점["tempHighVal"];
|
|
저고점["tempHighVal"] = 저고점["tempHigh4Val"];
|
|
|
|
if (저고점["전저가"] > 전전봉)
|
|
저고점["전저가"] = 전전봉;
|
|
}
|
|
|
|
//전고가
|
|
if (전전봉 > 전봉 && 전전봉 > 전전전봉 && 저고점["tempHighVal"] <= 저고점["tempLowVal"] &&
|
|
저고점["tempHighVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempLowVal"] >= 120 * (int)type)
|
|
{
|
|
저고점["tempHigh4Val"] = 저고점["tempHighVal"];
|
|
저고점["tempHighVal"] = 저고점["tempHigh2Val"];
|
|
저고점["tempHigh2Val"] = 저고점["tempHighVal"];
|
|
저고점["tempHighVal"] = ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds();
|
|
저고점["switchHighVal"] = 저고점["전전전전고가"];
|
|
저고점["전전전전고가"] = 저고점["전전전고가"];
|
|
저고점["전전전고가"] = 저고점["전전고가"];
|
|
저고점["전전고가"] = 저고점["전고가"];
|
|
저고점["Type"] = 1;
|
|
저고점["전고가"] = 전전봉;
|
|
}
|
|
else if (전전봉 > 전봉 && 전전봉 > 전전전봉 && 저고점["tempHighVal"] > 저고점["tempLowVal"] &&
|
|
저고점["tempHighVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempLowVal"] >= 120 * (int)type)
|
|
{
|
|
if (저고점["전고가"] < 전전봉)
|
|
{
|
|
저고점["tempHighVal"] = ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds();
|
|
저고점["전고가"] = 전전봉;
|
|
}
|
|
}
|
|
else if (전전봉 > 전봉 && 전전봉 > 전전전봉 &&
|
|
저고점["tempHighVal"] != ((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() &&
|
|
((DateTimeOffset)candleData.Argument).ToUnixTimeSeconds() - 저고점["tempLowVal"] < 120 * (int)type)
|
|
{
|
|
//이전으로 초기화 작업(Low)
|
|
저고점["전저가"] = 저고점["전전저가"];
|
|
저고점["전전저가"] = 저고점["전전전저가"];
|
|
저고점["전전전저가"] = 저고점["전전전전저가"];
|
|
저고점["전전전전저가"] = 저고점["switchHighVal"];
|
|
저고점["Type"] = 1;
|
|
저고점["tempLowVal"] = 저고점["tempLow2Val"];
|
|
저고점["tempLow2Val"] = 저고점["tempLowVal"];
|
|
저고점["tempLowVal"] = 저고점["tempLow4Val"];
|
|
|
|
if (저고점["전고가"] < 전전봉)
|
|
저고점["전고가"] = 전전봉;
|
|
}
|
|
|
|
if (저고점["전전전저가"] == 0 || 저고점["전전전고가"] == 0)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public Dictionary<string, object> GetPendingOrders()
|
|
{
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
var reqStr = "/api/v2/mix/order/orders-pending";
|
|
|
|
var nvc = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "GET", reqStr, "productType=USDT-FUTURES", null, YHKIM_SecreteKey) },
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP",timestamp}
|
|
};
|
|
|
|
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetPendingOrder_Future, BitgetURL_PendingOrders_Future, null, MCandleTimeType.M30, "", "", nvc);
|
|
}
|
|
|
|
public long GetTimeStamp()
|
|
{
|
|
|
|
var result = (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetGetTimeStamp, BitgetURL_GetTimestamp, null, MCandleTimeType.M30, "", "", null);
|
|
if (result == null)
|
|
{
|
|
return 0;
|
|
}
|
|
var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(result["data"]));
|
|
long.TryParse(data["serverTime"].ToString(), out var returnData);
|
|
return returnData;
|
|
}
|
|
|
|
|
|
public List<Dictionary<string, object>> GetFutureAccountList()
|
|
{
|
|
|
|
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
var reqStr = "/api/v2/mix/account/accounts";
|
|
|
|
var nvc = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "GET", reqStr, "productType=USDT-FUTURES", null, YHKIM_SecreteKey) },
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP",timestamp}
|
|
};
|
|
|
|
return (List<Dictionary<string, object>>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetAccountList_Future, BitgetURL_AccountList_Future, null, MCandleTimeType.M30, "", "", nvc);
|
|
}
|
|
|
|
public Dictionary<string, object> CancelFutureOrder(string symbol, string orderId)
|
|
{
|
|
|
|
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
var reqStr = "/api/v2/mix/order/cancel-order";
|
|
var postStr = "{\"symbol\" : \"" + symbol + "\", \"orderId\" : \"" + orderId + "\", \"productType\" : \"usdt-futures\" , \"marginCoin\" : \"USDT\"}";
|
|
var nvc = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "POST", reqStr, "", postStr, YHKIM_SecreteKey)},
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP", timestamp}
|
|
};
|
|
|
|
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetCancelOrder_Future, BitgetURL_CancelOrder_Future, null, MCandleTimeType.M30, postStr, "", nvc);
|
|
}
|
|
|
|
public Dictionary<string, object> ChangeFuturePositionMode(FuturePositionMode mode)
|
|
{
|
|
|
|
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
var reqStr = "/api/v2/mix/account/set-position-mode";
|
|
var postStr = "{\"productType\" : \"USDT-FUTURES\", \"posMode\" : \"" + Utils.Convertor.GetEnumDescription((Enum)mode) + "\"}";
|
|
|
|
var nvc = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "POST", reqStr, "", postStr, YHKIM_SecreteKey)},
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP", timestamp}
|
|
};
|
|
|
|
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetChangePositionMode_Future, BitgetURL_ChangePositionMode_Future, null, MCandleTimeType.M30, postStr, "", nvc);
|
|
}
|
|
|
|
public Dictionary<string, object> GetFutureOrderDetail(string symbol, string orderId)
|
|
{
|
|
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
// sell은 ClientOID 가 필요
|
|
var orderDetailStr = "/api/v2/mix/order/detail";
|
|
timestamp = GetTimeStamp().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=" + orderId.ToString() + "&productType=USDT-FUTURES", null, MCandleTimeType.M30, "", "", orderDetailnvc);
|
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, object> FutureOrder(string symbol, FutureMarginMode marginMode, double size, double price, FutureSide futureSide, OrderType orderType, double leverage, string id = "")
|
|
{
|
|
var side = "";
|
|
var tradeSide = "";
|
|
|
|
if (futureSide == FutureSide.BuyShort)
|
|
{
|
|
id = Guid.NewGuid().ToString();
|
|
side = "sell";
|
|
tradeSide = "open";
|
|
}
|
|
else if (futureSide == FutureSide.BuyLong)
|
|
{
|
|
id = Guid.NewGuid().ToString();
|
|
side = "buy";
|
|
tradeSide = "Open";
|
|
}
|
|
else if (futureSide == FutureSide.SellShort)
|
|
{
|
|
side = "sell";
|
|
tradeSide = "close";
|
|
}
|
|
else if (futureSide == FutureSide.SellLong)
|
|
{
|
|
side = "buy";
|
|
tradeSide = "close";
|
|
}
|
|
|
|
if (orderType == OrderType.market)
|
|
price = 0;
|
|
|
|
|
|
|
|
var timestamp = GetTimeStamp().ToString();
|
|
|
|
var reqStr = "/api/v2/mix/order/place-order";
|
|
|
|
if (futureSide == FutureSide.BuyShort || futureSide == FutureSide.BuyLong)
|
|
{
|
|
//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-SIGN", GenerateSignString(timestamp, "POST", "/api/v2/mix/account/set-margin-mode", "", changeMarginModeStr, YHKIM_SecreteKey)},
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP", timestamp}
|
|
};
|
|
var result = (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetChangeMarginMode_Future, BitgetURL_ChangeMarginMode_Future, null, MCandleTimeType.M30, changeMarginModeStr, "", nvcMargin);
|
|
if (result == null || result["msg"]?.ToString() != "success")
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var leverageStr = "{\"symbol\": \"" + symbol + "\", \"productType\": \"USDT-FUTURES\", \"marginCoin\": \"USDT\", \"leverage\": \"" + leverage.ToString() + "\", \"holdSide\": \"" + (futureSide == FutureSide.BuyShort ? "short" : "long") + "\"}";
|
|
timestamp = GetTimeStamp().ToString();
|
|
var nvcLeverage = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "POST", "/api/v2/mix/account/set-leverage", "", leverageStr, YHKIM_SecreteKey)},
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP", timestamp}
|
|
};
|
|
result = (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetChangeLeverage_Future, BitgetURL_ChangeLeverage_Future, null, MCandleTimeType.M30, leverageStr, "", nvcLeverage);
|
|
if (result == null || result["msg"]?.ToString() != "success")
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var result = CancelFutureOrder(symbol, id);
|
|
if (result == null || result["msg"]?.ToString() != "success")
|
|
{
|
|
Log.Error("Sell에서 Cancel관련 Error");
|
|
}
|
|
}
|
|
|
|
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)
|
|
+ "\", \"force\": \"gtc\", \"clientOid\": \"" + id + "\" }";
|
|
timestamp = GetTimeStamp().ToString();
|
|
var nvc = new NameValueCollection {
|
|
{"ACCESS-KEY", YHKIM_AccessKey},
|
|
{"ACCESS-SIGN", GenerateSignString(timestamp, "POST", reqStr, "", postStr, YHKIM_SecreteKey)},
|
|
{"ACCESS-PASSPHRASE", YHKIM_PassphraseKey },
|
|
{"ACCESS-TIMESTAMP", timestamp}
|
|
};
|
|
return (Dictionary<string, object>)WebConnection.SendWebServer(ExchangeWebReqType.BitgetOrder_Future, BitgetURL_BuySellOrder_Future, null, MCandleTimeType.M30, postStr, "", nvc);
|
|
}
|
|
|
|
public string GenerateSignString(string timestamp, string method, string requestPath, string queryString, string body, string secretKey)
|
|
{
|
|
method = method.ToUpper();
|
|
body = body == null ? "" : body;
|
|
queryString = string.IsNullOrWhiteSpace(queryString) ? "" : "?" + queryString;
|
|
string preHash = timestamp + method + requestPath + queryString + body;
|
|
|
|
var encSecretKey_byteData = System.Text.Encoding.UTF8.GetBytes(secretKey);
|
|
var encPreHash_byteData = System.Text.Encoding.UTF8.GetBytes(preHash);
|
|
|
|
return Convert.ToBase64String(new HMACSHA256(encSecretKey_byteData).ComputeHash(encPreHash_byteData));
|
|
}
|
|
|
|
public void calIchimokuProcess_Add()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
public void calIchimokuProcess_Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|