|
@@ -8,7 +8,6 @@ import (
|
|
|
"unsafe"
|
|
|
)
|
|
|
|
|
|
-// 持仓榜单表
|
|
|
type TradePositionTop struct {
|
|
|
Id uint64 `gorm:"column:id;primaryKey"` //`orm:"column(id);pk"`
|
|
|
ClassifyName string //分类名称
|
|
@@ -49,14 +48,12 @@ type TradePositionGuangzhouTop struct {
|
|
|
}
|
|
|
|
|
|
func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
if exchange == "dalian" {
|
|
|
list := make([]*TradePositionDalianTop, 0)
|
|
|
for _, v := range items {
|
|
|
tmp := (*TradePositionDalianTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
} else if exchange == "zhengzhou" {
|
|
@@ -65,7 +62,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
tmp := (*TradePositionZhengzhouTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
} else if exchange == "cffex" {
|
|
@@ -74,7 +70,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
tmp := (*TradePositionCffexTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
} else if exchange == "shanghai" {
|
|
@@ -83,7 +78,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
tmp := (*TradePositionShanghaiTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
} else if exchange == "ine" {
|
|
@@ -92,7 +86,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
tmp := (*TradePositionIneTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
} else if exchange == "guangzhou" {
|
|
@@ -101,7 +94,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
tmp := (*TradePositionGuangzhouTop)(unsafe.Pointer(v))
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- //_, err = o.InsertMulti(len(list), list)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(list, utils.MultiAddNum).Error
|
|
|
return
|
|
|
}
|
|
@@ -110,9 +102,6 @@ func InsertMultiTradePositionTop(exchange string, items []*TradePositionTop) (er
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeDataTime(exchange string, startDate, endDate string) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT * 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"
|
|
|
- //_, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
|
|
|
|
|
|
sql := "SELECT * 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"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Find(&list).Error
|
|
@@ -120,9 +109,6 @@ func GetTradePositionTopByExchangeDataTime(exchange string, startDate, endDate s
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeDataTimeByClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate, classifyNames, classifyTypes).Find(&list).Error
|
|
@@ -130,9 +116,6 @@ func GetTradePositionTopByExchangeDataTimeByClassify(exchange string, startDate,
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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"
|
|
|
- //err = o.Raw(sql, startDate, endDate).QueryRow(&count)
|
|
|
|
|
|
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"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Scan(&count).Error
|
|
@@ -140,9 +123,6 @@ func GetTradePositionTopCountByExchangeDataTime(exchange string, startDate, endD
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeSourceType(exchange string, dataTime string, sourceType int) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT * FROM trade_position_" + exchange + "_top where data_time= ? and source_type = ? ORDER BY classify_name, classify_type, deal_type, deal_value desc"
|
|
|
- //_, err = o.Raw(sql, dataTime, sourceType).QueryRows(&list)
|
|
|
|
|
|
sql := "SELECT * FROM trade_position_" + exchange + "_top where data_time= ? and source_type = ? ORDER BY classify_name, classify_type, deal_type, deal_value desc"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, dataTime, sourceType).Find(&list).Error
|
|
@@ -150,9 +130,6 @@ func GetTradePositionTopByExchangeSourceType(exchange string, dataTime string, s
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeSourceTypeClassify(exchange string, dataTime string, sourceType int, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, dataTime, sourceType, classifyNames, classifyTypes).Find(&list).Error
|
|
@@ -202,20 +179,6 @@ type UpdateChangeVal struct {
|
|
|
}
|
|
|
|
|
|
func MultiUpdatePositionTop(exchange string, updates []UpdateDealValueChange) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //p, err := o.Raw("UPDATE trade_position_" + exchange + "_top SET deal_value=?, deal_change=?, source_type=?, modify_time=? WHERE id = ?").Prepare()
|
|
|
- //if err != nil {
|
|
|
- // return
|
|
|
- //}
|
|
|
- //defer func() {
|
|
|
- // _ = p.Close() // 别忘记关闭 statement
|
|
|
- //}()
|
|
|
- //for _, v := range updates {
|
|
|
- // _, err = p.Exec(v.DealValue, v.DealChange, v.SourceType, v.ModifyTime, v.Id)
|
|
|
- // if err != nil {
|
|
|
- // return
|
|
|
- // }
|
|
|
- //}
|
|
|
|
|
|
sql := `"UPDATE trade_position_" + exchange + "_top SET deal_value=?, deal_change=?, source_type=?, modify_time=? WHERE id = ?"`
|
|
|
for _, v := range updates {
|
|
@@ -229,9 +192,6 @@ func MultiUpdatePositionTop(exchange string, updates []UpdateDealValueChange) (e
|
|
|
}
|
|
|
|
|
|
func DeletePositionTopByDataTime(exchange string, dataTime string, dealType int) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "delete from trade_position_" + exchange + "_top WHERE data_time=? and deal_type=?"
|
|
|
- //_, err = o.Raw(sql, dataTime, dealType).Exec()
|
|
|
|
|
|
sql := "delete from trade_position_" + exchange + "_top WHERE data_time=? and deal_type=?"
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, dataTime, dealType).Error
|
|
@@ -239,9 +199,6 @@ func DeletePositionTopByDataTime(exchange string, dataTime string, dealType int)
|
|
|
}
|
|
|
|
|
|
func DeletePositionTopByDataTimeClassify(exchange string, dataTime string, dealType int, classifyNames, classifyTypes []string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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()
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Exec(sql, dataTime, dealType, classifyNames, classifyTypes).Error
|
|
@@ -249,9 +206,6 @@ func DeletePositionTopByDataTimeClassify(exchange string, dataTime string, dealT
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeDataTimeType(exchange string, dataTime string, dealType int) (list []TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "select * from trade_position_" + exchange + "_top WHERE data_time=? and deal_type=?"
|
|
|
- //_, err = o.Raw(sql, dataTime, dealType).QueryRows(&list)
|
|
|
|
|
|
sql := "select * from trade_position_" + exchange + "_top WHERE data_time=? and deal_type=?"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, dataTime, dealType).Find(&list).Error
|
|
@@ -259,9 +213,6 @@ func GetTradePositionTopByExchangeDataTimeType(exchange string, dataTime string,
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopByExchangeDataTimeTypeClassify(exchange string, dataTime string, dealType int, classifyNames, classifyTypes []string) (list []TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, dataTime, dealType, classifyNames, classifyTypes).Find(&list).Error
|
|
@@ -269,17 +220,6 @@ func GetTradePositionTopByExchangeDataTimeTypeClassify(exchange string, dataTime
|
|
|
}
|
|
|
|
|
|
func MultiInsertTradeBaseDataToTop(exchange string, startDate, endDate string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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 buy_short_name !=' ' and data_time between ? and ?"
|
|
|
- //_, err = o.Raw(sql1, now, now, startDate, endDate).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 sold_short_name !=' ' and data_time between ? and ?"
|
|
|
- //_, err = o.Raw(sql2, now, now, startDate, endDate).Exec()
|
|
|
|
|
|
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) " +
|
|
@@ -295,17 +235,6 @@ func MultiInsertTradeBaseDataToTop(exchange string, startDate, endDate string) (
|
|
|
}
|
|
|
|
|
|
func MultiInsertTradeBaseDataToTopByClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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 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 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()
|
|
|
|
|
|
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)" +
|
|
@@ -320,12 +249,7 @@ func MultiInsertTradeBaseDataToTopByClassify(exchange string, startDate, endDate
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetTradePositionTopOriginDataTimes 获取榜单原始数据日期-正序
|
|
|
func GetTradePositionTopOriginDataTimes(exchange string) (dates []string, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := `SELECT DISTINCT data_time FROM base_from_trade_%s_index ORDER BY data_time ASC`
|
|
|
- //sql = fmt.Sprintf(sql, exchange)
|
|
|
- //_, err = o.Raw(sql).QueryRows(&dates)
|
|
|
|
|
|
sql := `SELECT DISTINCT data_time FROM base_from_trade_%s_index ORDER BY data_time ASC`
|
|
|
sql = fmt.Sprintf(sql, exchange)
|
|
@@ -333,7 +257,6 @@ func GetTradePositionTopOriginDataTimes(exchange string) (dates []string, err er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// BaseFromTradeClassify 交易所分类表
|
|
|
type BaseFromTradeClassify struct {
|
|
|
Id uint64 `gorm:"column:id;primaryKey"` // `orm:"column(id);pk"`
|
|
|
ClassifyName string //分类名称
|
|
@@ -344,33 +267,22 @@ type BaseFromTradeClassify struct {
|
|
|
ModifyTime time.Time //修改时间
|
|
|
}
|
|
|
|
|
|
-// GetAllBaseFromTradeClassify 获取所有的交易所分类列表
|
|
|
func GetAllBaseFromTradeClassify() (list []*BaseFromTradeClassify, err error) {
|
|
|
- //sql := `SELECT * FROM base_from_trade_classify `
|
|
|
- //
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.Raw(sql).QueryRows(&list)
|
|
|
|
|
|
sql := `SELECT * FROM base_from_trade_classify `
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// Update 更新
|
|
|
func (m *BaseFromTradeClassify) Update(cols []string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.Update(m, cols...)
|
|
|
err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// MultiAddBaseFromTradeClassify 批量插入交易所分类
|
|
|
func MultiAddBaseFromTradeClassify(items []*BaseFromTradeClassify) (err error) {
|
|
|
if len(items) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.InsertMulti(len(items), items)
|
|
|
err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error
|
|
|
return
|
|
|
}
|
|
@@ -382,18 +294,7 @@ type TradeClassifyName struct {
|
|
|
ModifyTime time.Time //数据最近的日期
|
|
|
}
|
|
|
|
|
|
-// GetExchangeClassify 获取交易所分类列表
|
|
|
func GetExchangeClassify(exchange string) (list []TradeClassifyName, err error) {
|
|
|
- //tableName := "trade_position_" + exchange + "_top"
|
|
|
- //orderStr := "classify_name DESC, classify_type asc"
|
|
|
- //if exchange == "zhengzhou" {
|
|
|
- // orderStr = "classify_name asc"
|
|
|
- //}
|
|
|
- //sql := `SELECT classify_name, classify_type,MAX(data_time) as data_time,MAX(modify_time) as modify_time FROM ` + tableName + ` GROUP BY classify_name, classify_type `
|
|
|
- //sql += ` ORDER BY ` + orderStr
|
|
|
- //
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.Raw(sql).QueryRows(&list)
|
|
|
|
|
|
tableName := "trade_position_" + exchange + "_top"
|
|
|
orderStr := "classify_name DESC, classify_type asc"
|
|
@@ -407,44 +308,21 @@ func GetExchangeClassify(exchange string) (list []TradeClassifyName, err error)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetTradePositionTopCleanByExchangeDataTime 根据时间查询净多单和净空单的值
|
|
|
func GetTradePositionTopCleanByExchangeDataTime(exchange string, startDate, endDate string) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT * FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? and deal_type in (3,4) ORDER BY classify_name, classify_type, deal_type, data_time, deal_value desc"
|
|
|
- //_, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
|
|
|
|
|
|
sql := "SELECT * FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? and deal_type in (3,4) ORDER BY classify_name, classify_type, deal_type, data_time, deal_value desc"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetTradePositionTopCleanByExchangeDataTimeClassify 根据时间查询净多单和净空单的值
|
|
|
func GetTradePositionTopCleanByExchangeDataTimeClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (list []*TradePositionTop, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate, classifyNames, classifyTypes).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// MultiUpdatePositionTopChangeVal 批量更新榜单里变化量的值
|
|
|
func MultiUpdatePositionTopChangeVal(exchange string, updates []UpdateChangeVal) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //p, err := o.Raw("UPDATE trade_position_" + exchange + "_top SET deal_change=?, modify_time=? WHERE id = ?").Prepare()
|
|
|
- //if err != nil {
|
|
|
- // return
|
|
|
- //}
|
|
|
- //defer func() {
|
|
|
- // _ = p.Close() // 别忘记关闭 statement
|
|
|
- //}()
|
|
|
- //for _, v := range updates {
|
|
|
- // _, err = p.Exec(v.DealChange, v.ModifyTime, v.Id)
|
|
|
- // if err != nil {
|
|
|
- // return
|
|
|
- // }
|
|
|
- //}
|
|
|
|
|
|
sql := `"UPDATE trade_position_" + exchange + "_top SET deal_change=?, modify_time=? WHERE id = ?"`
|
|
|
for _, v := range updates {
|
|
@@ -458,9 +336,6 @@ func MultiUpdatePositionTopChangeVal(exchange string, updates []UpdateChangeVal)
|
|
|
}
|
|
|
|
|
|
func GetTradePositionOriginClassifyCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT COUNT(DISTINCT classify_name, classify_type) FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
|
|
|
- //err = o.Raw(sql, startDate, endDate).QueryRow(&count)
|
|
|
|
|
|
sql := "SELECT COUNT(DISTINCT classify_name, classify_type) FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Scan(&count).Error
|
|
@@ -468,9 +343,6 @@ func GetTradePositionOriginClassifyCountByExchangeDataTime(exchange string, star
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopClassifyCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Scan(&count).Error
|
|
@@ -483,9 +355,6 @@ type TradePositionClassifyInfo struct {
|
|
|
}
|
|
|
|
|
|
func GetTradePositionOriginClassifyByExchangeDataTime(exchange string, startDate, endDate string) (list []TradePositionClassifyInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT DISTINCT classify_name, classify_type FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
|
|
|
- //_, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
|
|
|
|
|
|
sql := "SELECT DISTINCT classify_name, classify_type FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Find(&list).Error
|
|
@@ -493,20 +362,13 @@ func GetTradePositionOriginClassifyByExchangeDataTime(exchange string, startDate
|
|
|
}
|
|
|
|
|
|
func GetTradePositionTopClassifyByExchangeDataTime(exchange string, startDate, endDate string) (list []TradePositionClassifyInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //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)
|
|
|
|
|
|
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 = global.DEFAULT_DmSQL.Raw(sql, startDate, endDate).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// DeleteTradePositionTopAllByExchangeDataTime 删除计算数据
|
|
|
func DeleteTradePositionTopAllByExchangeDataTime(exchange string, startDate, endDate string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "DELETE FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? "
|
|
|
- //_, err = o.Raw(sql, startDate, endDate).Exec()
|
|
|
|
|
|
sql := "DELETE FROM trade_position_" + exchange + "_top where data_time >= ? and data_time <= ? "
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, startDate, endDate).Error
|
|
@@ -518,9 +380,6 @@ type GetFirstBaseFromTradeIndeDate struct {
|
|
|
}
|
|
|
|
|
|
func GetFirstBaseFromTradeIndexByDate(exchange string) (item *GetFirstBaseFromTradeIndeDate, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := "SELECT * FROM base_from_trade_" + exchange + "_index where `rank` < 50 order by data_time asc"
|
|
|
- //err = o.Raw(sql).QueryRow(&item)
|
|
|
|
|
|
sql := "SELECT * FROM base_from_trade_" + exchange + "_index where `rank` < 50 order by data_time asc"
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql).Find(&item).Error
|