quote.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. package quote
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "mtp2_if/mtpcache"
  8. "mtp2_if/utils"
  9. "net/http"
  10. "time"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // QueryQuoteDayReq 获取商品盘面信息请求参数
  14. type QueryQuoteDayReq struct {
  15. GoodsCodes string `form:"goodsCodes"`
  16. }
  17. // QueryQuoteDayRsp 获取商品盘面信息返回模型
  18. type QueryQuoteDayRsp struct {
  19. Exchangedate int64 `json:"exchangedate"` // 交易日
  20. Goodscode string `json:"goodscode"` // 商品代码
  21. Exchangecode int `json:"exchangecode"` // 交易所代码
  22. Preclose float64 `json:"preclose"` // 昨收
  23. Opentime time.Time `json:"opentime"` // 开盘时间
  24. Opened float64 `json:"opened"` // 开盘价
  25. Highest float64 `json:"highest"` // 最高价
  26. Lowest float64 `json:"lowest"` // 最低价
  27. Lasttime string `json:"lasttime"` // 行情时间(只有现价变化行情时间才变化)
  28. Utclasttime time.Time `json:"utclasttime"` // utc的行情时间
  29. Last float64 `json:"last"` // 最新价
  30. Lastvolume int64 `json:"lastvolume"` // 最新成交量
  31. Lastturnover float64 `json:"lastturnover` // 最新成交金额
  32. Totalbidvolume int64 `json:"totalbidvolume"` // 外盘
  33. Totalaskvolume int64 `json:"totalaskvolume"` // 内盘
  34. Totalvolume int64 `json:"totalvolume"` // 总量
  35. Totalturnover float64 `json:"totalturnover"` // 总金额
  36. Bid float64 `json:"bid"` // 买1
  37. Bid2 float64 `json:"bid2"` // 买2
  38. Bid3 float64 `json:"bid3"` // 买3
  39. Bid4 float64 `json:"bid4"` // 买4
  40. Bid5 float64 `json:"bid5"` // 买5
  41. Bidvolume int64 `json:"bidvolume"` // 买量1
  42. Bidvolume2 int64 `json:"bidvolume2"` // 买量2
  43. Bidvolume3 int64 `json:"bidvolume3"` // 买量3
  44. Bidvolume4 int64 `json:"bidvolume4"` // 买量4
  45. Bidvolume5 int64 `json:"bidvolume5"` // 买量5
  46. Ask float64 `json:"ask"` // 卖1
  47. Ask2 float64 `json:"ask2"` // 卖2
  48. Ask3 float64 `json:"ask3"` // 卖3
  49. Ask4 float64 `json:"ask4"` // 卖4
  50. Ask5 float64 `json:"ask5"` // 卖5
  51. Askvolume int64 `json:"askvolume"` // 卖量1
  52. Askvolume2 int64 `json:"askvolume2"` // 卖量2
  53. Askvolume3 int64 `json:"askvolume3"` // 卖量3
  54. Askvolume4 int64 `json:"askvolume4"` // 卖量4
  55. Askvolume5 int64 `json:"askvolume5"` // 卖量5
  56. Presettle float64 `json:"presettle"` // 昨结价
  57. Settle float64 `json:"settle"` // 结算价
  58. Preholdvolume int64 `json:"preholdvolume"` // 昨持仓
  59. Holdvolume int64 `json:"holdvolume"` // 持仓
  60. Averageprice float64 `json:"averageprice"` // 均价
  61. Orderid int64 `json:"orderid"` // 序号
  62. Limitup float64 `json:"limitup"` // 涨停价
  63. Limitdown float64 `json:"limitdown"` // 跌停价
  64. Inventory int64 `json:"inventory"` // 库存
  65. Holdincrement int64 `json:"holdincrement"` // 单笔持仓
  66. Iscleared int `json:"iscleared"` // 是否清盘标志
  67. Issettled int `json:"issettled"` // 是否结算标志
  68. Bidqueueinfo string `json:"bidqueueinfo"` // 大利市买港股用
  69. Askqueueinfo string `json:"askqueueinfo"` // 大利市卖港股用
  70. Bidorderid int64 `json:"bidorderid"` // 买单号1
  71. Bidorderid2 int64 `json:"bidorderid2"` // 买单号2
  72. Bidorderid3 int64 `json:"bidorderid3"` // 买单号3
  73. Bidorderid4 int64 `json:"bidorderid4"` // 买单号4
  74. Bidorderid5 int64 `json:"bidorderid5"` // 买单号5
  75. Askorderid int64 `json:"askorderid"` // 卖单号1
  76. Askorderid2 int64 `json:"askorderid2"` // 卖单号2
  77. Askorderid3 int64 `json:"askorderid3"` // 卖单号3
  78. Askorderid4 int64 `json:"askorderid4"` // 卖单号4
  79. Askorderid5 int64 `json:"askorderid5"` // 卖单号5
  80. Lastlot int64 `json:"lastlot"` // 最新成交手数
  81. Totallot int64 `json:"totallot"` // 总手数
  82. Strikeprice float64 `json:"strikeprice"` // 发行价
  83. Cleartime int64 `json:"cleartime"` // 清盘时间
  84. Calloptionpremiums int64 `json:"calloptionpremiums"` // 认购期权1
  85. Calloptionpremiums2 int64 `json:"calloptionpremiums2"` // 认购期权2
  86. Calloptionpremiums3 int64 `json:"calloptionpremiums3"` // 认购期权3
  87. Calloptionpremiums4 int64 `json:"calloptionpremiums4"` // 认购期权4
  88. Calloptionpremiums5 int64 `json:"calloptionpremiums5"` // 认购期权5
  89. Putoptionpremiums int64 `json:"putoptionpremiums"` // 认沽期权1
  90. Putoptionpremiums2 int64 `json:"putoptionpremiums2"` // 认沽期权2
  91. Putoptionpremiums3 int64 `json:"putoptionpremiums3"` // 认沽期权3
  92. Putoptionpremiums4 int64 `json:"putoptionpremiums4"` // 认沽期权4
  93. Putoptionpremiums5 int64 `json:"putoptionpremiums5"` // 认沽期权5
  94. Nontotalvolume int64 `json:"nontotalvolume"` // 非交易总量
  95. Nontotalholdervolume int64 `json:"nontotalholdervolume"` // 非交易持仓量
  96. Nontotalturnover int64 `json:"nontotalturnover"` // 非交易总金额
  97. Nontotallot int64 `json:"nontotallot"` // 非交易总手数
  98. Publictradetype string `json:"publictradetype"` // 公共交易标志类型 港股专用
  99. Iep float64 `json:"iep"` // 平衡价 港股专用
  100. Iev float64 `json:"iev"` // 平衡量 港股专用
  101. Grepmarketprice float64 `json:"grepmarketprice"` // 暗盘价 港股专用
  102. Bid6 float64 `json:"bid6"` // 买6
  103. Bid7 float64 `json:"bid7"` // 买7
  104. Bid8 float64 `json:"bid8"` // 买8
  105. Bid9 float64 `json:"bid9"` // 买9
  106. Bid10 float64 `json:"bid10"` // 买10
  107. Bidvolume6 int64 `json:"bidvolume6"` // 买量6
  108. Bidvolume7 int64 `json:"bidvolume7"` // 买量7
  109. Bidvolume8 int64 `json:"bidvolume8"` // 买量8
  110. Bidvolume9 int64 `json:"bidvolume9"` // 买量9
  111. Bidvolume10 int64 `json:"bidvolume10"` // 买量10
  112. Ask6 float64 `json:"ask6"` // 卖6
  113. Ask7 float64 `json:"ask7"` // 卖7
  114. Ask8 float64 `json:"ask8"` // 卖8
  115. Ask9 float64 `json:"ask9"` // 卖9
  116. Ask10 float64 `json:"ask10"` // 卖10
  117. Askvolume6 int64 `json:"askvolume6"` // 卖量6
  118. Askvolume7 int64 `json:"askvolume7"` // 卖量7
  119. Askvolume8 int64 `json:"askvolume8"` // 卖量8
  120. Askvolume9 int64 `json:"askvolume9"` // 卖量9
  121. Askvolume10 int64 `json:"askvolume10"` // 卖量10
  122. Bidordervolume int64 `json:"bidordervolume"` // 买单量1
  123. Bidordervolume2 int64 `json:"bidordervolume2"` // 买单量2
  124. Bidordervolume3 int64 `json:"bidordervolume3"` // 买单量3
  125. Bidordervolume4 int64 `json:"bidordervolume4"` // 买单量4
  126. Bidordervolume5 int64 `json:"bidordervolume5"` // 买单量5
  127. Bidordervolume6 int64 `json:"bidordervolume6"` // 买单量6
  128. Bidordervolume7 int64 `json:"bidordervolume7"` // 买单量7
  129. Bidordervolume8 int64 `json:"bidordervolume8"` // 买单量8
  130. Bidordervolume9 int64 `json:"bidordervolume9"` // 买单量9
  131. Bidordervolume10 int64 `json:"bidordervolume10"` // 买单量10
  132. Askordervolume int64 `json:"askordervolume"` // 卖单量1
  133. Askordervolume2 int64 `json:"askordervolume2"` // 卖单量2
  134. Askordervolume3 int64 `json:"askordervolume3"` // 卖单量3
  135. Askordervolume4 int64 `json:"askordervolume4"` // 卖单量4
  136. Askordervolume5 int64 `json:"askordervolume5"` // 卖单量5
  137. Askordervolume6 int64 `json:"askordervolume6"` // 卖单量6
  138. Askordervolume7 int64 `json:"askordervolume7"` // 卖单量7
  139. Askordervolume8 int64 `json:"askordervolume8"` // 卖单量8
  140. Askordervolume9 int64 `json:"askordervolume9"` // 卖单量9
  141. Askordervolume10 int64 `json:"askordervolume10"` // 卖单量10
  142. }
  143. // QueryQuoteDay 获取商品盘面信息
  144. // @Summary 获取商品盘面信息
  145. // @Produce json
  146. // @Security ApiKeyAuth
  147. // @Param goodsCodes query string false "此参数不填则查所有;商品代码列表,格式:CU2102,CU2103,AL2107"
  148. // @Success 200 {object} QueryQuoteDayRsp
  149. // @Failure 500 {object} app.Response
  150. // @Router /Quote/QueryQuoteDay [get]
  151. // @Tags 行情服务
  152. func QueryQuoteDay(c *gin.Context) {
  153. appG := app.Gin{C: c}
  154. // 获取请求参数
  155. var req QueryQuoteDayReq
  156. if err := appG.C.ShouldBindQuery(&req); err != nil {
  157. logger.GetLogger().Errorf("QueryQuoteDay failed: %s", err.Error())
  158. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  159. return
  160. }
  161. rsp := make([]QueryQuoteDayRsp, 0)
  162. quoteDays, err := models.GetQuoteDays(req.GoodsCodes)
  163. if err != nil {
  164. logger.GetLogger().Errorf("QueryQuoteDay failed: %s", err.Error())
  165. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  166. return
  167. }
  168. for _, v := range quoteDays {
  169. // 获取对应的商品信息
  170. goods, bFind := mtpcache.GetGoods(v.Goodscode)
  171. if bFind {
  172. rsp = append(rsp, QueryQuoteDayRsp{
  173. Exchangedate: v.Exchangedate,
  174. Goodscode: v.Goodscode,
  175. Exchangecode: v.Exchangecode,
  176. Preclose: utils.IntToFloat64(int(v.Preclose), int(goods.DECIMALPLACE)),
  177. Opentime: time.Unix(int64(v.Opentime), 0),
  178. Opened: utils.IntToFloat64(int(v.Opened), int(goods.DECIMALPLACE)),
  179. Highest: utils.IntToFloat64(int(v.Highest), int(goods.DECIMALPLACE)),
  180. Lowest: utils.IntToFloat64(int(v.Lowest), int(goods.DECIMALPLACE)),
  181. Lasttime: v.Lasttime,
  182. Utclasttime: time.Unix(int64(v.Utclasttime), 0),
  183. Last: utils.IntToFloat64(int(v.Last), int(goods.DECIMALPLACE)),
  184. Lastvolume: v.Lastvolume,
  185. Lastturnover: utils.IntToFloat64(int(v.Lastturnover), int(goods.DECIMALPLACE)),
  186. Totalbidvolume: v.Totalbidvolume,
  187. Totalaskvolume: v.Totalaskvolume,
  188. Totalvolume: v.Totalvolume,
  189. Totalturnover: utils.IntToFloat64(int(v.Totalturnover), int(goods.DECIMALPLACE)),
  190. Bid: utils.IntToFloat64(int(v.Bid), int(goods.DECIMALPLACE)),
  191. Bid2: utils.IntToFloat64(int(v.Bid2), int(goods.DECIMALPLACE)),
  192. Bid3: utils.IntToFloat64(int(v.Bid3), int(goods.DECIMALPLACE)),
  193. Bid4: utils.IntToFloat64(int(v.Bid4), int(goods.DECIMALPLACE)),
  194. Bid5: utils.IntToFloat64(int(v.Bid5), int(goods.DECIMALPLACE)),
  195. Bidvolume: v.Bidvolume,
  196. Bidvolume2: v.Bidvolume2,
  197. Bidvolume3: v.Bidvolume3,
  198. Bidvolume4: v.Bidvolume4,
  199. Bidvolume5: v.Bidvolume5,
  200. Ask: utils.IntToFloat64(int(v.Ask), int(goods.DECIMALPLACE)),
  201. Ask2: utils.IntToFloat64(int(v.Ask2), int(goods.DECIMALPLACE)),
  202. Ask3: utils.IntToFloat64(int(v.Ask3), int(goods.DECIMALPLACE)),
  203. Ask4: utils.IntToFloat64(int(v.Ask4), int(goods.DECIMALPLACE)),
  204. Ask5: utils.IntToFloat64(int(v.Ask5), int(goods.DECIMALPLACE)),
  205. Askvolume: v.Askvolume,
  206. Askvolume2: v.Askvolume2,
  207. Askvolume3: v.Askvolume3,
  208. Askvolume4: v.Askvolume4,
  209. Askvolume5: v.Askvolume5,
  210. Presettle: utils.IntToFloat64(int(v.Presettle), int(goods.DECIMALPLACE)),
  211. Settle: utils.IntToFloat64(int(v.Settle), int(goods.DECIMALPLACE)),
  212. Preholdvolume: v.Preholdvolume,
  213. Holdvolume: v.Holdvolume,
  214. Averageprice: utils.IntToFloat64(int(v.Averageprice), int(goods.DECIMALPLACE)),
  215. Orderid: v.Orderid,
  216. Limitup: utils.IntToFloat64(int(v.Limitup), int(goods.DECIMALPLACE)),
  217. Limitdown: utils.IntToFloat64(int(v.Limitdown), int(goods.DECIMALPLACE)),
  218. Inventory: v.Inventory,
  219. Holdincrement: v.Holdincrement,
  220. Iscleared: v.Iscleared,
  221. Issettled: v.Issettled,
  222. Bidqueueinfo: v.Bidqueueinfo,
  223. Askqueueinfo: v.Askqueueinfo,
  224. Bidorderid: v.Bidorderid,
  225. Bidorderid2: v.Bidorderid2,
  226. Bidorderid3: v.Bidorderid3,
  227. Bidorderid4: v.Bidorderid4,
  228. Bidorderid5: v.Bidorderid5,
  229. Askorderid: v.Askorderid,
  230. Askorderid2: v.Askorderid2,
  231. Askorderid3: v.Askorderid3,
  232. Askorderid4: v.Askorderid4,
  233. Askorderid5: v.Askorderid5,
  234. Lastlot: v.Lastlot,
  235. Totallot: v.Totallot,
  236. Strikeprice: utils.IntToFloat64(int(v.Strikeprice), int(goods.DECIMALPLACE)),
  237. Cleartime: v.Cleartime,
  238. Calloptionpremiums: v.Calloptionpremiums,
  239. Calloptionpremiums2: v.Calloptionpremiums2,
  240. Calloptionpremiums3: v.Calloptionpremiums3,
  241. Calloptionpremiums4: v.Calloptionpremiums4,
  242. Calloptionpremiums5: v.Calloptionpremiums5,
  243. Putoptionpremiums: v.Putoptionpremiums,
  244. Putoptionpremiums2: v.Putoptionpremiums2,
  245. Putoptionpremiums3: v.Putoptionpremiums3,
  246. Putoptionpremiums4: v.Putoptionpremiums4,
  247. Putoptionpremiums5: v.Putoptionpremiums5,
  248. Nontotalvolume: v.Nontotalvolume,
  249. Nontotalholdervolume: v.Nontotalholdervolume,
  250. Nontotalturnover: v.Nontotalturnover,
  251. Nontotallot: v.Nontotallot,
  252. Publictradetype: v.Publictradetype,
  253. Iep: utils.IntToFloat64(int(v.Iep), int(goods.DECIMALPLACE)),
  254. Iev: utils.IntToFloat64(int(v.Iev), int(goods.DECIMALPLACE)),
  255. Grepmarketprice: utils.IntToFloat64(int(v.Grepmarketprice), int(goods.DECIMALPLACE)),
  256. Bid6: utils.IntToFloat64(int(v.Bid6), int(goods.DECIMALPLACE)),
  257. Bid7: utils.IntToFloat64(int(v.Bid7), int(goods.DECIMALPLACE)),
  258. Bid8: utils.IntToFloat64(int(v.Bid8), int(goods.DECIMALPLACE)),
  259. Bid9: utils.IntToFloat64(int(v.Bid9), int(goods.DECIMALPLACE)),
  260. Bid10: utils.IntToFloat64(int(v.Bid10), int(goods.DECIMALPLACE)),
  261. Bidvolume6: v.Bidvolume6,
  262. Bidvolume7: v.Bidvolume7,
  263. Bidvolume8: v.Bidvolume8,
  264. Bidvolume9: v.Bidvolume9,
  265. Bidvolume10: v.Bidvolume10,
  266. Ask6: utils.IntToFloat64(int(v.Ask6), int(goods.DECIMALPLACE)),
  267. Ask7: utils.IntToFloat64(int(v.Ask7), int(goods.DECIMALPLACE)),
  268. Ask8: utils.IntToFloat64(int(v.Ask8), int(goods.DECIMALPLACE)),
  269. Ask9: utils.IntToFloat64(int(v.Ask9), int(goods.DECIMALPLACE)),
  270. Ask10: utils.IntToFloat64(int(v.Ask10), int(goods.DECIMALPLACE)),
  271. Askvolume6: v.Askvolume6,
  272. Askvolume7: v.Askvolume7,
  273. Askvolume8: v.Askvolume8,
  274. Askvolume9: v.Askvolume9,
  275. Askvolume10: v.Askvolume10,
  276. Bidordervolume: v.Bidordervolume,
  277. Bidordervolume2: v.Bidordervolume2,
  278. Bidordervolume3: v.Bidordervolume3,
  279. Bidordervolume4: v.Bidordervolume4,
  280. Bidordervolume5: v.Bidordervolume5,
  281. Bidordervolume6: v.Bidordervolume6,
  282. Bidordervolume7: v.Bidordervolume7,
  283. Bidordervolume8: v.Bidordervolume8,
  284. Bidordervolume9: v.Bidordervolume9,
  285. Bidordervolume10: v.Bidordervolume10,
  286. Askordervolume: v.Askordervolume,
  287. Askordervolume2: v.Askordervolume2,
  288. Askordervolume3: v.Askordervolume3,
  289. Askordervolume4: v.Askordervolume4,
  290. Askordervolume5: v.Askordervolume5,
  291. Askordervolume6: v.Askordervolume6,
  292. Askordervolume7: v.Askordervolume7,
  293. Askordervolume8: v.Askordervolume8,
  294. Askordervolume9: v.Askordervolume9,
  295. Askordervolume10: v.Askordervolume10,
  296. })
  297. }
  298. }
  299. // 查询成功
  300. logger.GetLogger().Debugln("QueryQuoteDay successed, rows: %v", len(rsp))
  301. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  302. }