trade_guangzhou.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type TradeGuangZhou struct {
  7. Code string `json:"code"`
  8. Msg string `json:"msg"`
  9. Param struct {
  10. TradeDate []string `json:"trade_date"`
  11. TradeType []string `json:"trade_type"`
  12. } `json:"param"`
  13. Data []struct {
  14. Variety string `json:"variety"`
  15. DiffI int `json:"diffI"`
  16. High int `json:"high"`
  17. Turnover float64 `json:"turnover"`
  18. ImpliedVolatility interface{} `json:"impliedVolatility"`
  19. Diff int `json:"diff"`
  20. Delta interface{} `json:"delta"`
  21. Close int `json:"close"`
  22. Diff1 int `json:"diff1"`
  23. LastClear int `json:"lastClear"`
  24. Open int `json:"open"`
  25. MatchQtySum int `json:"matchQtySum"`
  26. DelivMonth string `json:"delivMonth"`
  27. Low int `json:"low"`
  28. ClearPrice int `json:"clearPrice"`
  29. VarietyOrder string `json:"varietyOrder"`
  30. OpenInterest int `json:"openInterest"`
  31. Volumn int `json:"volumn"`
  32. } `json:"data"`
  33. Time int64 `json:"time"`
  34. }
  35. type BaseFromTradeGuangzhouClassify struct {
  36. BaseFromTradeGuangzhouClassifyId int `orm:"column(base_from_trade_guangzhou_classify_id);pk"`
  37. ClassifyName string `description:"分类名称"`
  38. ClassifyCode string `description:"分类编码"`
  39. ParentId int `description:"分类父级id"`
  40. ModifyTime time.Time `description:"修改时间"`
  41. CreateTime time.Time `description:"创建时间"`
  42. }
  43. type BaseFromTradeGuangzhouIndex struct {
  44. BaseFromTradeGuangzhouIndexId int `orm:"column(base_from_trade_guangzhou_index_id);pk"`
  45. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  46. BaseFromTradeGuangzhouContractId int `description:"合约id"`
  47. IndexCode string `description:"指标编码"`
  48. IndexName string `description:"指标名称"`
  49. Frequency string `description:"频率"`
  50. Unit string `description:"单位"`
  51. StartDate string `description:"开始日期"`
  52. EndDate string `description:"结束日期"`
  53. CreateTime time.Time `description:"创建日期"`
  54. ModifyTime time.Time `description:"修改日期"`
  55. Value float64 `description:"数据值"`
  56. }
  57. type BaseFromTradeGuangzhouData struct {
  58. BaseFromTradeGuangzhouDataId int `orm:"column(base_from_trade_guangzhou_data_id);pk"`
  59. BaseFromTradeGuangzhouIndexId int `description:"指标id"`
  60. IndexCode string `description:"指标编码"`
  61. DataTime string `description:"数据日期"`
  62. Value float64 `description:"数据值"`
  63. QtySub float64 `description:"增减"`
  64. CreateTime time.Time `description:"创建日期"`
  65. ModifyTime time.Time `description:"修改日期"`
  66. }
  67. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouClassifyAll(parentId int) (list []*BaseFromTradeGuangzhouClassify, err error) {
  68. o := orm.NewOrmUsingDB("data")
  69. sql := `SELECT * FROM base_from_trade_guangzhou_classify WHERE parent_id=? `
  70. _, err = o.Raw(sql, parentId).QueryRows(&list)
  71. return list, err
  72. }
  73. func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouIndex() (lastId int64, err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. lastId, err = o.Insert(obj)
  76. return
  77. }
  78. func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouClassify(classifyItem *BaseFromTradeGuangzhouClassify) (lastId int64, err error) {
  79. o := orm.NewOrmUsingDB("data")
  80. lastId, err = o.Insert(classifyItem)
  81. return
  82. }
  83. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndexAll() (list []*BaseFromTradeGuangzhouIndex, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT * FROM base_from_trade_guangzhou_index `
  86. _, err = o.Raw(sql).QueryRows(&list)
  87. return list, err
  88. }
  89. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouDataByDate(date string) (list []*BaseFromTradeGuangzhouData, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := ` SELECT * FROM base_from_trade_guangzhou_data WHERE data_time=? `
  92. _, err = o.Raw(sql, date).QueryRows(&list)
  93. return list, err
  94. }
  95. func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouData(dataList []*BaseFromTradeGuangzhouData) (err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. _, err = o.InsertMulti(len(dataList), &dataList)
  98. return
  99. }
  100. // 修改
  101. func (obj *BaseFromTradeGuangzhouIndex) UpdateGuangzhouData(updateParams, whereParam map[string]interface{}) (err error) {
  102. to := orm.NewOrmUsingDB("data")
  103. ptrStructOrTableName := "base_from_trade_guangzhou_data"
  104. qs := to.QueryTable(ptrStructOrTableName)
  105. for expr, exprV := range whereParam {
  106. qs = qs.Filter(expr, exprV)
  107. }
  108. _, err = qs.Update(updateParams)
  109. return
  110. }
  111. // 修改
  112. func (obj *BaseFromTradeGuangzhouIndex) UpdateGuangzhouIndex(updateParams, whereParam map[string]interface{}) (err error) {
  113. to := orm.NewOrmUsingDB("data")
  114. ptrStructOrTableName := "base_from_trade_guangzhou_index"
  115. qs := to.QueryTable(ptrStructOrTableName)
  116. for expr, exprV := range whereParam {
  117. qs = qs.Filter(expr, exprV)
  118. }
  119. _, err = qs.Update(updateParams)
  120. return
  121. }
  122. // 合约
  123. type GuangzhouContract struct {
  124. Code string `json:"code"`
  125. Msg string `json:"msg"`
  126. Param struct {
  127. Variety []string `json:"variety"`
  128. TradeDate []string `json:"trade_date"`
  129. } `json:"param"`
  130. Data []string `json:"data"`
  131. Time int64 `json:"time"`
  132. }
  133. type BaseFromTradeGuangzhouContract struct {
  134. BaseFromTradeGuangzhouContractId int `orm:"column(base_from_trade_guangzhou_contract_id);pk"`
  135. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  136. ClassifyCode string `description:"分类编码"`
  137. Contract string `description:"合约编码"`
  138. TradeDate string `description:"合约日期"`
  139. }
  140. // 新增合约
  141. func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouContract(item *BaseFromTradeGuangzhouContract) (err error) {
  142. o := orm.NewOrmUsingDB("data")
  143. _, err = o.Insert(item)
  144. return
  145. }
  146. // 获取所有合约
  147. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouContract(tradeDate string) (list []*BaseFromTradeGuangzhouContract, err error) {
  148. o := orm.NewOrmUsingDB("data")
  149. if tradeDate != "" {
  150. sql := ` SELECT * FROM base_from_trade_guangzhou_contract WHERE trade_date=? `
  151. _, err = o.Raw(sql, tradeDate).QueryRows(&list)
  152. return
  153. } else {
  154. sql := ` SELECT * FROM base_from_trade_guangzhou_contract `
  155. _, err = o.Raw(sql).QueryRows(&list)
  156. return
  157. }
  158. }
  159. // 广州交易所期货-日成交持仓排名
  160. type GuangzhouDealPosiQuotes struct {
  161. Code string `json:"code"`
  162. Msg string `json:"msg"`
  163. Param struct {
  164. TradeDate []string `json:"trade_date"`
  165. TradeType []string `json:"trade_type"`
  166. Variety []string `json:"variety"`
  167. ContractId []string `json:"contract_id"`
  168. DataType []string `json:"data_type"`
  169. } `json:"param"`
  170. Data []struct {
  171. ContractId string `json:"contractId"`
  172. MemberId string `json:"memberId"`
  173. Abbr string `json:"abbr"`
  174. TodayQty int `json:"todayQty"`
  175. QtySub int `json:"qtySub"`
  176. CpFlag interface{} `json:"cpFlag"`
  177. } `json:"data"`
  178. Time int64 `json:"time"`
  179. }
  180. type GuangzhouWbillQty struct {
  181. Code string `json:"code"`
  182. Msg string `json:"msg"`
  183. Param struct {
  184. GenDate []string `json:"gen_date"`
  185. Variety []string `json:"variety"`
  186. } `json:"param"`
  187. Data []struct {
  188. VarietyOrder string `json:"varietyOrder"`
  189. GroupCodeOrder *string `json:"groupCodeOrder"`
  190. WhCodeOrder string `json:"whCodeOrder"`
  191. WhType string `json:"whType"`
  192. Variety string `json:"variety"`
  193. GenDate string `json:"genDate"`
  194. WhAbbr string `json:"whAbbr"`
  195. LastWbillQty int `json:"lastWbillQty"`
  196. RegWbillQty int `json:"regWbillQty"`
  197. LogoutWbillQty int `json:"logoutWbillQty"`
  198. WbillQty int `json:"wbillQty"`
  199. Diff int `json:"diff"`
  200. } `json:"data"`
  201. Time int64 `json:"time"`
  202. }
  203. type GuangzhouCongregateDeliveryQuotes struct {
  204. Code string `json:"code"`
  205. Msg string `json:"msg"`
  206. Param struct {
  207. ContractMonth []string `json:"contract_month"`
  208. } `json:"param"`
  209. Data []struct {
  210. VarietyId string `json:"varietyId"`
  211. VarietyName string `json:"varietyName"`
  212. ContractId string `json:"contractId"`
  213. WhName string `json:"whName"`
  214. WbillNum int `json:"wbillNum"`
  215. } `json:"data"`
  216. Time int64 `json:"time"`
  217. }
  218. type GuangzhouDataMinAndMaxDate struct {
  219. BaseFromTradeGuangzhouIndexId int `description:"指标id"`
  220. StartDate string `description:"开始日期"`
  221. EndDate string `description:"结束日期"`
  222. }
  223. // 获取所有合约
  224. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouDataMinAndMaxDate() (list []*GuangzhouDataMinAndMaxDate, err error) {
  225. o := orm.NewOrmUsingDB("data")
  226. sql := ` SELECT a.base_from_trade_guangzhou_index_id,MIN(a.data_time) AS start_date,MAX(a.data_time) AS end_date
  227. FROM base_from_trade_guangzhou_data AS a
  228. GROUP BY a.base_from_trade_guangzhou_index_id `
  229. _, err = o.Raw(sql).QueryRows(&list)
  230. return
  231. }