|
|
@@ -1,5 +1,5 @@
|
|
|
import { reactive, computed, toRefs } from 'vue'
|
|
|
-import { timerInterceptor } from '@/utils/timer'
|
|
|
+import { handlePriceColor } from '@/filters'
|
|
|
import { queryErmcpGoods, queryQuoteDay } from '@/services/api/goods'
|
|
|
import { defineStore } from '../store'
|
|
|
import { timerTask } from '@/utils/timer'
|
|
|
@@ -13,142 +13,11 @@ import moment from 'moment'
|
|
|
export const useFuturesStore = defineStore(() => {
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
- quotes: <Partial<Model.QuoteDayRsp>[]>[], // 行情数据
|
|
|
goodsList: <Model.GoodsRsp[]>[], // 商品列表
|
|
|
+ quotes: <Partial<Model.QuoteDayRsp>[]>[], // 行情数据
|
|
|
quoteDayList: <Model.QuoteDayRsp[]>[], // 盘面列表
|
|
|
})
|
|
|
|
|
|
- // 行情列表
|
|
|
- const quoteList = computed(() => {
|
|
|
- return state.goodsList.reduce((res, cur) => {
|
|
|
- const { agreeunit, goodsid, goodscode, goodsname, goodunitid, goodsgroupid, marketid, decimalplace, quoteminunit, trademode, quotegear } = cur
|
|
|
- const quoteDayInfo = state.quoteDayList.find((e) => e.goodscode.toUpperCase() === goodscode.toUpperCase())
|
|
|
- const {
|
|
|
- averageprice = 0,
|
|
|
- last = 0,
|
|
|
- bid = 0,
|
|
|
- bid2 = 0,
|
|
|
- bid3 = 0,
|
|
|
- bid4 = 0,
|
|
|
- bid5 = 0,
|
|
|
- ask = 0,
|
|
|
- ask2 = 0,
|
|
|
- ask3 = 0,
|
|
|
- ask4 = 0,
|
|
|
- ask5 = 0,
|
|
|
- bidvolume = 0,
|
|
|
- bidvolume2 = 0,
|
|
|
- bidvolume3 = 0,
|
|
|
- bidvolume4 = 0,
|
|
|
- bidvolume5 = 0,
|
|
|
- askvolume = 0,
|
|
|
- askvolume2 = 0,
|
|
|
- askvolume3 = 0,
|
|
|
- askvolume4 = 0,
|
|
|
- askvolume5 = 0,
|
|
|
- totalvolume = 0,
|
|
|
- lastvolume = 0,
|
|
|
- holdvolume = 0,
|
|
|
- holdincrement = 0,
|
|
|
- presettle = 0,
|
|
|
- preclose = 0,
|
|
|
- totalturnover = 0,
|
|
|
- opened = 0,
|
|
|
- highest = 0,
|
|
|
- lowest = 0,
|
|
|
- lasttime = '',
|
|
|
- settle = 0,
|
|
|
- limitup = 0,
|
|
|
- limitdown = 0,
|
|
|
- } = quoteDayInfo ?? {}
|
|
|
-
|
|
|
- const rise = last ? last - presettle : 0 // 涨跌额/涨跌: 最新价 - 昨结价
|
|
|
- const change = presettle ? rise / presettle : 0 // 涨跌幅/幅度: (最新价 - 昨结价) / 昨结价
|
|
|
- const amplitude = presettle ? (highest - lowest) / presettle : 0 // 振幅: (最高价 - 最低价 ) / 最新价
|
|
|
-
|
|
|
- // 处理行情价格颜色
|
|
|
- const handleColor = (value: number) => {
|
|
|
- if (value === 0 || value === presettle) {
|
|
|
- return ''
|
|
|
- } else if (value > presettle) {
|
|
|
- return 'g-price-up'
|
|
|
- } else {
|
|
|
- return 'g-price-down'
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const item: Model.Futures = {
|
|
|
- agreeunit,
|
|
|
- averageprice,
|
|
|
- marketid,
|
|
|
- goodsgroupid,
|
|
|
- goodsid,
|
|
|
- goodscode,
|
|
|
- goodsname,
|
|
|
- goodunitid,
|
|
|
- decimalplace,
|
|
|
- last,
|
|
|
- lasttime,
|
|
|
- rise,
|
|
|
- change,
|
|
|
- amplitude,
|
|
|
- bid,
|
|
|
- bid2,
|
|
|
- bid3,
|
|
|
- bid4,
|
|
|
- bid5,
|
|
|
- ask,
|
|
|
- ask2,
|
|
|
- ask3,
|
|
|
- ask4,
|
|
|
- ask5,
|
|
|
- bidvolume,
|
|
|
- bidvolume2,
|
|
|
- bidvolume3,
|
|
|
- bidvolume4,
|
|
|
- bidvolume5,
|
|
|
- askvolume,
|
|
|
- askvolume2,
|
|
|
- askvolume3,
|
|
|
- askvolume4,
|
|
|
- askvolume5,
|
|
|
- totalvolume,
|
|
|
- lastvolume,
|
|
|
- holdvolume,
|
|
|
- holdincrement,
|
|
|
- presettle,
|
|
|
- preclose,
|
|
|
- totalturnover,
|
|
|
- opened,
|
|
|
- highest,
|
|
|
- lowest,
|
|
|
- settle,
|
|
|
- limitup,
|
|
|
- limitdown,
|
|
|
- quoteminunit,
|
|
|
- bidColor: handleColor(bid),
|
|
|
- bid2Color: handleColor(bid2),
|
|
|
- bid3Color: handleColor(bid3),
|
|
|
- bid4Color: handleColor(bid4),
|
|
|
- bid5Color: handleColor(bid5),
|
|
|
- askColor: handleColor(ask),
|
|
|
- ask2Color: handleColor(ask2),
|
|
|
- ask3Color: handleColor(ask3),
|
|
|
- ask4Color: handleColor(ask4),
|
|
|
- ask5Color: handleColor(ask5),
|
|
|
- lastColor: handleColor(last),
|
|
|
- averagepriceColor: handleColor(averageprice),
|
|
|
- openedColor: handleColor(opened),
|
|
|
- highestColor: handleColor(highest),
|
|
|
- lowestColor: handleColor(lowest),
|
|
|
- trademode,
|
|
|
- quotegear,
|
|
|
- }
|
|
|
- res.push(item)
|
|
|
- return res
|
|
|
- }, [] as Model.Futures[])
|
|
|
- })
|
|
|
-
|
|
|
// 获取商品列表
|
|
|
const getGoodsList = async () => {
|
|
|
timerTask.clearTimeout('quoteDay')
|
|
|
@@ -181,37 +50,144 @@ export const useFuturesStore = defineStore(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 通过 goodscode 获取实时行情信息
|
|
|
- const getQuoteInfo = (goodsCode: string) => {
|
|
|
- return computed(() => {
|
|
|
- const quote = state.quotes.find((e) => e.goodscode === goodsCode)
|
|
|
- return {
|
|
|
- ...quote
|
|
|
+ // 商品行情列表
|
|
|
+ const goodsQuoteList = computed(() => {
|
|
|
+ return state.goodsList.reduce((res, cur) => {
|
|
|
+ const quote = state.quotes.find((e) => e.goodscode?.toUpperCase() === cur.goodscode.toUpperCase())
|
|
|
+ const quoteDay = state.quoteDayList.find((e) => e.goodscode.toUpperCase() === cur.goodscode.toUpperCase())
|
|
|
+
|
|
|
+ const goods: Model.GoodsQuote = {
|
|
|
+ goodsid: cur.goodsid,
|
|
|
+ goodscode: cur.goodscode,
|
|
|
+ goodsname: cur.goodsname,
|
|
|
+ goodsgroupid: cur.goodsgroupid,
|
|
|
+ goodunitid: cur.goodunitid,
|
|
|
+ marketid: cur.marketid,
|
|
|
+ trademode: cur.trademode,
|
|
|
+ agreeunit: cur.agreeunit,
|
|
|
+ decimalplace: cur.decimalplace,
|
|
|
+ quoteminunit: cur.quoteminunit,
|
|
|
+ quotegear: cur.quotegear,
|
|
|
+ last: quote?.last ?? quoteDay?.last ?? 0,
|
|
|
+ lasttime: quote?.lasttime ?? quoteDay?.lasttime ?? '',
|
|
|
+ bid: quote?.bid ?? quoteDay?.bid ?? 0,
|
|
|
+ bid2: quote?.bid2 ?? quoteDay?.bid2 ?? 0,
|
|
|
+ bid3: quote?.bid3 ?? quoteDay?.bid3 ?? 0,
|
|
|
+ bid4: quote?.bid4 ?? quoteDay?.bid4 ?? 0,
|
|
|
+ bid5: quote?.bid5 ?? quoteDay?.bid5 ?? 0,
|
|
|
+ bidvolume: quote?.bidvolume ?? quoteDay?.bidvolume ?? 0,
|
|
|
+ bidvolume2: quote?.bidvolume2 ?? quoteDay?.bidvolume2 ?? 0,
|
|
|
+ bidvolume3: quote?.bidvolume3 ?? quoteDay?.bidvolume3 ?? 0,
|
|
|
+ bidvolume4: quote?.bidvolume4 ?? quoteDay?.bidvolume4 ?? 0,
|
|
|
+ bidvolume5: quote?.bidvolume5 ?? quoteDay?.bidvolume5 ?? 0,
|
|
|
+ ask: quote?.ask ?? quoteDay?.ask ?? 0,
|
|
|
+ ask2: quote?.ask2 ?? quoteDay?.ask2 ?? 0,
|
|
|
+ ask3: quote?.ask3 ?? quoteDay?.ask3 ?? 0,
|
|
|
+ ask4: quote?.ask4 ?? quoteDay?.ask4 ?? 0,
|
|
|
+ ask5: quote?.ask5 ?? quoteDay?.ask5 ?? 0,
|
|
|
+ askvolume: quote?.askvolume ?? quoteDay?.askvolume ?? 0,
|
|
|
+ askvolume2: quote?.askvolume2 ?? quoteDay?.askvolume2 ?? 0,
|
|
|
+ askvolume3: quote?.askvolume3 ?? quoteDay?.askvolume3 ?? 0,
|
|
|
+ askvolume4: quote?.askvolume4 ?? quoteDay?.askvolume4 ?? 0,
|
|
|
+ askvolume5: quote?.askvolume5 ?? quoteDay?.askvolume5 ?? 0,
|
|
|
+ lastvolume: quote?.lastvolume ?? quoteDay?.lastvolume ?? 0,
|
|
|
+ presettle: quote?.presettle ?? quoteDay?.presettle ?? 0,
|
|
|
+ opened: quote?.opened ?? quoteDay?.opened ?? 0,
|
|
|
+ highest: quote?.highest ?? quoteDay?.highest ?? 0,
|
|
|
+ lowest: quote?.lowest ?? quoteDay?.lowest ?? 0,
|
|
|
+ limitup: quote?.limitup ?? quoteDay?.limitup ?? 0,
|
|
|
+ limitdown: quote?.limitdown ?? quoteDay?.limitdown ?? 0,
|
|
|
+ averageprice: quote?.averageprice ?? quoteDay?.averageprice ?? 0,
|
|
|
+ rise: 0,
|
|
|
+ change: 0,
|
|
|
+ amplitude: 0,
|
|
|
+ bidColor: '',
|
|
|
+ bid2Color: '',
|
|
|
+ bid3Color: '',
|
|
|
+ bid4Color: '',
|
|
|
+ bid5Color: '',
|
|
|
+ askColor: '',
|
|
|
+ ask2Color: '',
|
|
|
+ ask3Color: '',
|
|
|
+ ask4Color: '',
|
|
|
+ ask5Color: '',
|
|
|
+ lastColor: '',
|
|
|
+ averagepriceColor: '',
|
|
|
+ openedColor: '',
|
|
|
+ highestColor: '',
|
|
|
+ lowestColor: '',
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理最高最低价
|
|
|
+ if (goods.last) {
|
|
|
+ if (goods.last > goods.highest) {
|
|
|
+ goods.highest = goods.last
|
|
|
+ }
|
|
|
+ if (goods.last < goods.lowest) {
|
|
|
+ goods.lowest = goods.last
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
- // 通过 goodscode 获取实时盘面信息
|
|
|
- const getQuoteDayInfo = (code?: string | number) => {
|
|
|
- return computed(() => quoteList.value.find((e) => e.goodscode === code || e.goodsid === code))
|
|
|
+ if (quoteDay) {
|
|
|
+ goods.rise = goods.last ? goods.last - goods.presettle : 0 // 涨跌额/涨跌: 最新价 - 昨结价
|
|
|
+ goods.change = goods.presettle ? goods.rise / goods.presettle : 0 // 涨跌幅/幅度: (最新价 - 昨结价) / 昨结价
|
|
|
+ goods.amplitude = goods.presettle ? (goods.highest - goods.lowest) / goods.presettle : 0 // 振幅: (最高价 - 最低价 ) / 最新价
|
|
|
+
|
|
|
+ // 处理行情价格颜色
|
|
|
+ const handleColor = (value: number) => handlePriceColor(value, goods.presettle)
|
|
|
+
|
|
|
+ goods.bidColor = handleColor(goods.bid)
|
|
|
+ goods.bid2Color = handleColor(goods.bid2)
|
|
|
+ goods.bid3Color = handleColor(goods.bid3)
|
|
|
+ goods.bid4Color = handleColor(goods.bid4)
|
|
|
+ goods.bid5Color = handleColor(goods.bid5)
|
|
|
+ goods.askColor = handleColor(goods.ask)
|
|
|
+ goods.ask2Color = handleColor(goods.ask2)
|
|
|
+ goods.ask3Color = handleColor(goods.ask3)
|
|
|
+ goods.ask4Color = handleColor(goods.ask4)
|
|
|
+ goods.ask5Color = handleColor(goods.ask5)
|
|
|
+ goods.lastColor = handleColor(goods.last)
|
|
|
+ goods.averagepriceColor = handleColor(goods.averageprice)
|
|
|
+ goods.openedColor = handleColor(goods.opened)
|
|
|
+ goods.highestColor = handleColor(goods.highest)
|
|
|
+ goods.lowestColor = handleColor(goods.lowest)
|
|
|
+ }
|
|
|
+ res.push(goods)
|
|
|
+ return res
|
|
|
+ }, [] as Model.GoodsQuote[])
|
|
|
+ })
|
|
|
+
|
|
|
+ // 通过 goodscode 获取实时盘面
|
|
|
+ const getGoodsQuote = (code: string | number) => {
|
|
|
+ return computed(() => goodsQuoteList.value.find((e) => e.goodscode === code || e.goodsid === code))
|
|
|
}
|
|
|
|
|
|
// 通过 goodscode 获取实时行情报价
|
|
|
- const getQuotePrice = (code?: string | number) => {
|
|
|
+ const getQuotePrice = (goodsCode: string) => {
|
|
|
return computed(() => {
|
|
|
- const quote = getQuoteDayInfo(code)
|
|
|
+ const quote = getGoodsQuote(goodsCode)
|
|
|
return quote.value?.last ?? 0
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ // 通过 goodscode 获取实时行情
|
|
|
+ const getQuote = (goodsCode: string) => {
|
|
|
+ return computed(() => {
|
|
|
+ const quote = state.quotes.find((e) => e.goodscode === goodsCode)
|
|
|
+ return {
|
|
|
+ ...quote
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
// 获取商品名称
|
|
|
- const getGoodsName = (code?: string | number) => {
|
|
|
+ const getGoodsName = (code: string | number) => {
|
|
|
const quote = state.goodsList.find((e) => e.goodscode === code || e.goodsid === code)
|
|
|
- return quote?.goodsname
|
|
|
+ return quote?.goodsname ?? ''
|
|
|
}
|
|
|
|
|
|
// 获取商品市场ID
|
|
|
- const getGoodsMarket = (code?: string | number) => {
|
|
|
+ const getGoodsMarket = (code: string | number) => {
|
|
|
const quote = state.goodsList.find((e) => e.goodscode === code || e.goodsid === code)
|
|
|
return quote?.marketid ?? 0
|
|
|
}
|
|
|
@@ -228,7 +204,6 @@ export const useFuturesStore = defineStore(() => {
|
|
|
state.quotes.push(quote)
|
|
|
}
|
|
|
})
|
|
|
- handleQuoteDay()
|
|
|
})
|
|
|
|
|
|
// 处理行情数据
|
|
|
@@ -295,43 +270,13 @@ export const useFuturesStore = defineStore(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 更新盘面数据
|
|
|
- const handleQuoteDay = timerInterceptor.setThrottle(() => {
|
|
|
- state.quotes.forEach((item) => {
|
|
|
- const quoteDay = state.quoteDayList.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
|
|
|
- if (quoteDay) {
|
|
|
- let key: keyof Model.QuoteDayRsp
|
|
|
- // 遍历对象赋值
|
|
|
- for (key in item) {
|
|
|
- const value = item[key]
|
|
|
- if (value !== undefined) {
|
|
|
- (<K extends typeof key>(prop: K, value: Model.QuoteDayRsp[K]) => {
|
|
|
- quoteDay[prop] = value
|
|
|
- })(key, value)
|
|
|
- }
|
|
|
- }
|
|
|
- // 处理最高最低价
|
|
|
- if (quoteDay.last) {
|
|
|
- if (quoteDay.last > quoteDay.highest) {
|
|
|
- quoteDay.highest = quoteDay.last
|
|
|
- }
|
|
|
- if (quoteDay.last < quoteDay.lowest) {
|
|
|
- quoteDay.lowest = quoteDay.last
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.warn('行情推送的商品 ' + item.goodscode + ' 缺少盘面信息')
|
|
|
- }
|
|
|
- })
|
|
|
- }, 100)
|
|
|
-
|
|
|
return {
|
|
|
...toRefs(state),
|
|
|
- quoteList,
|
|
|
- getGoodsList,
|
|
|
- getQuoteDayInfo,
|
|
|
- getQuoteInfo,
|
|
|
+ goodsQuoteList,
|
|
|
+ getQuote,
|
|
|
getQuotePrice,
|
|
|
+ getGoodsList,
|
|
|
+ getGoodsQuote,
|
|
|
getGoodsName,
|
|
|
getGoodsMarket,
|
|
|
quotePushNotify,
|