feat(api): allow new chart timeframes in staging
This commit is contained in:
@@ -744,7 +744,7 @@ function computeCandleFlowMovesFromTicks({ candle, bucketSeconds, points, rows,
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseTimeframeToSeconds(tf) {
|
function parseTimeframeToSeconds(tf) {
|
||||||
const v = String(tf || '').trim().toLowerCase();
|
const v = normalizeChartTimeframe(tf);
|
||||||
if (!v) return 60;
|
if (!v) return 60;
|
||||||
const m = v.match(/^(\d+)(s|m|h|d)$/);
|
const m = v.match(/^(\d+)(s|m|h|d)$/);
|
||||||
if (!m) throw new Error(`invalid_tf`);
|
if (!m) throw new Error(`invalid_tf`);
|
||||||
@@ -755,6 +755,40 @@ function parseTimeframeToSeconds(tf) {
|
|||||||
return num * mult;
|
return num * mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SUPPORTED_CHART_TIMEFRAMES = new Set([
|
||||||
|
'1s',
|
||||||
|
'5s',
|
||||||
|
'15s',
|
||||||
|
'30s',
|
||||||
|
'1m',
|
||||||
|
'5m',
|
||||||
|
'15m',
|
||||||
|
'30m',
|
||||||
|
'1h',
|
||||||
|
'4h',
|
||||||
|
'8h',
|
||||||
|
'12h',
|
||||||
|
'1d',
|
||||||
|
]);
|
||||||
|
|
||||||
|
function normalizeChartTimeframe(tf) {
|
||||||
|
const raw = String(tf || '').trim();
|
||||||
|
if (!raw) return '1m';
|
||||||
|
|
||||||
|
const aliased =
|
||||||
|
raw === '1D' || raw === '24h' || raw === '24H'
|
||||||
|
? '1d'
|
||||||
|
: raw === '1H'
|
||||||
|
? '1h'
|
||||||
|
: raw.toLowerCase();
|
||||||
|
|
||||||
|
if (!SUPPORTED_CHART_TIMEFRAMES.has(aliased)) {
|
||||||
|
throw new Error('invalid_tf');
|
||||||
|
}
|
||||||
|
|
||||||
|
return aliased;
|
||||||
|
}
|
||||||
|
|
||||||
function fillForwardCandles(candles, { bucketSeconds, limit, nowSec }) {
|
function fillForwardCandles(candles, { bucketSeconds, limit, nowSec }) {
|
||||||
if (!Array.isArray(candles) || candles.length === 0) return [];
|
if (!Array.isArray(candles) || candles.length === 0) return [];
|
||||||
if (!Number.isFinite(bucketSeconds) || bucketSeconds <= 0) return candles;
|
if (!Number.isFinite(bucketSeconds) || bucketSeconds <= 0) return candles;
|
||||||
|
|||||||
Reference in New Issue
Block a user