|
@@ -173,6 +173,7 @@ type OriginTradeData struct {
|
|
|
ValType int `description:"数据类型: 1-多单; 2-空单"`
|
|
|
}
|
|
|
|
|
|
+// GetTradeDataByClassifyAndCompany 根据品种和公司名称获取持仓数据
|
|
|
func GetTradeDataByClassifyAndCompany(exchange, classifyName string, contracts, companies []string) (items []*OriginTradeData, err error) {
|
|
|
if exchange == "" {
|
|
|
err = fmt.Errorf("数据表名称有误")
|
|
@@ -217,6 +218,49 @@ func GetTradeDataByClassifyAndCompany(exchange, classifyName string, contracts,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetTradeZhengzhouDataByClassifyAndCompany 郑商所-根据品种和公司名称获取持仓数据
|
|
|
+func GetTradeZhengzhouDataByClassifyAndCompany(exchange string, contracts, companies []string) (items []*OriginTradeData, err error) {
|
|
|
+ if exchange == "" {
|
|
|
+ err = fmt.Errorf("数据表名称有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(contracts) == 0 || len(companies) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tableName := fmt.Sprintf("base_from_trade_%s_index", exchange)
|
|
|
+ sql := `SELECT
|
|
|
+ rank,
|
|
|
+ buy_short_name AS company_name,
|
|
|
+ buy_value AS val,
|
|
|
+ buy_change AS val_change,
|
|
|
+ classify_name AS classify_type,
|
|
|
+ data_time,
|
|
|
+ 1 AS val_type
|
|
|
+ FROM
|
|
|
+ %s
|
|
|
+ WHERE
|
|
|
+ classify_name IN (%s) AND buy_short_name IN (%s)
|
|
|
+ UNION ALL
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ rank,
|
|
|
+ sold_short_name,
|
|
|
+ sold_value,
|
|
|
+ sold_change,
|
|
|
+ classify_name AS classify_type,
|
|
|
+ data_time,
|
|
|
+ 2 AS val_type
|
|
|
+ FROM
|
|
|
+ %s
|
|
|
+ WHERE
|
|
|
+ classify_name IN (%s) AND sold_short_name IN (%s)
|
|
|
+ )`
|
|
|
+ sql = fmt.Sprintf(sql, tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)), tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)))
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ _, err = o.Raw(sql, contracts, companies, contracts, companies).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// ContractCompanyTradeData [合约-期货公司]持仓数据
|
|
|
type ContractCompanyTradeData struct {
|
|
|
CompanyName string `description:"期货公司名称"`
|
|
@@ -237,6 +281,17 @@ const (
|
|
|
|
|
|
WarehouseDefaultUnit = "手"
|
|
|
WarehouseDefaultFrequency = "日度"
|
|
|
+
|
|
|
+ GuangZhouTopCompanyAliasName = "日成交持仓排名" // 广期所TOP20对应的公司名称
|
|
|
+ GuangZhouSeatNameBuy = "持买单量" // 广期所指标名称中的多单名称
|
|
|
+ GuangZhouSeatNameSold = "持卖单量" // 广期所指标名称中的空单名称
|
|
|
+ GuangZhouTopSeatNameBuy = "持买单量总计" // 广期所指标名称中的TOP20多单名称
|
|
|
+ GuangZhouTopSeatNameSold = "持卖单量总计" // 广期所指标名称中的TOP20空单名称
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ TradeExchangeZhengzhou = "zhengzhou"
|
|
|
+ TradeExchangeGuangzhou = "guangzhou"
|
|
|
)
|
|
|
|
|
|
var WarehouseTypeSuffixNames = map[int]string{
|
|
@@ -245,6 +300,14 @@ var WarehouseTypeSuffixNames = map[int]string{
|
|
|
WarehousePureBuyChartType: "席位净多单",
|
|
|
}
|
|
|
|
|
|
+// GuangzhouSeatNameValType 广期所数据名称对应的席位方向
|
|
|
+var GuangzhouSeatNameValType = map[string]int{
|
|
|
+ GuangZhouSeatNameBuy: 1,
|
|
|
+ GuangZhouSeatNameSold: 2,
|
|
|
+ GuangZhouTopSeatNameBuy: 1,
|
|
|
+ GuangZhouTopSeatNameSold: 2,
|
|
|
+}
|
|
|
+
|
|
|
// ContractCompanyTradeDataList [合约-期货公司]持仓数据详情
|
|
|
type ContractCompanyTradeDataList struct {
|
|
|
Date time.Time `description:"数据日期"`
|
|
@@ -328,3 +391,143 @@ func GetLastTradeDataByClassify(exchange, classifyName string, contracts []strin
|
|
|
_, err = o.Raw(sql, classifyName, contracts, classifyName, contracts, classifyName, contracts, classifyName, contracts).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetLastTradeZhengzhouDataByClassify 郑商所-获取[合约]末位多空单数据
|
|
|
+func GetLastTradeZhengzhouDataByClassify(exchange string, contracts []string) (items []*OriginTradeData, err error) {
|
|
|
+ if exchange == "" {
|
|
|
+ err = fmt.Errorf("数据表名称有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(contracts) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ contractReplacer := utils.GetOrmInReplace(len(contracts))
|
|
|
+
|
|
|
+ tableName := fmt.Sprintf("base_from_trade_%s_index", exchange)
|
|
|
+ sql := `SELECT
|
|
|
+ tpt.rank,
|
|
|
+ tpt.buy_short_name AS company_name,
|
|
|
+ tpt.buy_value AS val,
|
|
|
+ tpt.buy_change AS val_change,
|
|
|
+ tpt.classify_name AS classify_type,
|
|
|
+ tpt.data_time,
|
|
|
+ 1 AS val_type
|
|
|
+ FROM
|
|
|
+ %s tpt
|
|
|
+ JOIN
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ data_time, classify_name, MAX(rank) AS max_rank
|
|
|
+ FROM
|
|
|
+ %s
|
|
|
+ WHERE
|
|
|
+ classify_name IN (%s) AND buy_short_name <> ''
|
|
|
+ GROUP BY
|
|
|
+ data_time,
|
|
|
+ classify_name
|
|
|
+ ) sub
|
|
|
+ ON
|
|
|
+ tpt.data_time = sub.data_time AND tpt.classify_name = sub.classify_name AND tpt.rank = sub.max_rank
|
|
|
+ WHERE
|
|
|
+ tpt.classify_name IN (%s)
|
|
|
+ UNION ALL
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ tpt.rank, tpt.sold_short_name, tpt.sold_value, tpt.sold_change, tpt.classify_name AS classify_type, tpt.data_time, 2 AS val_type
|
|
|
+ FROM
|
|
|
+ %s tpt
|
|
|
+ JOIN
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ data_time, classify_name, MAX(rank) AS max_rank
|
|
|
+ FROM
|
|
|
+ %s
|
|
|
+ WHERE
|
|
|
+ classify_name IN (%s) AND sold_short_name <> ''
|
|
|
+ GROUP BY
|
|
|
+ data_time, classify_name
|
|
|
+ ) sub
|
|
|
+ ON
|
|
|
+ tpt.data_time = sub.data_time AND tpt.classify_name = sub.classify_name AND tpt.rank = sub.max_rank
|
|
|
+ WHERE
|
|
|
+ tpt.classify_name IN (%s)
|
|
|
+ )`
|
|
|
+ sql = fmt.Sprintf(sql, tableName, tableName, contractReplacer, contractReplacer, tableName, tableName, contractReplacer, contractReplacer)
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ _, err = o.Raw(sql, contracts, contracts, contracts, contracts).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type BaseFromTradeGuangzhouIndex struct {
|
|
|
+ BaseFromTradeGuangzhouIndexId int `orm:"column(base_from_trade_guangzhou_index_id);pk"`
|
|
|
+ BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
|
|
|
+ IndexCode string `description:"指标编码"`
|
|
|
+ IndexName string `description:"指标名称"`
|
|
|
+ Frequency string `description:"频率"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ StartDate string `description:"开始日期"`
|
|
|
+ EndDate string `description:"结束日期"`
|
|
|
+ CreateTime time.Time `description:"创建日期"`
|
|
|
+ ModifyTime time.Time `description:"修改日期"`
|
|
|
+}
|
|
|
+
|
|
|
+func GetBaseFromTradeGuangzhouIndexByClassifyId(classifyId int) (list []*BaseFromTradeGuangzhouIndex, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT * FROM base_from_trade_guangzhou_index WHERE base_from_trade_guangzhou_classify_id = ?`
|
|
|
+ _, err = o.Raw(sql, classifyId).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type BaseFromTradeGuangzhouData struct {
|
|
|
+ BaseFromTradeGuangzhouDataId int `orm:"column(base_from_trade_guangzhou_data_id);pk"`
|
|
|
+ BaseFromTradeGuangzhouIndexId int `description:"指标id"`
|
|
|
+ IndexCode string `description:"指标编码"`
|
|
|
+ DataTime time.Time `description:"数据日期"`
|
|
|
+ Value float64 `description:"数据值"`
|
|
|
+ QtySub float64 `description:"增减"`
|
|
|
+ CreateTime time.Time `description:"创建日期"`
|
|
|
+ ModifyTime time.Time `description:"修改日期"`
|
|
|
+}
|
|
|
+
|
|
|
+// GetBaseFromTradeGuangzhouDataByIndexIds 获取指标数据
|
|
|
+func GetBaseFromTradeGuangzhouDataByIndexIds(indexIds []int) (list []*BaseFromTradeGuangzhouData, err error) {
|
|
|
+ if len(indexIds) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM base_from_trade_guangzhou_data WHERE base_from_trade_guangzhou_index_id IN (%s) ORDER BY base_from_trade_guangzhou_index_id`, utils.GetOrmInReplace(len(indexIds)))
|
|
|
+ _, err = o.Raw(sql, indexIds).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetBaseFromTradeGuangzhouMinDataByIndexIds 获取指标中的末位数据
|
|
|
+func GetBaseFromTradeGuangzhouMinDataByIndexIds(indexIds []int) (list []*BaseFromTradeGuangzhouData, err error) {
|
|
|
+ indexLen := len(indexIds)
|
|
|
+ if indexLen == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := fmt.Sprintf(`SELECT
|
|
|
+ t1.data_time,
|
|
|
+ t1.min_value AS value
|
|
|
+ FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ data_time,
|
|
|
+ MIN(value) AS min_value
|
|
|
+ FROM
|
|
|
+ base_from_trade_guangzhou_data
|
|
|
+ WHERE
|
|
|
+ base_from_trade_guangzhou_index_id IN (%s)
|
|
|
+ GROUP BY
|
|
|
+ data_time
|
|
|
+ ) t1
|
|
|
+ JOIN
|
|
|
+ base_from_trade_guangzhou_data t2
|
|
|
+ ON
|
|
|
+ t1.data_time = t2.data_time AND t1.min_value = t2.value AND t2.base_from_trade_guangzhou_index_id IN (%s)
|
|
|
+ GROUP BY
|
|
|
+ t1.data_time`, utils.GetOrmInReplace(indexLen), utils.GetOrmInReplace(indexLen))
|
|
|
+ _, err = o.Raw(sql, indexIds, indexIds).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|