fix: limit klines to 1 hour, fix chart parsing string to number
- Kline data now fetches only last hour of data - SignalChart converts string 'close' prices to numbers
This commit is contained in:
@@ -154,9 +154,17 @@ async def start_simulation(
|
|||||||
# Fetch klines SYNCHRONOUSLY so user can see chart immediately
|
# Fetch klines SYNCHRONOUSLY so user can see chart immediately
|
||||||
try:
|
try:
|
||||||
token_id = f"{config.token}-{config.chain}"
|
token_id = f"{config.token}-{config.chain}"
|
||||||
|
|
||||||
|
# Calculate time range (last 1 hour)
|
||||||
|
import time
|
||||||
|
end_time = int(time.time() * 1000)
|
||||||
|
start_time = end_time - (60 * 60 * 1000) # 1 hour ago
|
||||||
|
|
||||||
klines_data = await ave_client.get_klines(
|
klines_data = await ave_client.get_klines(
|
||||||
token_id,
|
token_id,
|
||||||
interval=config.kline_interval,
|
interval=config.kline_interval,
|
||||||
|
start_time=start_time,
|
||||||
|
end_time=end_time,
|
||||||
limit=500
|
limit=500
|
||||||
)
|
)
|
||||||
klines_for_chart = [
|
klines_for_chart = [
|
||||||
|
|||||||
@@ -41,12 +41,14 @@
|
|||||||
// Clear
|
// Clear
|
||||||
ctx.clearRect(0, 0, width, height);
|
ctx.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
// Get price data
|
// Get price data (convert strings to numbers)
|
||||||
const prices = klines.length > 0
|
const priceData = klines.length > 0
|
||||||
? klines.map(k => k.close)
|
? klines.map(k => ({ time: k.time, price: parseFloat(k.close) || 0 }))
|
||||||
: signals.map(s => s.price);
|
: signals.map(s => ({ time: 0, price: s.price }));
|
||||||
|
|
||||||
if (prices.length === 0) return;
|
if (priceData.length === 0) return;
|
||||||
|
|
||||||
|
const prices = priceData.map(d => d.price);
|
||||||
|
|
||||||
const padding = { top: 20, right: 20, bottom: 30, left: 60 };
|
const padding = { top: 20, right: 20, bottom: 30, left: 60 };
|
||||||
const chartWidth = width - padding.left - padding.right;
|
const chartWidth = width - padding.left - padding.right;
|
||||||
|
|||||||
Reference in New Issue
Block a user