trade_analysis.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package trade_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. // 上期能源持仓榜单表
  7. type TradePositionTop struct {
  8. Id uint64 `gorm:"primaryKey;column:id" json:"id"`
  9. ClassifyName string `gorm:"column:classify_name" json:"classify_name"` //分类名称
  10. ClassifyType string `gorm:"column:classify_type" json:"classify_type"` //分类名称下的类型
  11. DealShortName string `gorm:"column:deal_short_name" json:"deal_short_name"` //成交量公司简称
  12. DealValue int `gorm:"column:deal_value" json:"deal_value"` //成交量
  13. DealChange int `gorm:"column:deal_change" json:"deal_change"` //成交变化量
  14. DataTime time.Time `gorm:"column:data_time" json:"data_time"` //数据日期
  15. CreateTime time.Time `gorm:"column:create_time" json:"create_time"` //插入时间
  16. ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"` //修改时间
  17. DealType int `gorm:"column:deal_type" json:"deal_type"` //交易类型:1多单,2空单,3净多单,4净空单
  18. SourceType int `gorm:"column:source_type" json:"source_type"` //数据来源,0是原始数据的值,1是由T+1日推算出的值,2是由T日的榜单数据推算出的值
  19. Rank int `gorm:"column:rank" json:"rank"` //排名
  20. }
  21. type TradeClassifyNameList struct {
  22. Exchange string `description:"交易所"`
  23. ExchangeEn string `description:"交易所英文"`
  24. Sort int `description:"排序字段" `
  25. Num int `description:"品种数量"`
  26. DataTime string `description:"最新更新时间"`
  27. CurrDate string `description:"当前日期"`
  28. Items []TradeClassifyNameListItem `description:"子类"`
  29. }
  30. type TradeClassifyNameListSort []TradeClassifyNameList
  31. func (v TradeClassifyNameListSort) Len() int {
  32. return len(v)
  33. }
  34. func (v TradeClassifyNameListSort) Swap(i, j int) {
  35. v[i], v[j] = v[j], v[i]
  36. }
  37. func (v TradeClassifyNameListSort) Less(i, j int) bool {
  38. return v[i].Sort < v[j].Sort
  39. }
  40. type TradeClassifyNameListItemSort []TradeClassifyNameListItem
  41. func (v TradeClassifyNameListItemSort) Len() int {
  42. return len(v)
  43. }
  44. func (v TradeClassifyNameListItemSort) Swap(i, j int) {
  45. v[i], v[j] = v[j], v[i]
  46. }
  47. func (v TradeClassifyNameListItemSort) Less(i, j int) bool {
  48. return v[i].ClassifyName < v[j].ClassifyName
  49. }
  50. type TradeClassifyNameListItem struct {
  51. ClassifyName string `description:"交易分类"`
  52. Items []TradeClassifyNameListItemItem `description:"合约代码"`
  53. }
  54. type TradeClassifyNameListItemItemSort []TradeClassifyNameListItemItem
  55. func (v TradeClassifyNameListItemItemSort) Len() int {
  56. return len(v)
  57. }
  58. func (v TradeClassifyNameListItemItemSort) Swap(i, j int) {
  59. v[i], v[j] = v[j], v[i]
  60. }
  61. func (v TradeClassifyNameListItemItemSort) Less(i, j int) bool {
  62. return v[i].ClassifyType < v[j].ClassifyType
  63. }
  64. type TradeClassifyNameListItemItem struct {
  65. ClassifyType string `description:"分类名称下的类型"`
  66. }
  67. type TradeClassifyName struct {
  68. ClassifyName string //分类名称
  69. ClassifyType string //分类名称下的类型
  70. LatestDate string //分类下最晚日期
  71. }
  72. // GetExchangeClassify 获取交易所分类列表
  73. func GetExchangeClassify(exchange string) (list []TradeClassifyName, err error) {
  74. tableName := "base_from_trade_" + exchange + "_index"
  75. orderStr := "classify_name DESC, classify_type asc"
  76. if exchange == "zhengzhou" {
  77. orderStr = "classify_name asc"
  78. }
  79. sql := "SELECT classify_name, classify_type FROM " + tableName + " WHERE `rank` <=20 and `rank` > 0 GROUP BY classify_name, classify_type "
  80. sql += ` ORDER BY ` + orderStr
  81. err = global.DmSQL["data"].Raw(sql).Scan(&list).Error
  82. return
  83. }
  84. type LastTimeItem struct {
  85. CreateTime time.Time
  86. }
  87. type GetPositionTopReq struct {
  88. Exchange string `json:"exchange" form:"exchange"` //交易所
  89. ClassifyName string `json:"classify_name" form:"classify_name"` //分类名称
  90. ClassifyType string `json:"classify_type" form:"classify_type"` //具体合约名称
  91. DataTime string `json:"data_time" form:"data_time"` //请求日期,如果为空,则返回最新的榜单日期
  92. }
  93. type GetPositionTopResp struct {
  94. BuyList GetPositionTopList `description:"多单列表"`
  95. SoldList GetPositionTopList `description:"空单列表"`
  96. CleanBuyList GetPositionTopList `description:"净多单列表"`
  97. CleanSoldList GetPositionTopList `description:"净空单列表"`
  98. DataTime string `description:"最新日期或者请求日期"`
  99. LastDataTime string `description:"最新日期"`
  100. }
  101. type GetPositionTopList struct {
  102. TotalDealValue int `description:"总计成交量"`
  103. TotalDealChange int `description:"校昨日变化"`
  104. List []GetPositionTopListItem `description:"榜单详情列表"`
  105. }
  106. type GetPositionTopListItem struct {
  107. DealShortName string `description:"成交量公司简称"`
  108. DealValue int `description:"成交量"`
  109. DealChange int `description:"成交变化量"`
  110. Rank int `description:"当前名次"`
  111. Rate string `description:"当前占比"`
  112. BeforeAllRate string `description:"排在前面的成交量总计占比(包含)"`
  113. BeforeAllValue int `description:"排在前面的成交量总计"`
  114. BeforeAllChange int `description:"排在前面的成交量增减总计"`
  115. }
  116. func GetTradePositionTop(exchange string, classifyName, classifyType, dataTime string) (list []TradePositionTop, err error) {
  117. tableName := "trade_position_" + exchange + "_top"
  118. sql := `SELECT * FROM ` + tableName + " WHERE classify_name=? and classify_type=? and data_time=? and `rank` <=20 and `rank` > 0 ORDER BY deal_value desc"
  119. err = global.DmSQL["data"].Raw(sql, classifyName, classifyType, dataTime).Find(&list).Error
  120. return
  121. }