|
|
|
|
@ -917,6 +917,10 @@
|
|
|
|
|
<option value="daily">日线</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label class="form-label">结束日期</label>
|
|
|
|
|
<input type="date" class="form-input" id="queryEndTime">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<button class="btn btn-primary" onclick="queryCache()" style="height: 42px;">
|
|
|
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
|
|
|
|
@ -1876,21 +1880,44 @@
|
|
|
|
|
async function queryCache() {
|
|
|
|
|
const symbol = document.getElementById('querySymbol').value.trim();
|
|
|
|
|
const period = document.getElementById('queryPeriod').value;
|
|
|
|
|
const endDate = document.getElementById('queryEndTime').value;
|
|
|
|
|
|
|
|
|
|
if (!symbol) return showToast('请输入品种代码', 'error');
|
|
|
|
|
|
|
|
|
|
addLog(`查询缓存: ${symbol} ${period || '全部'}`);
|
|
|
|
|
addLog(`查询缓存: ${symbol} ${period || '全部'} 结束日期: ${endDate || '今天'}`);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const url = period ? `${API}/data/latest/${symbol}/${period}` : `${API}/data/latest/${symbol}`;
|
|
|
|
|
// 构建查询参数
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
if (period) params.append('period', period);
|
|
|
|
|
if (endDate) {
|
|
|
|
|
// 将日期转换为当天结束时间 23:59:59
|
|
|
|
|
const endDateTime = new Date(endDate);
|
|
|
|
|
endDateTime.setHours(23, 59, 59, 999);
|
|
|
|
|
params.append('end_time', endDateTime.toISOString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const queryString = params.toString();
|
|
|
|
|
const url = `${API}/data/latest/${symbol}${queryString ? '?' + queryString : ''}`;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(url);
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
|
|
// 先检查响应状态
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
showToast(data.detail || '未找到缓存数据', 'error');
|
|
|
|
|
const errorText = await res.text();
|
|
|
|
|
console.error('API错误响应:', errorText);
|
|
|
|
|
try {
|
|
|
|
|
const errorData = JSON.parse(errorText);
|
|
|
|
|
showToast(errorData.detail || '查询失败', 'error');
|
|
|
|
|
} catch {
|
|
|
|
|
showToast(`服务器错误: ${res.status}`, 'error');
|
|
|
|
|
}
|
|
|
|
|
document.getElementById('btnExportData').disabled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
|
|
addLog(`查询成功: ${symbol}, 缓存 ${data.timeframes ? data.timeframes.length : 0} 个周期`, 'success');
|
|
|
|
|
|
|
|
|
|
currentQueryData = data;
|
|
|
|
|
@ -1905,6 +1932,7 @@
|
|
|
|
|
renderKlineChart(data.timeframes[0], symbol);
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('查询异常:', e);
|
|
|
|
|
showToast(`查询失败: ${e.message}`, 'error');
|
|
|
|
|
document.getElementById('btnExportData').disabled = true;
|
|
|
|
|
}
|
|
|
|
|
@ -1917,12 +1945,25 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const symbol = document.getElementById('querySymbol').value.trim() || 'unknown';
|
|
|
|
|
const period = document.getElementById('queryPeriod').value;
|
|
|
|
|
const endDate = document.getElementById('queryEndTime').value;
|
|
|
|
|
|
|
|
|
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
|
|
|
const filename = `${symbol}_多周期数据_${timestamp}.json`;
|
|
|
|
|
|
|
|
|
|
// 根据是否选择结束日期和周期,生成不同的文件名
|
|
|
|
|
let filename;
|
|
|
|
|
if (endDate) {
|
|
|
|
|
filename = `${symbol}_${period || '多周期'}_截至${endDate}_${timestamp}.json`;
|
|
|
|
|
} else {
|
|
|
|
|
const today = new Date().toISOString().slice(0, 10);
|
|
|
|
|
filename = `${symbol}_${period || '多周期'}_截至${today}_${timestamp}.json`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const exportObj = {
|
|
|
|
|
symbol: currentQueryData.symbol || symbol,
|
|
|
|
|
type: currentQueryData.type || 'futures',
|
|
|
|
|
period: period || 'all',
|
|
|
|
|
end_date: endDate || new Date().toISOString().slice(0, 10),
|
|
|
|
|
current_price: currentQueryData.current_price,
|
|
|
|
|
timestamp: currentQueryData.timestamp || new Date().toISOString(),
|
|
|
|
|
timeframes: {}
|
|
|
|
|
@ -2956,6 +2997,14 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init
|
|
|
|
|
// 页面加载时设置默认日期为今天
|
|
|
|
|
function initDefaultDate() {
|
|
|
|
|
const today = new Date().toISOString().slice(0, 10);
|
|
|
|
|
document.getElementById('queryEndTime').value = today;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
initDefaultDate();
|
|
|
|
|
loadConfig();
|
|
|
|
|
loadTasks();
|
|
|
|
|
</script>
|
|
|
|
|
|