This commit is contained in:
Flatlogic Bot 2025-11-16 16:03:04 +00:00
parent 4bb72bebc1
commit 766cac14c7
3 changed files with 27 additions and 20 deletions

View File

@ -3,15 +3,15 @@ header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
// --- Configuration ---
$symbols = ['BTCUSDT', 'ETHUSDT'];
$exchange = 'Binance';
$interval = '1m';
$symbols = ['bitcoin', 'ethereum']; // CoinGecko IDs
$exchange = 'CoinGecko';
$interval = '1d'; // CoinGecko provides daily data
// --- Data Fetching ---
function fetch_candlestick_data($symbol, $interval) {
$api_url = sprintf(
"https://api.binance.com/api/v3/klines?symbol=%s&interval=%s&limit=5",
$symbol, $interval
"https://api.coingecko.com/api/v3/coins/%s/ohlc?vs_currency=usd&days=1",
$symbol
);
$ch = curl_init();
@ -23,15 +23,29 @@ function fetch_candlestick_data($symbol, $interval) {
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return json_decode($response, true);
if ($http_code !== 200) {
error_log("CoinGecko API request failed with HTTP code {$http_code}: {$response}");
return null;
}
$data = json_decode($response, true);
if (isset($data['error'])) {
error_log("CoinGecko API error: " . $data['error']);
return null;
}
return $data;
}
// --- Database Logging ---
function log_candlestick_data($pdo, $symbol, $exchange, $interval, $kline) {
$sql = <<<SQL
INSERT INTO candlestick_data (symbol, exchange, interval_time, open_time, open_price, high_price, low_price, close_price, volume, close_time, quote_asset_volume, number_of_trades, taker_buy_base_asset_volume, taker_buy_quote_asset_volume)
VALUES (:symbol, :exchange, :interval_time, :open_time, :open_price, :high_price, :low_price, :close_price, :volume, :close_time, :quote_asset_volume, :number_of_trades, :taker_buy_base_asset_volume, :taker_buy_quote_asset_volume)
VALUES (:symbol, :exchange, :interval_time, :open_time, :open_price, :high_price, :low_price, :close_price, 0, 0, 0, 0, 0, 0)
ON DUPLICATE KEY UPDATE
close_price = VALUES(close_price), high_price = VALUES(high_price), low_price = VALUES(low_price), volume = VALUES(volume);
SQL;
@ -47,12 +61,6 @@ SQL;
':high_price' => $kline[2],
':low_price' => $kline[3],
':close_price' => $kline[4],
':volume' => $kline[5],
':close_time' => $kline[6],
':quote_asset_volume' => $kline[7],
':number_of_trades' => $kline[8],
':taker_buy_base_asset_volume' => $kline[9],
':taker_buy_quote_asset_volume' => $kline[10],
]);
}
@ -76,9 +84,9 @@ try {
$latest_kline = end($klines);
$latest_tickers[] = [
'exchange' => $exchange,
'symbol' => $symbol,
'symbol' => strtoupper($symbol),
'price' => $latest_kline[4], // Close price
'change_24h_percent' => 0, // Placeholder, as kline API doesn't provide this directly
'change_24h_percent' => 0, // Placeholder
'signal' => '-'
];
}
@ -91,7 +99,6 @@ try {
}
// --- Output for Frontend ---
// This part is for the main dashboard display, not the alerts API.
if (isset($_GET['symbol'])) {
$symbol_to_find = strtoupper($_GET['symbol']);
foreach ($latest_tickers as $ticker) {

View File

@ -3,8 +3,8 @@ document.addEventListener('DOMContentLoaded', function () {
const ALERT_POLLING_INTERVAL = 10000; // 10 seconds for alerts
const liveTickers = [
{ symbol: 'BTCUSDT', elementId: 'live-crypto-row-btc', lastPrice: 0 },
{ symbol: 'ETHUSDT', elementId: 'live-crypto-row-eth', lastPrice: 0 }
{ symbol: 'BITCOIN', elementId: 'live-crypto-row-btc', lastPrice: 0 },
{ symbol: 'ETHEREUM', elementId: 'live-crypto-row-eth', lastPrice: 0 }
];
async function fetchAndupdate(ticker, rowElement) {

View File

@ -64,7 +64,7 @@
<td>
<div class="d-flex align-items-center">
<img src="https://via.placeholder.com/24/f0b90b/000000?Text=B" class="symbol-logo rounded-circle" alt="BTC">
<span class="fw-bold symbol">BTC/USDT</span>
<span class="fw-bold symbol">BITCOIN</span>
</div>
</td>
<td class="fw-bold fs-5 price">$0.00</td>
@ -82,7 +82,7 @@
<td>
<div class="d-flex align-items-center">
<img src="https://via.placeholder.com/24/6f42c1/FFFFFF?Text=E" class="symbol-logo rounded-circle" alt="ETH">
<span class="fw-bold symbol">ETH/USDT</span>
<span class="fw-bold symbol">ETHEREUM</span>
</div>
</td>
<td class="fw-bold fs-5 price">$0.00</td>