|
|
@@ -1,6 +1,5 @@
|
|
|
-import { reactive, toRefs, shallowRef } from 'vue'
|
|
|
+import { reactive, shallowRef, toRefs } from 'vue'
|
|
|
import { queryTSData } from '@/services/api/quote'
|
|
|
-import { useFuturesStore } from '@/stores'
|
|
|
import moment from 'moment'
|
|
|
|
|
|
// https://blog.csdn.net/jones2000/article/details/100181279
|
|
|
@@ -21,16 +20,16 @@ export interface NetworkFilterData {
|
|
|
}
|
|
|
|
|
|
// https://blog.csdn.net/jones2000/article/details/100149703
|
|
|
-export interface HistoryMinuteData {
|
|
|
+export interface RequestData {
|
|
|
name?: string; // 股票名称
|
|
|
symbol: string; // 股票代码
|
|
|
yclose: number; // 昨收
|
|
|
- open: number; // 当日开盘价
|
|
|
- high: number; // 当日最高价
|
|
|
- low: number; // 当日最低价
|
|
|
- vol: number; // 当日成交量
|
|
|
- amount: number; // 当日成交金额
|
|
|
- price: number; // 最新价/收盘价
|
|
|
+ open?: number; // 当日开盘价
|
|
|
+ high?: number; // 当日最高价
|
|
|
+ low?: number; // 当日最低价
|
|
|
+ vol?: number; // 当日成交量
|
|
|
+ amount?: number; // 当日成交金额
|
|
|
+ price?: number; // 最新价/收盘价
|
|
|
yclearing?: number; // 结算价
|
|
|
date: number; // 交易日期
|
|
|
time: number; // 最新的交易时间
|
|
|
@@ -48,7 +47,7 @@ export interface MinuteData {
|
|
|
amount: number; // 成交金额
|
|
|
date: number; // 交易日期 格式:yyyymmdd 如20191011=>2019-10-11
|
|
|
time: number; // 交易时间 格式:hhmm 如930 就是9:30
|
|
|
- avprice: number; // 均价
|
|
|
+ avprice?: number; // 均价
|
|
|
increase?: number; // 涨幅
|
|
|
risefall?: number; // 涨跌
|
|
|
lead?: number; // 领先指标(指数才有)
|
|
|
@@ -56,34 +55,37 @@ export interface MinuteData {
|
|
|
yclearing?: number; // 昨结算价(期货才有)
|
|
|
}
|
|
|
|
|
|
-export type NetworkFilterCallback = (historyMinuteData: { stock: HistoryMinuteData[] }) => void
|
|
|
+export type NetworkFilterCallback = (requestData: { stock: RequestData[] }) => void
|
|
|
|
|
|
export function useMinuteData(goodsCode: string) {
|
|
|
- const futuresStore = useFuturesStore()
|
|
|
- const quote = futuresStore.getGoodsQuote(goodsCode)
|
|
|
- const historyData = shallowRef<Model.TSDataRsp>()
|
|
|
+ const tsData = shallowRef<Model.TSDataRsp>()
|
|
|
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
+ symbol: ''
|
|
|
+ })
|
|
|
+
|
|
|
+ // 获取历史行情
|
|
|
+ const getTSDataAsync = queryTSData({
|
|
|
+ data: {
|
|
|
+ goodsCode,
|
|
|
+ }
|
|
|
+ }).then((res) => {
|
|
|
+ tsData.value = res.data
|
|
|
+ return res
|
|
|
})
|
|
|
|
|
|
const networkFilter = (data: NetworkFilterData, callback: NetworkFilterCallback) => {
|
|
|
data.PreventDefault = true
|
|
|
if (data.Name === 'MinuteChartContainer::RequestMinuteData') {
|
|
|
- getTSData().then((res) => {
|
|
|
- const { opened = 0, highest = 0, lowest = 0, totalvolume = 0, totalturnover = 0, last = 0 } = quote.value ?? {}
|
|
|
- const lastItem=res.data.historyDatas[res.data.historyDatas.length-1]
|
|
|
+ getTSDataAsync.then((res) => {
|
|
|
+ const [lastItem] = res.data.historyDatas.slice(-1)
|
|
|
+ state.symbol = data.Request.Data.symbol[0]
|
|
|
callback({
|
|
|
stock: [
|
|
|
{
|
|
|
- symbol: data.Request.Data.symbol[0],
|
|
|
+ symbol: state.symbol,
|
|
|
yclose: res.data.preSettle,
|
|
|
- open: opened,
|
|
|
- high: highest,
|
|
|
- low: lowest,
|
|
|
- vol: totalvolume,
|
|
|
- amount: totalturnover,
|
|
|
- price: last,
|
|
|
date: Number(moment(lastItem.ts).format('YYYYMMDD')),
|
|
|
time: Number(moment(lastItem.ts).format('HHmm')),
|
|
|
minute: res.data.historyDatas.map((e) => ({
|
|
|
@@ -95,7 +97,6 @@ export function useMinuteData(goodsCode: string) {
|
|
|
amount: e.tt,
|
|
|
date: Number(moment(e.ts).format('YYYYMMDD')),
|
|
|
time: Number(moment(e.ts).format('HHmm')),
|
|
|
- avprice: totalturnover/totalvolume
|
|
|
}))
|
|
|
}
|
|
|
]
|
|
|
@@ -104,86 +105,81 @@ export function useMinuteData(goodsCode: string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取历史行情
|
|
|
- const getTSData = () => {
|
|
|
- return queryTSData({
|
|
|
- data: {
|
|
|
- goodsCode,
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 处理图表数据
|
|
|
- const handleChartData = (data: Model.HistoryDatasRsp[]) => {
|
|
|
- return data.map((e, i) => {
|
|
|
- const date = Number(moment(e.ts).format('YYYYMMDD'))
|
|
|
- const time = Number(moment(e.ts).format('HHmm'))
|
|
|
- const preclose = data[i - 1] // 上一个收盘价
|
|
|
- const close = preclose ? preclose.c : e.c
|
|
|
-
|
|
|
- return [
|
|
|
- date, // 日期
|
|
|
- close, // 前收盘
|
|
|
- e.o, // 开盘价
|
|
|
- e.h, // 最高
|
|
|
- e.l, // 最低
|
|
|
- e.c, // 收盘
|
|
|
- e.tv, // 成交量
|
|
|
- e.tt, // 成交金额
|
|
|
- time, // 时间
|
|
|
- e.hv // 持仓量
|
|
|
- ]
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
// 更新最新数据
|
|
|
const updateLastData = (q: Partial<Model.QuoteDayRsp>) => {
|
|
|
const { last, lasttime } = q
|
|
|
- // if (last && lasttime) {
|
|
|
- // const lastIndex = historyData.value.length - 1 // 历史数据最后索引位置
|
|
|
- // const cycleMilliseconds = getCycleMilliseconds()
|
|
|
+ if (tsData.value && last && lasttime) {
|
|
|
+ const { preSettle, historyDatas } = tsData.value
|
|
|
+ const lastIndex = historyDatas.length - 1 // 历史数据最后索引位置
|
|
|
+ const cycleMilliseconds = 60 * 1000 // 一分钟毫秒数
|
|
|
+
|
|
|
+ const oldTime = lastIndex === -1 ? moment(lasttime) : moment(historyDatas[lastIndex].ts) // 历史行情最后时间
|
|
|
+ const diffTime = moment(lasttime).valueOf() - oldTime.valueOf() // 计算时间差
|
|
|
|
|
|
- // const oldTime = lastIndex === -1 ? moment(lasttime) : moment(historyData.value[lastIndex].ts) // 历史行情最后时间
|
|
|
- // const diffTime = moment(lasttime).valueOf() - oldTime.valueOf() // 计算时间差
|
|
|
+ // 判断时间差是否大于周期时间
|
|
|
+ if (lastIndex === -1 || diffTime > cycleMilliseconds) {
|
|
|
+ // 新增分时数据
|
|
|
+ historyDatas.push({
|
|
|
+ o: last,
|
|
|
+ h: last,
|
|
|
+ l: last,
|
|
|
+ c: last,
|
|
|
+ tv: q.lastvolume ?? 0,
|
|
|
+ tt: q.Lastturnover ?? 0,
|
|
|
+ hv: q.holdvolume ?? 0,
|
|
|
+ s: q.settle ?? 0,
|
|
|
+ ts: lasttime,
|
|
|
+ f: false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 更新列表中最后一条记录的数据
|
|
|
+ const record = historyDatas[lastIndex]
|
|
|
+ if (record.l > last) {
|
|
|
+ record.l = last // 更新最低价
|
|
|
+ }
|
|
|
+ if (record.h < last) {
|
|
|
+ record.h = last // 更新最高价
|
|
|
+ }
|
|
|
+ record.c = last // 更新收盘价
|
|
|
+ record.tv = q.lastvolume ?? record.tv
|
|
|
+ record.tt = q.Lastturnover ?? record.tt
|
|
|
+ record.hv = q.holdvolume ?? record.hv
|
|
|
+ record.s = q.settle ?? record.s
|
|
|
+ }
|
|
|
|
|
|
- // // 判断时间差是否大于周期时间
|
|
|
- // if (lastIndex === -1 || diffTime > cycleMilliseconds) {
|
|
|
- // historyData.value.push({
|
|
|
- // o: last,
|
|
|
- // h: last,
|
|
|
- // l: last,
|
|
|
- // c: last,
|
|
|
- // tv: q.lastvolume ?? 0,
|
|
|
- // tt: q.Lastturnover ?? 0,
|
|
|
- // hv: q.holdvolume ?? 0,
|
|
|
- // s: q.settle ?? 0,
|
|
|
- // ts: lasttime,
|
|
|
- // f: false
|
|
|
- // })
|
|
|
- // } else {
|
|
|
- // // 更新列表中最后一条记录的数据
|
|
|
- // const record = historyData.value[lastIndex]
|
|
|
- // if (record.l > last) {
|
|
|
- // record.l = last // 更新最低价
|
|
|
- // }
|
|
|
- // if (record.h < last) {
|
|
|
- // record.h = last // 更新最高价
|
|
|
- // }
|
|
|
- // record.c = last // 更新收盘价
|
|
|
- // record.tv = q.lastvolume ?? record.tv
|
|
|
- // record.tt = q.Lastturnover ?? record.tt
|
|
|
- // record.hv = q.holdvolume ?? record.hv
|
|
|
- // record.s = q.settle ?? record.s
|
|
|
- // }
|
|
|
+ const lastValue = historyDatas.slice(-1)
|
|
|
+ const date = Number(moment(lasttime).format('YYYYMMDD'))
|
|
|
+ const time = Number(moment(lasttime).format('HHmm'))
|
|
|
|
|
|
- // const lastValue = historyData.value.slice(-1)
|
|
|
- // return handleChartData(lastValue)
|
|
|
- // }
|
|
|
- return []
|
|
|
+ return {
|
|
|
+ dataType: 1, // 增量数据标识
|
|
|
+ stock: [
|
|
|
+ {
|
|
|
+ symbol: state.symbol,
|
|
|
+ date,
|
|
|
+ yclose: preSettle,
|
|
|
+ // 单条分钟数据格式 0=日期 1=时间 2=开 3=高 4=低 5=收 6=均价 7=量 8=金额 9=涨幅 10=涨跌 11=领先指标
|
|
|
+ minute: lastValue.map((e) => [
|
|
|
+ date,
|
|
|
+ time,
|
|
|
+ e.o,
|
|
|
+ e.h,
|
|
|
+ e.l,
|
|
|
+ e.c,
|
|
|
+ null,
|
|
|
+ e.tv,
|
|
|
+ e.tt
|
|
|
+ ])
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return undefined
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
...toRefs(state),
|
|
|
+ getTSDataAsync,
|
|
|
networkFilter,
|
|
|
updateLastData
|
|
|
}
|