Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +14 -4
index.html
CHANGED
@@ -293,8 +293,8 @@
|
|
293 |
});
|
294 |
|
295 |
// API Configuration
|
296 |
-
let API_KEY = localStorage.getItem('bingxApiKey') || '
|
297 |
-
let API_SECRET = localStorage.getItem('bingxApiSecret') || '
|
298 |
const API_BASE_URL = 'https://open-api.bingx.com';
|
299 |
|
300 |
// Toggle API Form
|
@@ -335,6 +335,9 @@
|
|
335 |
|
336 |
// Fetch from API
|
337 |
async function fetchFromAPI(endpoint, params = {}) {
|
|
|
|
|
|
|
338 |
params.timestamp = Date.now();
|
339 |
params.recvWindow = 5000; // Optional, check if needed
|
340 |
// Do not include apiKey in params
|
@@ -342,7 +345,10 @@
|
|
342 |
params.signature = signature;
|
343 |
const url = `${API_BASE_URL}${endpoint}?${new URLSearchParams(params)}`;
|
344 |
const response = await fetch(url, { method: 'GET', headers: { 'X-BX-APIKEY': API_KEY } });
|
345 |
-
if (!response.ok)
|
|
|
|
|
|
|
346 |
return response.json();
|
347 |
}
|
348 |
|
@@ -473,6 +479,10 @@
|
|
473 |
document.querySelectorAll('.trading-card h3').forEach(el => el.textContent = 'Loading...');
|
474 |
document.getElementById('trading-table-body').innerHTML = '<tr><td colspan="8" class="py-4 text-center">Loading...</td></tr>';
|
475 |
|
|
|
|
|
|
|
|
|
476 |
const [balance, positions, trades] = await Promise.all([
|
477 |
fetchBalance(),
|
478 |
fetchOpenPositions(),
|
@@ -500,7 +510,7 @@
|
|
500 |
document.getElementById('allocation-update').textContent = `Last updated: ${new Date().toLocaleTimeString()}`;
|
501 |
} catch (error) {
|
502 |
console.error('Error fetching data:', error);
|
503 |
-
alert(
|
504 |
}
|
505 |
}
|
506 |
|
|
|
293 |
});
|
294 |
|
295 |
// API Configuration
|
296 |
+
let API_KEY = localStorage.getItem('bingxApiKey') || ''; // Removed default hardcoded value
|
297 |
+
let API_SECRET = localStorage.getItem('bingxApiSecret') || ''; // Removed default hardcoded value
|
298 |
const API_BASE_URL = 'https://open-api.bingx.com';
|
299 |
|
300 |
// Toggle API Form
|
|
|
335 |
|
336 |
// Fetch from API
|
337 |
async function fetchFromAPI(endpoint, params = {}) {
|
338 |
+
if (!API_KEY || !API_SECRET) {
|
339 |
+
throw new Error('API Key and Secret are not set. Please enter your credentials.');
|
340 |
+
}
|
341 |
params.timestamp = Date.now();
|
342 |
params.recvWindow = 5000; // Optional, check if needed
|
343 |
// Do not include apiKey in params
|
|
|
345 |
params.signature = signature;
|
346 |
const url = `${API_BASE_URL}${endpoint}?${new URLSearchParams(params)}`;
|
347 |
const response = await fetch(url, { method: 'GET', headers: { 'X-BX-APIKEY': API_KEY } });
|
348 |
+
if (!response.ok) {
|
349 |
+
const errorText = await response.text();
|
350 |
+
throw new Error(`API Error ${response.status}: ${errorText}`);
|
351 |
+
}
|
352 |
return response.json();
|
353 |
}
|
354 |
|
|
|
479 |
document.querySelectorAll('.trading-card h3').forEach(el => el.textContent = 'Loading...');
|
480 |
document.getElementById('trading-table-body').innerHTML = '<tr><td colspan="8" class="py-4 text-center">Loading...</td></tr>';
|
481 |
|
482 |
+
if (!API_KEY || !API_SECRET) {
|
483 |
+
throw new Error('Please enter your BingX API Key and Secret in the credentials form.');
|
484 |
+
}
|
485 |
+
|
486 |
const [balance, positions, trades] = await Promise.all([
|
487 |
fetchBalance(),
|
488 |
fetchOpenPositions(),
|
|
|
510 |
document.getElementById('allocation-update').textContent = `Last updated: ${new Date().toLocaleTimeString()}`;
|
511 |
} catch (error) {
|
512 |
console.error('Error fetching data:', error);
|
513 |
+
alert(`Failed to sync with BingX API: ${error.message}. Please check your credentials, network, or BingX API documentation.`);
|
514 |
}
|
515 |
}
|
516 |
|