|
|
@@ -13,7 +13,7 @@ import moment from 'moment'
|
|
|
export const useFuturesStore = defineStore(() => {
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
- quotes: <Proto.Quote[]>[], // 行情数据
|
|
|
+ quotes: <Partial<Model.QuoteDayRsp>[]>[], // 行情数据
|
|
|
goodsList: <Model.GoodsRsp[]>[], // 商品列表
|
|
|
quoteDayList: <Model.QuoteDayRsp[]>[], // 盘面列表
|
|
|
})
|
|
|
@@ -185,11 +185,8 @@ export const useFuturesStore = defineStore(() => {
|
|
|
const getQuoteInfo = (goodsCode: string) => {
|
|
|
return computed(() => {
|
|
|
const quote = state.quotes.find((e) => e.goodscode === goodsCode)
|
|
|
- const lasttime = (quote?.date && quote.time) ? moment(quote.date + quote.time, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss') : ''
|
|
|
-
|
|
|
return {
|
|
|
- ...quote,
|
|
|
- lasttime
|
|
|
+ ...quote
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -219,191 +216,115 @@ export const useFuturesStore = defineStore(() => {
|
|
|
return quote?.marketid ?? 0
|
|
|
}
|
|
|
|
|
|
- // 更新盘面数据
|
|
|
- const updateQuoteDay = timerInterceptor.setThrottle(() => {
|
|
|
- state.quotes.forEach((item) => {
|
|
|
- const goods = state.goodsList.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
|
|
|
- const quote: Model.QuoteDayRsp | undefined = state.quoteDayList.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
|
|
|
- const lasttime = (item.date && item.time) ? moment(item.date + item.time, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss') : ''
|
|
|
-
|
|
|
- // 处理报价小数位
|
|
|
- const handleDeimalplace = (value = 0) => {
|
|
|
- const decimal = goods ? Math.pow(10, goods.decimalplace) : 0
|
|
|
- if (decimal) {
|
|
|
- return value / decimal
|
|
|
- }
|
|
|
- return value
|
|
|
+ // 接收行情推送通知
|
|
|
+ const quotePushNotify = eventBus.$on('QuotePushNotify', (res) => {
|
|
|
+ const data = res as Proto.Quote[]
|
|
|
+ data.forEach((item) => {
|
|
|
+ const quote = handleQuote(item)
|
|
|
+ const index = state.quotes.findIndex((e) => e.goodscode === item.goodscode)
|
|
|
+ if (index > -1) {
|
|
|
+ state.quotes[index] = quote
|
|
|
+ } else {
|
|
|
+ state.quotes.push(quote)
|
|
|
}
|
|
|
+ })
|
|
|
+ handleQuoteDay()
|
|
|
+ })
|
|
|
|
|
|
- const quoteItem: Model.QuoteDayRsp = {
|
|
|
- ask: handleDeimalplace(item.ask),
|
|
|
- ask2: handleDeimalplace(item.ask2),
|
|
|
- ask3: handleDeimalplace(item.ask3),
|
|
|
- ask4: handleDeimalplace(item.ask4),
|
|
|
- ask5: handleDeimalplace(item.ask5),
|
|
|
- ask6: 0,
|
|
|
- ask7: 0,
|
|
|
- ask8: 0,
|
|
|
- ask9: 0,
|
|
|
- ask10: 0,
|
|
|
- askorderid: 0,
|
|
|
- askorderid2: 0,
|
|
|
- askorderid3: 0,
|
|
|
- askorderid4: 0,
|
|
|
- askorderid5: 0,
|
|
|
- askordervolume: 0,
|
|
|
- askordervolume2: 0,
|
|
|
- askordervolume3: 0,
|
|
|
- askordervolume4: 0,
|
|
|
- askordervolume5: 0,
|
|
|
- askordervolume6: 0,
|
|
|
- askordervolume7: 0,
|
|
|
- askordervolume8: 0,
|
|
|
- askordervolume9: 0,
|
|
|
- askordervolume10: 0,
|
|
|
- askqueueinfo: '',
|
|
|
- askvolume: item.askvolume ?? 0,
|
|
|
- askvolume2: item.askvolume2 ?? 0,
|
|
|
- askvolume3: item.askvolume3 ?? 0,
|
|
|
- askvolume4: item.askvolume4 ?? 0,
|
|
|
- askvolume5: item.askvolume5 ?? 0,
|
|
|
- askvolume6: 0,
|
|
|
- askvolume7: 0,
|
|
|
- askvolume8: 0,
|
|
|
- askvolume9: 0,
|
|
|
- askvolume10: 0,
|
|
|
- averageprice: 0,
|
|
|
- bid: handleDeimalplace(item.bid),
|
|
|
- bid2: handleDeimalplace(item.bid2),
|
|
|
- bid3: handleDeimalplace(item.bid3),
|
|
|
- bid4: handleDeimalplace(item.bid4),
|
|
|
- bid5: handleDeimalplace(item.bid5),
|
|
|
- bid6: 0,
|
|
|
- bid7: 0,
|
|
|
- bid8: 0,
|
|
|
- bid9: 0,
|
|
|
- bid10: 0,
|
|
|
- bidorderid: 0,
|
|
|
- bidorderid2: 0,
|
|
|
- bidorderid3: 0,
|
|
|
- bidorderid4: 0,
|
|
|
- bidorderid5: 0,
|
|
|
- bidordervolume: 0,
|
|
|
- bidordervolume2: 0,
|
|
|
- bidordervolume3: 0,
|
|
|
- bidordervolume4: 0,
|
|
|
- bidordervolume5: 0,
|
|
|
- bidordervolume6: 0,
|
|
|
- bidordervolume7: 0,
|
|
|
- bidordervolume8: 0,
|
|
|
- bidordervolume9: 0,
|
|
|
- bidordervolume10: 0,
|
|
|
- bidqueueinfo: "",
|
|
|
- bidvolume: item.bidvolume ?? 0,
|
|
|
- bidvolume2: item.bidvolume2 ?? 0,
|
|
|
- bidvolume3: item.bidvolume3 ?? 0,
|
|
|
- bidvolume4: item.bidvolume4 ?? 0,
|
|
|
- bidvolume5: item.bidvolume5 ?? 0,
|
|
|
- bidvolume6: 0,
|
|
|
- bidvolume7: 0,
|
|
|
- bidvolume8: 0,
|
|
|
- bidvolume9: 0,
|
|
|
- bidvolume10: 0,
|
|
|
- calloptionpremiums: item.calloptionpremiums ?? 0,
|
|
|
- calloptionpremiums2: item.calloptionpremiums2 ?? 0,
|
|
|
- calloptionpremiums3: item.calloptionpremiums3 ?? 0,
|
|
|
- calloptionpremiums4: item.calloptionpremiums4 ?? 0,
|
|
|
- calloptionpremiums5: item.calloptionpremiums5 ?? 0,
|
|
|
- cleartime: 0,
|
|
|
- exchangecode: item.exchangecode ?? 0,
|
|
|
- exchangedate: item.exchangedate ?? 0,
|
|
|
- goodscode: item.goodscode ?? '',
|
|
|
- grepmarketprice: 0,
|
|
|
- highest: handleDeimalplace(item.highest),
|
|
|
- holdincrement: 0,
|
|
|
- holdvolume: item.holdvolume ?? 0,
|
|
|
- iep: 0,
|
|
|
- iev: 0,
|
|
|
- inventory: item.inventory ?? 0,
|
|
|
- iscleared: 0,
|
|
|
- issettled: 0,
|
|
|
- last: handleDeimalplace(item.last),
|
|
|
- lastlot: 0,
|
|
|
- lasttime,
|
|
|
- Lastturnover: 0,
|
|
|
- lastvolume: item.lastvolume ?? 0,
|
|
|
- limitdown: handleDeimalplace(item.limitlow),
|
|
|
- limitup: handleDeimalplace(item.limithigh),
|
|
|
- lowest: handleDeimalplace(item.lowest),
|
|
|
- nontotalholdervolume: 0,
|
|
|
- nontotallot: 0,
|
|
|
- nontotalturnover: 0,
|
|
|
- nontotalvolume: 0,
|
|
|
- opened: handleDeimalplace(item.opened),
|
|
|
- opentime: '',
|
|
|
- orderid: 0,
|
|
|
- preclose: handleDeimalplace(item.preclose),
|
|
|
- preholdvolume: item.preholdvolume ?? 0,
|
|
|
- presettle: handleDeimalplace(item.presettle),
|
|
|
- publictradetype: '',
|
|
|
- putoptionpremiums: handleDeimalplace(item.putoptionpremiums),
|
|
|
- putoptionpremiums2: handleDeimalplace(item.putoptionpremiums2),
|
|
|
- putoptionpremiums3: handleDeimalplace(item.putoptionpremiums3),
|
|
|
- putoptionpremiums4: handleDeimalplace(item.putoptionpremiums4),
|
|
|
- putoptionpremiums5: handleDeimalplace(item.putoptionpremiums5),
|
|
|
- settle: handleDeimalplace(item.settle),
|
|
|
- strikeprice: 0,
|
|
|
- totalaskvolume: 0,
|
|
|
- totalbidvolume: 0,
|
|
|
- totallot: 0,
|
|
|
- totalturnover: handleDeimalplace(item.totalturnover),
|
|
|
- totalvolume: item.totalvolume ?? 0,
|
|
|
- utclasttime: ''
|
|
|
+ // 处理行情数据
|
|
|
+ const handleQuote = (quote: Proto.Quote) => {
|
|
|
+ const goods = state.goodsList.find((e) => e.goodscode.toUpperCase() === quote.goodscode?.toUpperCase())
|
|
|
+ // 处理报价小数位
|
|
|
+ const handleDeimalplace = (value?: number) => {
|
|
|
+ if (goods && value) {
|
|
|
+ const decimal = Math.pow(10, goods.decimalplace)
|
|
|
+ return value / decimal
|
|
|
}
|
|
|
+ return value
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ last: handleDeimalplace(quote.last),
|
|
|
+ lasttime: (quote.date && quote.time) ? moment(quote.date + quote.time, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss') : undefined,
|
|
|
+ ask: handleDeimalplace(quote.ask),
|
|
|
+ ask2: handleDeimalplace(quote.ask2),
|
|
|
+ ask3: handleDeimalplace(quote.ask3),
|
|
|
+ ask4: handleDeimalplace(quote.ask4),
|
|
|
+ ask5: handleDeimalplace(quote.ask5),
|
|
|
+ askvolume: quote.askvolume,
|
|
|
+ askvolume2: quote.askvolume2,
|
|
|
+ askvolume3: quote.askvolume3,
|
|
|
+ askvolume4: quote.askvolume4,
|
|
|
+ askvolume5: quote.askvolume5,
|
|
|
+ bid: handleDeimalplace(quote.bid),
|
|
|
+ bid2: handleDeimalplace(quote.bid2),
|
|
|
+ bid3: handleDeimalplace(quote.bid3),
|
|
|
+ bid4: handleDeimalplace(quote.bid4),
|
|
|
+ bid5: handleDeimalplace(quote.bid5),
|
|
|
+ bidvolume: quote.bidvolume,
|
|
|
+ bidvolume2: quote.bidvolume2,
|
|
|
+ bidvolume3: quote.bidvolume3,
|
|
|
+ bidvolume4: quote.bidvolume4,
|
|
|
+ bidvolume5: quote.bidvolume5,
|
|
|
+ calloptionpremiums: quote.calloptionpremiums,
|
|
|
+ calloptionpremiums2: quote.calloptionpremiums2,
|
|
|
+ calloptionpremiums3: quote.calloptionpremiums3,
|
|
|
+ calloptionpremiums4: quote.calloptionpremiums4,
|
|
|
+ calloptionpremiums5: quote.calloptionpremiums5,
|
|
|
+ exchangecode: quote.exchangecode,
|
|
|
+ exchangedate: quote.exchangedate,
|
|
|
+ goodscode: quote.goodscode,
|
|
|
+ highest: handleDeimalplace(quote.highest),
|
|
|
+ holdvolume: quote.holdvolume,
|
|
|
+ inventory: quote.inventory,
|
|
|
+ lastvolume: quote.lastvolume,
|
|
|
+ limitdown: handleDeimalplace(quote.limitlow),
|
|
|
+ limitup: handleDeimalplace(quote.limithigh),
|
|
|
+ lowest: handleDeimalplace(quote.lowest),
|
|
|
+ opened: handleDeimalplace(quote.opened),
|
|
|
+ preclose: handleDeimalplace(quote.preclose),
|
|
|
+ preholdvolume: quote.preholdvolume,
|
|
|
+ presettle: handleDeimalplace(quote.presettle),
|
|
|
+ putoptionpremiums: handleDeimalplace(quote.putoptionpremiums),
|
|
|
+ putoptionpremiums2: handleDeimalplace(quote.putoptionpremiums2),
|
|
|
+ putoptionpremiums3: handleDeimalplace(quote.putoptionpremiums3),
|
|
|
+ putoptionpremiums4: handleDeimalplace(quote.putoptionpremiums4),
|
|
|
+ putoptionpremiums5: handleDeimalplace(quote.putoptionpremiums5),
|
|
|
+ settle: handleDeimalplace(quote.settle),
|
|
|
+ totalturnover: handleDeimalplace(quote.totalturnover),
|
|
|
+ totalvolume: quote.totalvolume,
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (quote) {
|
|
|
- Object.keys(item).forEach((key) => {
|
|
|
- // 只更新存在的属性
|
|
|
- if (Reflect.has(quote, key)) {
|
|
|
- (<K extends keyof Model.QuoteDayRsp>(prop: K) => {
|
|
|
- quote[prop] = quoteItem[prop]
|
|
|
- })(key as keyof Model.QuoteDayRsp)
|
|
|
+ // 更新盘面数据
|
|
|
+ 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 (quote.last) {
|
|
|
- if (quote.last > quote.highest) {
|
|
|
- quote.highest = quote.last
|
|
|
+ if (quoteDay.last) {
|
|
|
+ if (quoteDay.last > quoteDay.highest) {
|
|
|
+ quoteDay.highest = quoteDay.last
|
|
|
}
|
|
|
- if (quote.last < quote.lowest) {
|
|
|
- quote.lowest = quote.last
|
|
|
+ if (quoteDay.last < quoteDay.lowest) {
|
|
|
+ quoteDay.lowest = quoteDay.last
|
|
|
}
|
|
|
}
|
|
|
- // 处理最新时间
|
|
|
- if (lasttime) {
|
|
|
- quote.lasttime = lasttime
|
|
|
- }
|
|
|
} else {
|
|
|
console.warn('行情推送的商品 ' + item.goodscode + ' 缺少盘面信息')
|
|
|
- state.quoteDayList.push(quoteItem)
|
|
|
}
|
|
|
})
|
|
|
}, 100)
|
|
|
|
|
|
- // 接收行情推送通知
|
|
|
- const quotePushNotify = eventBus.$on('QuotePushNotify', (res) => {
|
|
|
- const data = res as Proto.Quote[]
|
|
|
- data.forEach((item) => {
|
|
|
- const index = state.quotes.findIndex((e) => e.goodscode === item.goodscode)
|
|
|
- if (index > -1) {
|
|
|
- state.quotes[index] = item
|
|
|
- } else {
|
|
|
- state.quotes.push(item)
|
|
|
- }
|
|
|
- })
|
|
|
- updateQuoteDay()
|
|
|
- })
|
|
|
-
|
|
|
return {
|
|
|
...toRefs(state),
|
|
|
quoteList,
|