我目前正在开发一个提供某些加密货币实时价格的网站,我使用coinmarketcap和binance api来访问这些数据,但我希望实时更新数据或每隔10秒更新一次,我尝试使用一些json脚本,但我有太多的连接错误。有没有办法更有效地更新该日期?这是我的代码有效,但我立即被阻止。
<!DOCTYPE html>
<html>
<head>
<title>Exchange tiempo real</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
function loadlink(){
$('#precio').load('index.php',function () { //id div a recargar
$(this).unwrap();
});
}
loadlink(); // Recargar valor
setInterval(function(){
loadlink() // tiempo de recarga
}, 15000);
</script>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<style type="text/css">
.precio {
font-family: 'Lato', sans-serif;
}
.titulo {
font-weight: 600;
}
</style>
</head>
<body>
<div id="precio" class="precio">
<?php
// TASA DE CONVERSIÓN
$rate = 1.07;
// CONVERSION TIPO DE CAMBIO USD/MXN
echo "<p class='titulo'>TIPO DE CAMBIO MXN/USD</p>";
$fxrates = json_decode(file_get_contents('http://api.fixer.io/latest?base=USD'),true);
echo $fxrates['rates']['MXN'];
//PRECIOS
echo "<br>";
echo "<p>BITCOIN/USD</p>";
$btcurl = "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT";
$btcjson = json_decode(file_get_contents($btcurl), true);
$btcprice = $btcjson["price"];
echo $btcprice*$rate;
echo "<br>";
echo "<p>XRP/USD</p>";
$xrpurl = "https://api.binance.com/api/v3/ticker/price?symbol=XRPBTC";
$xrpjson = json_decode(file_get_contents($xrpurl), true);
$xrpprice = $xrpjson["price"];
echo $btcprice*$xrpprice*$rate;
?>
</div>
</body>