trade_classify.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package trade_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. // BaseFromTradeClassify 交易所分类表
  7. type BaseFromTradeClassify struct {
  8. Id uint64 `orm:"column(id);pk" gorm:"primaryKey" `
  9. ClassifyName string //分类名称
  10. ClassifyType string //分类名称下的类型
  11. Exchange string //交易所
  12. LatestDate time.Time //数据最近的日期
  13. CreateTime time.Time //插入时间
  14. ModifyTime time.Time //修改时间
  15. }
  16. // GetAllBaseFromTradeClassify 获取所有的交易所分类列表
  17. func GetAllBaseFromTradeClassify() (list []*BaseFromTradeClassify, err error) {
  18. sql := `SELECT * FROM base_from_trade_classify `
  19. err = global.DmSQL["data"].Raw(sql).Find(&list).Error
  20. return
  21. }
  22. func GetTradeTopLastDataTime(exchange string, classifyName, classifyType string) (item *BaseFromTradeClassify, err error) {
  23. sql := `SELECT * FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
  24. pars := make([]interface{}, 0)
  25. pars = append(pars, exchange)
  26. if exchange == "zhengzhou" {
  27. pars = append(pars, classifyType)
  28. } else {
  29. pars = append(pars, classifyName)
  30. sql += ` AND classify_type=? `
  31. pars = append(pars, classifyType)
  32. }
  33. sql += ` ORDER BY latest_date desc`
  34. err = global.DmSQL["data"].Raw(sql, pars...).First(&item).Error
  35. return
  36. }
  37. // GetClassifyTypeByClassifyName 根据分类名称获取分类类型
  38. func GetClassifyTypeByClassifyName(exchange, classifyName string) (item *TradeClassifyName, err error) {
  39. sql := `SELECT classify_name, classify_type FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
  40. err = global.DmSQL["data"].Raw(sql, exchange, classifyName).First(&item).Error
  41. return
  42. }