fix(mse): chart price precision from actual data + kline limit 1000
- priceFormat precision derived from Binance kline close string decimal count instead of hardcoded 2 — DOGE shows 0.09849 not 0.10 - kline limit 200 → 1000 to show more history from bot start Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
65876fb895
commit
a8e80e0a15
1 changed files with 12 additions and 1 deletions
|
|
@ -488,6 +488,7 @@ function initChart() {
|
|||
upColor: '#2ecc71', downColor: '#e74c3c',
|
||||
borderUpColor: '#2ecc71', borderDownColor: '#e74c3c',
|
||||
wickUpColor: '#2ecc71', wickDownColor: '#e74c3c',
|
||||
priceFormat: { type: 'price', precision: 8, minMove: 0.00000001 },
|
||||
});
|
||||
chart.subscribeCrosshairMove(p => {
|
||||
if (!p.seriesData || !p.seriesData.size) return;
|
||||
|
|
@ -508,9 +509,19 @@ function initChart() {
|
|||
async function loadKlines() {
|
||||
const interval = TF_MAP[bot.timeframe] || '5m';
|
||||
try {
|
||||
const res = await fetch(`https://api.binance.com/api/v3/klines?symbol=${bot.symbol}&interval=${interval}&limit=200`);
|
||||
const res = await fetch(`https://api.binance.com/api/v3/klines?symbol=${bot.symbol}&interval=${interval}&limit=1000`);
|
||||
const data = await res.json();
|
||||
const candles = data.map(k => ({ time: Math.floor(k[0]/1000), open: parseFloat(k[1]), high: parseFloat(k[2]), low: parseFloat(k[3]), close: parseFloat(k[4]) }));
|
||||
|
||||
// fiyatın ondalık basamak sayısını ilk kapanış fiyatından türet
|
||||
if (candles.length) {
|
||||
const sample = data[data.length - 1][4]; // son kapanış string olarak
|
||||
const dotIdx = sample.indexOf('.');
|
||||
const decimals = dotIdx >= 0 ? sample.length - dotIdx - 1 : 0;
|
||||
const minMove = decimals > 0 ? parseFloat('0.' + '0'.repeat(decimals - 1) + '1') : 1;
|
||||
candleSeries.applyOptions({ priceFormat: { type: 'price', precision: decimals, minMove } });
|
||||
}
|
||||
|
||||
candleSeries.setData(candles);
|
||||
chart.timeScale().scrollToRealTime();
|
||||
chart.timeScale().setVisibleLogicalRange({ from: candles.length - 80, to: candles.length + 5 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue