손절 조건 처리하는 Buyer기능 추가

This commit is contained in:
kyh
2022-11-28 12:03:40 +09:00
parent aaa6163459
commit 6a192b4121
3 changed files with 72 additions and 13 deletions

View File

@@ -329,13 +329,13 @@ namespace Million_Buyer
candleTypeList = candleTypeList.Distinct().ToList();
//사고 파는 rex 데이터 가져오는 부분
var buyRex = _saveResultData.BuyRegularExpression;
var sellRex = _saveResultData.SellRegularExpression;
var buyScript = new InteratorScripter("Buy Script");
buyScript.regularExpressionString = buyRex;
buyScript.regularExpressionString = _saveResultData.BuyRegularExpression;
var sellScript = new InteratorScripter("Sell Script");
sellScript.regularExpressionString = sellRex;
sellScript.regularExpressionString = _saveResultData.SellRegularExpression;
var sellExceptionScript = new InteratorScripter("Sell Exception Script");
sellExceptionScript.regularExpressionString = _saveResultData.SellExceptionRegularExpression;
var scriptDic = new Dictionary<string, bool>();
@@ -468,8 +468,17 @@ namespace Million_Buyer
var minDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min();
var maxDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max().AddHours(1);
var buyDataList = buyList.FirstOrDefault(t => t.ConGoodsData.CoinFullName == item);
sw.Restart();
dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, item, true);
if (buyDataList != null && buyDataList.CandleDataLists_Im.Count > 0)
{
dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, item, true, buyDataList.CandleDataLists_Im[0]);
}
else
{
dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, item, true);
}
sw.Stop();
if (sw.Elapsed.TotalSeconds > 1)
InsertLog("Indicator Calculate 계산 시간 : " + sw.Elapsed.ToString());
@@ -516,7 +525,7 @@ namespace Million_Buyer
buyData.CandleDataLists_Im.Add(recentlyData);
var valDic = ResultLogicManager.GetIndicateValue(recentlyData.CalculateFlag, totalIndicatorList, recentlyData);
recentlyData.BuyValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(buyRex, valDic, recentlyData.CalculateFlag));
recentlyData.BuyValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(buyScript.regularExpressionString, valDic, recentlyData.CalculateFlag));
recentlyData.BuyTime = time;
buyData.ConGoodsData = CommonProperty.selectedMarketOfPlaceList.FirstOrDefault(t => t.CoinFullName == item);
@@ -574,7 +583,15 @@ namespace Million_Buyer
}
else
{
//default sell
var flag = sellScript.DicExcuteScript(recentlyData.CalculateFlag);
if (!flag)
{
//예외처리 로직 추가
}
if (flag)
{
sw.Restart();
@@ -583,7 +600,7 @@ namespace Million_Buyer
var sellItem = recentlyData;
var valDic = ResultLogicManager.GetIndicateValue(sellItem.CalculateFlag, totalIndicatorList, sellItem);
sellItem.SellValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(sellRex, valDic, sellItem.CalculateFlag), false);
sellItem.SellValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(sellScript.regularExpressionString, valDic, sellItem.CalculateFlag), false);
sellItem.SellTime = time;
var buyCandleData = buyItem.CandleDataLists_Im[0];

View File

@@ -317,7 +317,7 @@ namespace Million.Manager
/// <param name="childrenCandleDataList"></param>
/// <returns></returns>
public static void SwitchFun(List<IndicatorCoditionSetup> totalIndicator, IndicatorCoditionSetup setUp, List<CandleData> parentCandleDataList,
List<CandleData> childrenCandleDataList, List<IndicatorCoditionSetup> subIndicator, bool recentlyDataFlag, string coinFullName)
List<CandleData> childrenCandleDataList, List<IndicatorCoditionSetup> subIndicator, bool recentlyDataFlag, string coinFullName, CandleData buyData)
{
parentCandleDataList = parentCandleDataList.OrderBy(t => t.DateTime).ToList();
childrenCandleDataList = childrenCandleDataList.OrderBy(t => t.DateTime).ToList();
@@ -340,6 +340,10 @@ namespace Million.Manager
{
EndValue(setUp, parentCandleDataList, childrenCandleDataList);
}
else if (temp.PriceRateSetupConditionType == PriceRateSetupConditionType.비율)
{
RateValue(setUp, parentCandleDataList, childrenCandleDataList, buyData);
}
}
//돌파
else if (setUp.SubIndicatorSetupType == SubIndicatorSetupType.돌파비교)
@@ -365,6 +369,44 @@ namespace Million.Manager
}
}
/// <summary>
/// Rate 판매 -> 구매는 될수가 없음 기준이 없으므로(추후 어떤식으로 할지는 모르겠음)
/// </summary>
/// <param name="setUp"></param>
/// <param name="parentCandleDataList"></param>
/// <param name="childrenCandleDataList"></param>
/// <param name="buyList"></param>
private static void RateValue(IndicatorCoditionSetup setUp, List<CandleData> parentCandleDataList, List<CandleData> childrenCandleDataList, CandleData buyData)
{
// buy의 경우 하나만 사고 있음(여러개가 다른 가격대 일경우는 제외함 -> 나중에 V2에서 해야할 듯)
if(buyData != null)
{
var rate = ((PriceRateCondtionSetup)setUp).Rate;
var rateVal = buyData.BuyValue + (buyData.BuyValue * rate / 100);
foreach (var item in parentCandleDataList)
{
var itemValue = GetValue(item, setUp);
if (setUp.CandlePriceType == CommonProperty.CandlePriceType.종가)
itemValue = item.LowValue;
if(rateVal > itemValue)
{
item.CalculateFlag[setUp.IndexString] = true;
foreach (var child in childrenCandleDataList)
{
itemValue = GetValue(child, setUp);
if (setUp.CandlePriceType == CommonProperty.CandlePriceType.종가)
itemValue = child.LowValue;
if (rateVal > itemValue)
child.CalculateFlag[setUp.IndexString] = true;
}
}
}
}
}
/// <summary>
/// 종가 구매 및 판매
/// </summary>
@@ -1310,7 +1352,7 @@ namespace Million.Manager
/// <param name="subIndicator"></param>
public static void GetCalculateIndicator(List<IndicatorCoditionSetup> totalIndicator, List<string> indiList, List<IndicatorCoditionSetup> lossIndicator,
DateTime startDate, DateTime endDate, List<CandleData> resultCandleDataList, List<IndicatorCoditionSetup> subIndicator,
Dictionary<MCandleTimeType, List<CandleData>> parentList, bool recentlyDataFlag = false, string coinFullName = null)
Dictionary<MCandleTimeType, List<CandleData>> parentList, bool recentlyDataFlag = false, string coinFullName = null, CandleData buyData = null)
{
//최신 Child데이터 계산하기 전에 부모 자식 관계 정리부터 처리
var parentKeys = parentList.Keys;
@@ -1360,7 +1402,7 @@ namespace Million.Manager
list = list.Where(t => t.RecentlyDataFlag).ToList();
}
SwitchFun(totalIndicator, indicator, list, resultCandleDataList, subIndicator, recentlyDataFlag, coinFullName);
SwitchFun(totalIndicator, indicator, list, resultCandleDataList, subIndicator, recentlyDataFlag, coinFullName, buyData);
}
}
}

View File

@@ -89,7 +89,7 @@ namespace Million.Manager
/// <param name="endDate"></param>
/// <returns></returns>
public static Dictionary<MCandleTimeType, List<CandleData>> CalculateIndicator(Dictionary<MCandleTimeType, List<CandleData>> dic,
List<IndicatorCoditionSetup> totalIndicators, DateTime startDate, DateTime endDate,string coinFullName = null, bool recentlyDataFlag = false)
List<IndicatorCoditionSetup> totalIndicators, DateTime startDate, DateTime endDate,string coinFullName = null, bool recentlyDataFlag = false, CandleData buyData = null)
{
dic[MCandleTimeType.M1] = dic[MCandleTimeType.M1].Where(t => startDate <= t.DateTime && t.DateTime < endDate).ToList();
// Sub Indicator string list 반환
@@ -100,7 +100,7 @@ namespace Million.Manager
// 선처리
CalculateManager.GetCalculateIndicator(totalIndicators, subIndStringList, null, startDate,
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName);
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName, buyData);
var totalIndi = totalIndicators.Select(t => t.IndexString).ToList();
@@ -110,7 +110,7 @@ namespace Million.Manager
// 후처리
CalculateManager.GetCalculateIndicator(totalIndicators, totalIndi, null, startDate,
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName);
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName, buyData);
return dic;
}
}