mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 15:34:16 +08:00
Merge pull request #258 from 0112020179/codex/fix-null-minute-amount
fix(intraday): handle missing minute amount
This commit is contained in:
@@ -30,7 +30,8 @@ interface Props {
|
||||
showAvgLine?: boolean
|
||||
}
|
||||
|
||||
function fmtAmt(v: number): string {
|
||||
function fmtAmt(v: number | null | undefined): string {
|
||||
if (v == null || !Number.isFinite(v)) return '—'
|
||||
if (v >= 1_000_000_000) return `${(v / 1_000_000_000).toFixed(2)}亿`
|
||||
if (v >= 10_000) return `${(v / 10_000).toFixed(0)}万`
|
||||
return v.toFixed(0)
|
||||
|
||||
@@ -29,7 +29,8 @@ interface InfoPoint {
|
||||
prevClose: number | null
|
||||
}
|
||||
|
||||
function formatAmount(value: number): string {
|
||||
function formatAmount(value: number | null | undefined): string {
|
||||
if (value == null || !Number.isFinite(value)) return '—'
|
||||
if (value >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(2)}亿`
|
||||
if (value >= 10_000) return `${(value / 10_000).toFixed(0)}万`
|
||||
return value.toFixed(0)
|
||||
|
||||
@@ -208,7 +208,7 @@ export interface MinuteKlineRow {
|
||||
low: number
|
||||
close: number
|
||||
volume: number
|
||||
amount: number
|
||||
amount: number | null
|
||||
}
|
||||
|
||||
export interface MinuteKlineSession {
|
||||
|
||||
@@ -11,10 +11,15 @@ export function computeIntradayAverage(data: MinuteKlineRow[]): number[] {
|
||||
const result: number[] = []
|
||||
let amount = 0
|
||||
let volume = 0
|
||||
let hasAmount = true
|
||||
for (const row of data) {
|
||||
amount += row.amount
|
||||
if (typeof row.amount === 'number' && Number.isFinite(row.amount)) {
|
||||
amount += row.amount
|
||||
} else {
|
||||
hasAmount = false
|
||||
}
|
||||
volume += row.volume * 100
|
||||
result.push(volume > 0 ? amount / volume : row.close)
|
||||
result.push(hasAmount && volume > 0 ? amount / volume : row.close)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user