前20多空机构持仓仅显示最近3个月
This commit is contained in:
parent
8ea48632ee
commit
843f0d73be
@ -43,7 +43,7 @@
|
||||
<el-dialog
|
||||
v-model="positionOpen"
|
||||
title="机构持仓"
|
||||
width="70%"
|
||||
width="80%"
|
||||
top="5vh"
|
||||
class="panel-dialog position-dialog"
|
||||
destroy-on-close
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import type { PositionRow, PositionsData, ProfitRow, TopTwentySum } from '../../types'
|
||||
import { getRecentMonthsRange } from '../../utils/tradingDate'
|
||||
import type {
|
||||
JqkaDealPositionData,
|
||||
JqkaPositionItem,
|
||||
JqkaPositionProfitData,
|
||||
} from './types'
|
||||
|
||||
/** 前 20 多空总持仓图表仅保留最近 3 个月 */
|
||||
const TOP_TWENTY_SUM_MONTHS = 3
|
||||
|
||||
const TOP_N = 20
|
||||
|
||||
function withPercent(list: PositionRow[], totalHint?: number): PositionRow[] {
|
||||
@ -78,13 +82,14 @@ export function mapJqkaDealPosition(data: JqkaDealPositionData): PositionsData {
|
||||
}),
|
||||
)
|
||||
|
||||
const topTwentySum: TopTwentySum[] = (data.topTwentyPositionSum ?? []).map(
|
||||
(s) => ({
|
||||
const { startDate } = getRecentMonthsRange(TOP_TWENTY_SUM_MONTHS)
|
||||
const topTwentySum: TopTwentySum[] = (data.topTwentyPositionSum ?? [])
|
||||
.filter((s) => s.tradeDate >= startDate)
|
||||
.map((s) => ({
|
||||
tradeDate: s.tradeDate,
|
||||
longSum: s.f009nSum,
|
||||
shortSum: s.f015nSum,
|
||||
}),
|
||||
)
|
||||
}))
|
||||
|
||||
const updatedAt =
|
||||
list[0]?.tradeDate || sumLatest?.tradeDate || new Date().toISOString().slice(0, 10)
|
||||
|
||||
@ -18,18 +18,23 @@ import {
|
||||
import type { EChartsOption } from 'echarts'
|
||||
import VChart from 'vue-echarts'
|
||||
import type { TopTwentySum } from '../../types'
|
||||
import { getRecentMonthsRange } from '../../utils/tradingDate'
|
||||
|
||||
use([CanvasRenderer, BarChart, GridComponent, TooltipComponent, LegendComponent])
|
||||
|
||||
/** 仅展示最近 3 个月 */
|
||||
const DISPLAY_MONTHS = 3
|
||||
|
||||
const props = defineProps<{
|
||||
list: TopTwentySum[]
|
||||
}>()
|
||||
|
||||
const option = computed((): EChartsOption => {
|
||||
// 接口通常新→旧,图表按时间从左到右
|
||||
const sorted = [...props.list].sort((a, b) =>
|
||||
a.tradeDate.localeCompare(b.tradeDate),
|
||||
)
|
||||
const { startDate } = getRecentMonthsRange(DISPLAY_MONTHS)
|
||||
// 接口通常新→旧,图表按时间从左到右;仅保留最近 3 个月
|
||||
const sorted = [...props.list]
|
||||
.filter((x) => x.tradeDate >= startDate)
|
||||
.sort((a, b) => a.tradeDate.localeCompare(b.tradeDate))
|
||||
const dates = sorted.map((x) => x.tradeDate)
|
||||
const longData = sorted.map((x) => x.longSum)
|
||||
const shortData = sorted.map((x) => x.shortSum)
|
||||
|
||||
@ -51,6 +51,25 @@ export function extractVariety(contract: string): string {
|
||||
return m ? m[1] : contract
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近 N 个月日期区间(含起止日)。
|
||||
*/
|
||||
export function getRecentMonthsRange(
|
||||
months: number,
|
||||
from: Date = new Date(),
|
||||
): {
|
||||
startDate: string
|
||||
endDate: string
|
||||
} {
|
||||
const end = new Date(from.getFullYear(), from.getMonth(), from.getDate())
|
||||
const start = new Date(end)
|
||||
start.setMonth(start.getMonth() - months)
|
||||
return {
|
||||
startDate: formatDateYmd(start),
|
||||
endDate: formatDateYmd(end),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近一个月日期区间(含起止日),用于机构盈利等按区间查询的接口。
|
||||
*/
|
||||
@ -58,11 +77,5 @@ export function getRecentMonthRange(from: Date = new Date()): {
|
||||
startDate: string
|
||||
endDate: string
|
||||
} {
|
||||
const end = new Date(from.getFullYear(), from.getMonth(), from.getDate())
|
||||
const start = new Date(end)
|
||||
start.setMonth(start.getMonth() - 1)
|
||||
return {
|
||||
startDate: formatDateYmd(start),
|
||||
endDate: formatDateYmd(end),
|
||||
}
|
||||
return getRecentMonthsRange(1, from)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user