diff --git a/api/ticker.php b/api/ticker.php index e1b8277..9eba872 100644 --- a/api/ticker.php +++ b/api/ticker.php @@ -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 = << $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) { diff --git a/assets/js/main.js b/assets/js/main.js index b584f5f..8de055d 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -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) { diff --git a/index.php b/index.php index 39b8ed8..4e3dc8d 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@
- BTC/USDT + BITCOIN
$0.00 @@ -82,7 +82,7 @@
- ETH/USDT + ETHEREUM
$0.00