quote.go 18 KB

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