|
@@ -98,6 +98,13 @@ func GetTradePositionTopByExchangeDataTime(exchange string, startDate, endDate s
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func GetTradePositionTopByExchangeDataTimeByClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT * FROM trade_position_` + exchange + `_top where data_time >= ? and data_time <= ? and deal_type in (1,2) and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `) ORDER BY classify_name, classify_type, deal_type, data_time, deal_value desc`
|
|
|
+ _, err = o.Raw(sql, startDate, endDate, classifyNames, classifyTypes).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func GetTradePositionTopCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := "SELECT count(*) FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? and deal_type in (1,2) ORDER BY classify_name, classify_type, deal_type, data_time, deal_value desc"
|
|
@@ -112,6 +119,13 @@ func GetTradePositionTopByExchangeSourceType(exchange string, dataTime string, s
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func GetTradePositionTopByExchangeSourceTypeClassify(exchange string, dataTime string, sourceType int, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT * FROM trade_position_` + exchange + `_top where data_time= ? and source_type = ? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `) ORDER BY classify_name, classify_type, deal_type, deal_value desc`
|
|
|
+ _, err = o.Raw(sql, dataTime, sourceType, classifyNames, classifyTypes).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
type TradeTopClassify struct {
|
|
|
ClassifyName string //分类名称
|
|
|
ClassifyType string //分类名称下的类型
|
|
@@ -179,6 +193,13 @@ func DeletePositionTopByDataTime(exchange string, dataTime string, dealType int)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func DeletePositionTopByDataTimeClassify(exchange string, dataTime string, dealType int, classifyNames, classifyTypes []string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `delete from trade_position_` + exchange + `_top WHERE data_time=? and deal_type=? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
|
|
|
+ _, err = o.Raw(sql, dataTime, dealType, classifyNames, classifyTypes).Exec()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func GetTradePositionTopByExchangeDataTimeType(exchange string, dataTime string, dealType int) (list []TradePositionTop, err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := "select * from trade_position_" + exchange + "_top WHERE data_time=? and deal_type=?"
|
|
@@ -186,6 +207,13 @@ func GetTradePositionTopByExchangeDataTimeType(exchange string, dataTime string,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func GetTradePositionTopByExchangeDataTimeTypeClassify(exchange string, dataTime string, dealType int, classifyNames, classifyTypes []string) (list []TradePositionTop, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `select * from trade_position_` + exchange + `_top WHERE data_time=? and deal_type=? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
|
|
|
+ _, err = o.Raw(sql, dataTime, dealType, classifyNames, classifyTypes).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func MultiInsertTradeBaseDataToTop(exchange string, startDate, endDate string) (err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
now := time.Now().Format(utils.FormatDateTime)
|
|
@@ -201,6 +229,21 @@ SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_t
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func MultiInsertTradeBaseDataToTopByClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ now := time.Now().Format(utils.FormatDateTime)
|
|
|
+ sql1 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
|
|
|
+ SELECT classify_name,classify_type,buy_short_name,buy_value,buy_change,data_time,1,0,rank,?,? FROM base_from_trade_` + exchange + `_index where rank <50 and buy_short_name !="" and data_time between ? and ? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
|
|
|
+ _, err = o.Raw(sql1, now, now, startDate, endDate, classifyNames, classifyTypes).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql2 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
|
|
|
+SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_time,2,0,rank,?,? FROM base_from_trade_` + exchange + `_index where rank <50 and sold_short_name !="" and data_time between ? and ? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
|
|
|
+ _, err = o.Raw(sql2, now, now, startDate, endDate, classifyNames, classifyTypes).Exec()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetTradePositionTopOriginDataTimes 获取榜单原始数据日期-正序
|
|
|
func GetTradePositionTopOriginDataTimes(exchange string) (dates []string, err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
@@ -279,6 +322,14 @@ func GetTradePositionTopCleanByExchangeDataTime(exchange string, startDate, endD
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetTradePositionTopCleanByExchangeDataTimeClassify 根据时间查询净多单和净空单的值
|
|
|
+func GetTradePositionTopCleanByExchangeDataTimeClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT * FROM trade_position_` + exchange + `_top where data_time >= ? and data_time <= ? and deal_type in (3,4) and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `) and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `) ORDER BY classify_name, classify_type, deal_type, data_time, deal_value desc`
|
|
|
+ _, err = o.Raw(sql, startDate, endDate, classifyNames, classifyTypes).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// MultiUpdatePositionTopChangeVal 批量更新榜单里变化量的值
|
|
|
func MultiUpdatePositionTopChangeVal(exchange string, updates []UpdateChangeVal) (err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
@@ -297,3 +348,44 @@ func MultiUpdatePositionTopChangeVal(exchange string, updates []UpdateChangeVal)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func GetTradePositionOriginClassifyCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT COUNT(DISTINCT classify_name, classify_type) FROM base_from_trade_` + exchange + `_index where rank <50 and (buy_short_name !="" || sold_short_name !="" ) and data_time >= ? and data_time <= ?`
|
|
|
+ err = o.Raw(sql, startDate, endDate).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetTradePositionTopClassifyCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := "SELECT COUNT(DISTINCT classify_name, classify_type) FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? and deal_type in (1,2) "
|
|
|
+ err = o.Raw(sql, startDate, endDate).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type TradePositionClassifyInfo struct {
|
|
|
+ ClassifyName string //分类名称
|
|
|
+ ClassifyType string //分类名称下的类型
|
|
|
+}
|
|
|
+
|
|
|
+func GetTradePositionOriginClassifyByExchangeDataTime(exchange string, startDate, endDate string) (list []TradePositionClassifyInfo, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT DISTINCT classify_name, classify_type FROM base_from_trade_` + exchange + `_index where rank <50 and (buy_short_name !="" || sold_short_name !="" ) and data_time >= ? and data_time <= ?`
|
|
|
+ _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetTradePositionTopClassifyByExchangeDataTime(exchange string, startDate, endDate string) (list []TradePositionClassifyInfo, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := "SELECT DISTINCT classify_name, classify_type FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? and deal_type in (1,2) "
|
|
|
+ _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// DeleteTradePositionTopAllByExchangeDataTime 删除计算数据
|
|
|
+func DeleteTradePositionTopAllByExchangeDataTime(exchange string, startDate, endDate string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := "DELETE FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? "
|
|
|
+ _, err = o.Raw(sql, startDate, endDate).Exec()
|
|
|
+ return
|
|
|
+}
|