trade_analysis.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package trade_analysis
  2. import (
  3. "eta/eta_index_lib/models/trade_analysis"
  4. "eta/eta_index_lib/utils"
  5. "fmt"
  6. "strings"
  7. )
  8. func GetZhengzhouClassifyName(code string) (name string) {
  9. if strings.HasPrefix(code, "PTA") {
  10. name = "PTA"
  11. return
  12. }
  13. if strings.HasPrefix(code, "TA") {
  14. name = "PTA"
  15. return
  16. }
  17. if strings.HasPrefix(code, "ZC") {
  18. name = "动力煤"
  19. return
  20. }
  21. if strings.HasPrefix(code, "WH") {
  22. name = "强麦"
  23. return
  24. }
  25. if strings.HasPrefix(code, "UR") {
  26. name = "尿素"
  27. return
  28. }
  29. if strings.HasPrefix(code, "SR") {
  30. name = "白糖"
  31. return
  32. }
  33. if strings.HasPrefix(code, "SM") {
  34. name = "锰硅"
  35. return
  36. }
  37. if strings.HasPrefix(code, "SF") {
  38. name = "硅铁"
  39. return
  40. }
  41. if strings.HasPrefix(code, "SA") {
  42. name = "纯碱"
  43. return
  44. }
  45. if strings.HasPrefix(code, "RS") {
  46. name = "油菜籽"
  47. return
  48. }
  49. if strings.HasPrefix(code, "RM") {
  50. name = "菜籽粕"
  51. return
  52. }
  53. if strings.HasPrefix(code, "RI") {
  54. name = "早籼稻"
  55. return
  56. }
  57. if strings.HasPrefix(code, "PM") {
  58. name = "普麦"
  59. return
  60. }
  61. if strings.HasPrefix(code, "PK") {
  62. name = "花生"
  63. return
  64. }
  65. if strings.HasPrefix(code, "PF") {
  66. name = "涤纶短纤"
  67. return
  68. }
  69. if strings.HasPrefix(code, "OI") {
  70. name = "菜油"
  71. return
  72. }
  73. if strings.HasPrefix(code, "MA") {
  74. name = "甲醇"
  75. return
  76. }
  77. if strings.HasPrefix(code, "LR") {
  78. name = "晚籼稻"
  79. return
  80. }
  81. if strings.HasPrefix(code, "JR") {
  82. name = "粳稻"
  83. return
  84. }
  85. if strings.HasPrefix(code, "FG") {
  86. name = "玻璃"
  87. return
  88. }
  89. if strings.HasPrefix(code, "CY") {
  90. name = "棉纱"
  91. return
  92. }
  93. if strings.HasPrefix(code, "CJ") {
  94. name = "红枣"
  95. return
  96. }
  97. if strings.HasPrefix(code, "CF") {
  98. name = "棉花"
  99. return
  100. }
  101. if strings.HasPrefix(code, "AP") {
  102. name = "苹果"
  103. return
  104. }
  105. if strings.HasPrefix(code, "PX") {
  106. name = "PX"
  107. return
  108. }
  109. if strings.HasPrefix(code, "SH") {
  110. name = "烧碱"
  111. return
  112. }
  113. if strings.HasPrefix(code, "PR") {
  114. name = "瓶片"
  115. return
  116. }
  117. if name == "" {
  118. utils.FileLog.Info(fmt.Sprintf("郑商所-合约暂未归类: %s", code))
  119. }
  120. return
  121. }
  122. // GetZhengzhouContractsByClassifyNames 郑商所-获取所选品种下的所有合约
  123. func GetZhengzhouContractsByClassifyNames(classifyNames []string) (contracts []string, err error) {
  124. var cond string
  125. var pars []interface{}
  126. classifyOb := new(trade_analysis.BaseFromTradeClassify)
  127. cond += fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().Exchange)
  128. pars = append(pars, trade_analysis.TradeExchangeZhengzhou)
  129. fields := []string{classifyOb.Cols().ClassifyName, classifyOb.Cols().Exchange}
  130. list, e := classifyOb.GetClassifyItemsByCondition(cond, pars, fields, "id ASC")
  131. if e != nil {
  132. err = fmt.Errorf("获取郑商所品种合约失败, %v", e)
  133. return
  134. }
  135. for _, v := range list {
  136. classifyName := GetZhengzhouClassifyName(v.ClassifyName)
  137. if classifyName == "" {
  138. continue
  139. }
  140. if utils.InArrayByStr(classifyNames, classifyName) {
  141. contracts = append(contracts, v.ClassifyName)
  142. }
  143. }
  144. return
  145. }