quote.go 18 KB

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