AI分析关键字,净空持仓增减数据BUG

This commit is contained in:
tony 2026-07-21 23:28:57 +08:00
parent 843f0d73be
commit 0f04b1370a
4 changed files with 1470 additions and 5 deletions

1424
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -75,8 +75,9 @@ export function mapJqkaDealPosition(data: JqkaDealPositionData): PositionsData {
filter: (x) => x.f024n > 0, filter: (x) => x.f024n > 0,
}), }),
) )
// 净空:qty 取 |f024n|,增减需取反(净持仓更负 = 净空增加 → 显示为正)
const netShort = withPercent( const netShort = withPercent(
toRows(list, (x) => x.f024n, (x) => x.f025n, { toRows(list, (x) => x.f024n, (x) => -x.f025n, {
absQty: true, absQty: true,
filter: (x) => x.f024n < 0, filter: (x) => x.f024n < 0,
}), }),

View File

@ -1,27 +1,67 @@
import { ref } from 'vue' import { ref } from 'vue'
import type { AiAdvice } from '../types' import type { AiAdvice } from '../types'
import { aiAdviceMock } from '../mocks/aiAdvice' import { aiAdviceMock } from '../mocks/aiAdvice'
import { useQuotaStore, type AnalysisSnapshot, type KlinePeriod } from '../stores/quota'
import { useSettingsStore } from '../stores/settings'
function delay(ms = 400): Promise<void> { /** 提交给 AI 的完整载荷(格式化后的规则数据 + 关键词) */
return new Promise((r) => setTimeout(r, ms)) export interface AiAnalysisPayload {
/** 设置中的角色/分析关键词 */
keywords: string
/** 行情 + 新闻 + 机构持仓等接口快照 */
snapshot: AnalysisSnapshot
} }
const KLINE_PERIODS: KlinePeriod[] = ['day', 'week', 'month']
export function useAiAdvice() { export function useAiAdvice() {
const data = ref<AiAdvice>(structuredClone(aiAdviceMock)) const data = ref<AiAdvice>(structuredClone(aiAdviceMock))
const loading = ref(false) const loading = ref(false)
const error = ref<unknown>(null) const error = ref<unknown>(null)
const quota = useQuotaStore()
const settings = useSettingsStore()
/** 尽量补全日/周/月 K 线,失败不阻断主流程 */
async function ensureKlines() {
await Promise.all(
KLINE_PERIODS.map(async (period) => {
try {
await quota.loadKline(period)
} catch {
/* 已在 store 内打日志 */
}
}),
)
}
/**
* 一键获取建议:先收集行情 / 新闻 / 持仓(含 K 线),
* 再拼装提交给 AI 的关键词与格式化快照;当前阶段仅 console.log,仍返回 Mock 建议。
*/
async function refresh() { async function refresh() {
loading.value = true loading.value = true
error.value = null error.value = null
try { try {
await delay() await quota.fetchAll()
await ensureKlines()
const payload: AiAnalysisPayload = {
keywords: settings.keywords,
snapshot: quota.getAnalysisSnapshot(),
}
// 本阶段:打印将提交给 AI 的关键词与全部接口规则数据
console.log('[AI] 提交给 AI 的关键词', payload.keywords)
console.log('[AI] 提交给 AI 的数据(格式化规则快照)', payload.snapshot)
console.log('[AI] 完整载荷', payload)
data.value = { data.value = {
...structuredClone(aiAdviceMock), ...structuredClone(aiAdviceMock),
updatedAt: new Date().toLocaleString('zh-CN', { hour12: false }), updatedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
} }
} catch (e) { } catch (e) {
error.value = e error.value = e
console.error('[AI] 一键获取建议失败', e)
} finally { } finally {
loading.value = false loading.value = false
} }

View File

@ -112,7 +112,7 @@ export interface PositionsData {
volume: PositionRow[] volume: PositionRow[]
/** 净多持仓(f024n > 0) */ /** 净多持仓(f024n > 0) */
netLong: PositionRow[] netLong: PositionRow[]
/** 净空持仓(f024n < 0,qty 取绝对值) */ /** 净空持仓(f024n < 0,qty 取绝对值,change 为 -f025n) */
netShort: PositionRow[] netShort: PositionRow[]
/** 盈利机构前 20(day_profit > 0) */ /** 盈利机构前 20(day_profit > 0) */
profitGain: ProfitRow[] profitGain: ProfitRow[]