AI分析关键字,净空持仓增减数据BUG
This commit is contained in:
parent
843f0d73be
commit
0f04b1370a
1424
pnpm-lock.yaml
generated
Normal file
1424
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -75,8 +75,9 @@ export function mapJqkaDealPosition(data: JqkaDealPositionData): PositionsData {
|
||||
filter: (x) => x.f024n > 0,
|
||||
}),
|
||||
)
|
||||
// 净空:qty 取 |f024n|,增减需取反(净持仓更负 = 净空增加 → 显示为正)
|
||||
const netShort = withPercent(
|
||||
toRows(list, (x) => x.f024n, (x) => x.f025n, {
|
||||
toRows(list, (x) => x.f024n, (x) => -x.f025n, {
|
||||
absQty: true,
|
||||
filter: (x) => x.f024n < 0,
|
||||
}),
|
||||
|
||||
@ -1,27 +1,67 @@
|
||||
import { ref } from 'vue'
|
||||
import type { AiAdvice } from '../types'
|
||||
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> {
|
||||
return new Promise((r) => setTimeout(r, ms))
|
||||
/** 提交给 AI 的完整载荷(格式化后的规则数据 + 关键词) */
|
||||
export interface AiAnalysisPayload {
|
||||
/** 设置中的角色/分析关键词 */
|
||||
keywords: string
|
||||
/** 行情 + 新闻 + 机构持仓等接口快照 */
|
||||
snapshot: AnalysisSnapshot
|
||||
}
|
||||
|
||||
const KLINE_PERIODS: KlinePeriod[] = ['day', 'week', 'month']
|
||||
|
||||
export function useAiAdvice() {
|
||||
const data = ref<AiAdvice>(structuredClone(aiAdviceMock))
|
||||
const loading = ref(false)
|
||||
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() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
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 = {
|
||||
...structuredClone(aiAdviceMock),
|
||||
updatedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e
|
||||
console.error('[AI] 一键获取建议失败', e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ export interface PositionsData {
|
||||
volume: PositionRow[]
|
||||
/** 净多持仓(f024n > 0) */
|
||||
netLong: PositionRow[]
|
||||
/** 净空持仓(f024n < 0,qty 取绝对值) */
|
||||
/** 净空持仓(f024n < 0,qty 取绝对值,change 为 -f025n) */
|
||||
netShort: PositionRow[]
|
||||
/** 盈利机构前 20(day_profit > 0) */
|
||||
profitGain: ProfitRow[]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user