|
@@ -442,6 +442,12 @@ func DealYesterdayData(exchange, startDate string) (err error) {
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ //T-1日重新生成净多单和净空单的榜单后,需要更新T日净多单和净空单榜单里的变化量
|
|
|
+ err = updateAnalysisCleanTopChangeVal(exchange, startDate, yesterdayStr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -614,24 +620,6 @@ func createAnalysisCleanTop(exchange, startDate, endDate string) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func getYesterdayDate(today string) (yesterday string, err error) {
|
|
|
- i := 1
|
|
|
- tmpTime, err := time.ParseInLocation(utils.FormatDate, today, time.Local)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- tmpTimeDate := tmpTime.AddDate(0, 0, -i)
|
|
|
- weekStr := tmpTimeDate.Weekday().String()
|
|
|
- if weekStr == "Sunday" {
|
|
|
- i += 2
|
|
|
- } else if weekStr == "Saturday" {
|
|
|
- i += 1
|
|
|
- }
|
|
|
- tmpTimeDate = tmpTime.AddDate(0, 0, -i)
|
|
|
- yesterday = tmpTimeDate.Format(utils.FormatDate)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// getPrevTradeDataDate 获取指定日期上一个交易日日期
|
|
|
func getPrevTradeDataDate(date string, dates []string) string {
|
|
|
pre := -1
|
|
@@ -648,3 +636,69 @@ func getPrevTradeDataDate(date string, dates []string) string {
|
|
|
}
|
|
|
return dates[pre]
|
|
|
}
|
|
|
+
|
|
|
+// updateAnalysisCleanTopChangeVal T-1日重新生成净多单和净空单的榜单后,需要更新T日净多单和净空单榜单里的变化量
|
|
|
+func updateAnalysisCleanTopChangeVal(exchange, startDate, yesterday string) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("updateAnalysisCleanTopChangeVal err: " + err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ //查询T日的净多单和净空单榜单列表
|
|
|
+ //查询T-1日的净多单和净空单列表
|
|
|
+ //组装数据,计算T日与T-1日的变更值
|
|
|
+ //更新变更值
|
|
|
+ topList := make([]*data_manage.TradePositionTop, 0) //T日和T+1日列表
|
|
|
+ todayTopList := make([]*data_manage.TradePositionTop, 0) //T日列表
|
|
|
+
|
|
|
+ yesterdayTopListMap := make(map[string]int) //净多单净空单持仓量map
|
|
|
+
|
|
|
+ // 查询T日和T-1日的净多单和净空单列表
|
|
|
+ topList, err = data_manage.GetTradePositionTopCleanByExchangeDataTime(exchange, yesterday, startDate)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(topList) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range topList {
|
|
|
+ if v.DataTime == startDate {
|
|
|
+ todayTopList = append(todayTopList, v)
|
|
|
+ } else if v.DataTime == yesterday {
|
|
|
+ nameStr := v.ClassifyName + "_" + v.ClassifyType + "_" + v.DataTime + "_" + v.DealShortName + "_" + strconv.Itoa(v.DealType)
|
|
|
+ yesterdayTopListMap[nameStr] = v.DealValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(todayTopList) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 根据净多单/净空单数据, 比对上一个交易日的日期计算成交变化量, 并写入
|
|
|
+ now := time.Now()
|
|
|
+ updateList := make([]data_manage.UpdateChangeVal, 0)
|
|
|
+ for _, v := range todayTopList {
|
|
|
+ //T日值-T-1日值
|
|
|
+ yesterdayStr := v.ClassifyName + "_" + v.ClassifyType + "_" + yesterday + "_" + v.DealShortName + "_" + strconv.Itoa(v.DealType)
|
|
|
+ dealChange := 0
|
|
|
+ if c, ok := yesterdayTopListMap[yesterdayStr]; ok {
|
|
|
+ dealChange = v.DealValue - c
|
|
|
+ }
|
|
|
+ if dealChange != v.DealChange {
|
|
|
+ tmp := data_manage.UpdateChangeVal{
|
|
|
+ Id: v.Id,
|
|
|
+ ModifyTime: now,
|
|
|
+ DealChange: dealChange,
|
|
|
+ }
|
|
|
+ updateList = append(updateList, tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(updateList) > 0 {
|
|
|
+ err = data_manage.MultiUpdatePositionTopChangeVal(exchange, updateList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|