123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package trade_analysis
- import (
- "eta/eta_index_lib/models/trade_analysis"
- "eta/eta_index_lib/utils"
- "fmt"
- "strings"
- )
- func GetZhengzhouClassifyName(code string) (name string) {
- if strings.HasPrefix(code, "PTA") {
- name = "PTA"
- return
- }
- if strings.HasPrefix(code, "TA") {
- name = "PTA"
- return
- }
- if strings.HasPrefix(code, "ZC") {
- name = "动力煤"
- return
- }
- if strings.HasPrefix(code, "WH") {
- name = "强麦"
- return
- }
- if strings.HasPrefix(code, "UR") {
- name = "尿素"
- return
- }
- if strings.HasPrefix(code, "SR") {
- name = "白糖"
- return
- }
- if strings.HasPrefix(code, "SM") {
- name = "锰硅"
- return
- }
- if strings.HasPrefix(code, "SF") {
- name = "硅铁"
- return
- }
- if strings.HasPrefix(code, "SA") {
- name = "纯碱"
- return
- }
- if strings.HasPrefix(code, "RS") {
- name = "油菜籽"
- return
- }
- if strings.HasPrefix(code, "RM") {
- name = "菜籽粕"
- return
- }
- if strings.HasPrefix(code, "RI") {
- name = "早籼稻"
- return
- }
- if strings.HasPrefix(code, "PM") {
- name = "普麦"
- return
- }
- if strings.HasPrefix(code, "PK") {
- name = "花生"
- return
- }
- if strings.HasPrefix(code, "PF") {
- name = "涤纶短纤"
- return
- }
- if strings.HasPrefix(code, "OI") {
- name = "菜油"
- return
- }
- if strings.HasPrefix(code, "MA") {
- name = "甲醇"
- return
- }
- if strings.HasPrefix(code, "LR") {
- name = "晚籼稻"
- return
- }
- if strings.HasPrefix(code, "JR") {
- name = "粳稻"
- return
- }
- if strings.HasPrefix(code, "FG") {
- name = "玻璃"
- return
- }
- if strings.HasPrefix(code, "CY") {
- name = "棉纱"
- return
- }
- if strings.HasPrefix(code, "CJ") {
- name = "红枣"
- return
- }
- if strings.HasPrefix(code, "CF") {
- name = "棉花"
- return
- }
- if strings.HasPrefix(code, "AP") {
- name = "苹果"
- return
- }
- if strings.HasPrefix(code, "PX") {
- name = "PX"
- return
- }
- if strings.HasPrefix(code, "SH") {
- name = "烧碱"
- return
- }
- if strings.HasPrefix(code, "PR") {
- name = "瓶片"
- return
- }
- if name == "" {
- utils.FileLog.Info(fmt.Sprintf("郑商所-合约暂未归类: %s", code))
- }
- return
- }
- // GetZhengzhouContractsByClassifyNames 郑商所-获取所选品种下的所有合约
- func GetZhengzhouContractsByClassifyNames(classifyNames []string) (contracts []string, err error) {
- var cond string
- var pars []interface{}
- classifyOb := new(trade_analysis.BaseFromTradeClassify)
- cond += fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().Exchange)
- pars = append(pars, trade_analysis.TradeExchangeZhengzhou)
- fields := []string{classifyOb.Cols().ClassifyName, classifyOb.Cols().Exchange}
- list, e := classifyOb.GetClassifyItemsByCondition(cond, pars, fields, "id ASC")
- if e != nil {
- err = fmt.Errorf("获取郑商所品种合约失败, %v", e)
- return
- }
- for _, v := range list {
- classifyName := GetZhengzhouClassifyName(v.ClassifyName)
- if classifyName == "" {
- continue
- }
- if utils.InArrayByStr(classifyNames, classifyName) {
- contracts = append(contracts, v.ClassifyName)
- }
- }
- return
- }
|