|
@@ -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:"期货公司名称"`
|
|
@@ -348,6 +392,72 @@ func GetLastTradeDataByClassify(exchange, classifyName string, contracts []strin
|
|
|
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"`
|