diff --git a/src/api/jqka/position.ts b/src/api/jqka/position.ts index 935abff..e02822f 100644 --- a/src/api/jqka/position.ts +++ b/src/api/jqka/position.ts @@ -8,7 +8,7 @@ import type { } from './types' import { extractVariety, - getPreviousTradingDate, + getPositionQueryDate, getRecentMonthRange, } from '../../utils/tradingDate' @@ -19,7 +19,7 @@ export interface GetDealPositionParams { variety?: string /** * 查询日期 YYYY-MM-DD。 - * 缺省为上一交易日(接口一般只能查到上一交易日)。 + * 缺省:交易日 16:00 后为当天,否则上一交易日。 */ date?: string } @@ -33,7 +33,7 @@ export async function getDealPosition( ): Promise { const contract = params.contract const variety = params.variety ?? extractVariety(contract) - const date = params.date ?? getPreviousTradingDate() + const date = params.date ?? getPositionQueryDate() const { data } = await jqkaHttp.get( '/futgwapi/api/market/v1/position/getDealPosition/', diff --git a/src/components/quote/QuoteStats.vue b/src/components/quote/QuoteStats.vue index 5d28f2e..0918649 100644 --- a/src/components/quote/QuoteStats.vue +++ b/src/components/quote/QuoteStats.vue @@ -38,14 +38,14 @@ const columns = computed((): StatCell[][] => { { label: '成交额', value: `${q.amount}亿` }, ], [ - { label: '持仓量', value: q.openInterest.toLocaleString() }, + { label: '持仓量', value: `${(q.openInterest / 10000).toFixed(2)}万` }, { label: '振幅', value: `${q.amplitude}%` }, - { label: '外盘', value: q.outerVol.toLocaleString(), className: 'price-up' }, + { label: '外盘', value: `${(q.outerVol / 10000).toFixed(2)}万`, className: 'price-up' }, ], [ { label: '昨收', value: q.prevClose.toFixed(2) }, { label: '成交量', value: q.volume.toLocaleString() }, - { label: '内盘', value: q.innerVol.toLocaleString(), className: 'price-down' }, + { label: '内盘', value: `${(q.innerVol / 10000).toFixed(2)}万`, className: 'price-down' }, ], [ { label: '最低', value: q.low.toFixed(2), className: 'price-down' }, diff --git a/src/composables/usePositions.ts b/src/composables/usePositions.ts index c60224a..66d38a4 100644 --- a/src/composables/usePositions.ts +++ b/src/composables/usePositions.ts @@ -4,7 +4,7 @@ import { useQuotaStore } from '../stores/quota' /** * 机构持仓 composable:状态统一落在 quota store。 - * 打开页面时按上一交易日拉取同花顺会员持仓。 + * 打开页面时按交易日规则拉取同花顺会员持仓(16:00 后查当天,否则上一交易日)。 */ export function usePositions() { const store = useQuotaStore() diff --git a/src/stores/quota.ts b/src/stores/quota.ts index 592499f..eba0838 100644 --- a/src/stores/quota.ts +++ b/src/stores/quota.ts @@ -15,6 +15,7 @@ import { getDealPosition, getPositionProfitRank } from '../api/jqka/position' import { mapJqkaDealPosition, mapJqkaPositionProfit } from '../api/jqka/mapPosition' import { extractVariety, + getPositionQueryDate, getPreviousTradingDate, } from '../utils/tradingDate' @@ -129,7 +130,8 @@ export const useQuotaStore = defineStore('quota', () => { /** * 拉取会员持仓 + 机构盈利。 - * 持仓日期默认上一交易日;若遇节假日空数据则再往前最多试 5 个交易日。 + * 持仓日期:交易日 16:00 后查当天,否则查上一交易日; + * 若遇节假日空数据则再往前最多试 5 个交易日。 * 盈利默认最近一个月、按当前品种查询。 */ async function fetchPositions() { @@ -138,7 +140,7 @@ export const useQuotaStore = defineStore('quota', () => { try { const contract = contractConfig.code const variety = contractConfig.variety || extractVariety(contract) - let date = getPreviousTradingDate() + let date = getPositionQueryDate() let mapped: PositionsData | null = null for (let i = 0; i < 5; i++) { diff --git a/src/utils/tradingDate.ts b/src/utils/tradingDate.ts index 31d1d74..5c7a6dc 100644 --- a/src/utils/tradingDate.ts +++ b/src/utils/tradingDate.ts @@ -13,9 +13,13 @@ function isWeekend(d: Date): boolean { return day === 0 || day === 6 } +/** 是否交易日(跳过周末;不含法定节假日日历) */ +export function isTradingDay(d: Date = new Date()): boolean { + return !isWeekend(d) +} + /** * 上一个交易日(跳过周末;不含法定节假日日历)。 - * 持仓接口一般只能查到上一交易日数据,故默认用此日期。 */ export function getPreviousTradingDate(from: Date = new Date()): string { const d = new Date(from.getFullYear(), from.getMonth(), from.getDate()) @@ -26,6 +30,19 @@ export function getPreviousTradingDate(from: Date = new Date()): string { return formatDateYmd(d) } +/** + * 机构持仓默认查询日期: + * - 当天为交易日且已到下午 16:00(含)→ 查当天 + * - 否则(交易日 16:00 前,或非交易日)→ 查上一交易日 + */ +export function getPositionQueryDate(from: Date = new Date()): string { + const now = new Date(from) + if (isTradingDay(now) && now.getHours() >= 16) { + return formatDateYmd(now) + } + return getPreviousTradingDate(now) +} + /** * 从合约代码提取品种,如 FG609 → FG、au2512 → au */