- Update Bourse
This commit is contained in:
parent
3db34568c5
commit
fc2abd5bac
4 changed files with 70 additions and 52 deletions
|
|
@ -419,6 +419,8 @@ function catLink($cat_id) {
|
|||
|
||||
// CRON à mettre dans crons/FinancialIntraday.php avec */15 9-18 * * * (toutes les 15 min entre 9h et 18h, on ne peut pas faire 17h30 mais gérer dans le code.)
|
||||
|
||||
// CRON à mettre dans crons/FinancialStock.php avec */15 9-18 * * * (toutes les 15 min entre 9h et 18h, on ne peut pas faire 17h30 mais gérer dans le code.)
|
||||
|
||||
// CRON à mettre dans crons/FinancialHistory.php avec 0 4 * * * (tous les jours à 4H)
|
||||
|
||||
//AJAX pour récupérer les données de l'action en fonction de la période pour les afficher dans un chartJS
|
||||
|
|
@ -428,13 +430,9 @@ add_action( 'wp_ajax_nopriv_getGraphData', 'getGraphData' );
|
|||
function getFinancialHistoryDatasByPeriod($period = false)
|
||||
{
|
||||
global $wpdb;
|
||||
if ($period){
|
||||
if ($period === "5"){
|
||||
return $wpdb->get_results("SELECT * FROM wp_financialdata_history LIMIT 5");
|
||||
}
|
||||
return $wpdb->get_results("SELECT * FROM wp_financialdata_history WHERE date > CURDATE() - INTERVAL $period DAY");
|
||||
}
|
||||
return $wpdb->get_results("SELECT * FROM wp_financialdata_history");
|
||||
if ($period)
|
||||
return $wpdb->get_results("SELECT * FROM wp_financialdata_history WHERE date >= CURDATE() - INTERVAL $period DAY ORDER BY date DESC");
|
||||
return $wpdb->get_results("SELECT * FROM wp_financialdata_history ORDER BY date DESC");
|
||||
}
|
||||
|
||||
function getGraphData(){
|
||||
|
|
|
|||
|
|
@ -24,17 +24,17 @@
|
|||
<div class="heading-financial">
|
||||
<h4>Financial Data : LOUP.PA (LDC SA)</h4>
|
||||
<h4><?= number_format($price, 2); ?> <span style="font-size:18px; font-weight:normal;">EUR</span>
|
||||
<?php if(strpos($change, '-') === false){ ?>
|
||||
<?php if(strpos($change, '-') === false): ?>
|
||||
<span style='color:green;font-size:20px; font-weight:normal;'><?= number_format($change, 2); ?>€ (<?= $change_percent; ?>)</span>
|
||||
<?php } else { ?>
|
||||
<?php else: ?>
|
||||
<span style='color:red;font-size:20px; font-weight:normal;'><?= number_format($change, 2); ?>€ (<?= $change_percent; ?>)</span>
|
||||
<?php } ?>
|
||||
<?php endif; ?>
|
||||
<br/>
|
||||
<span style="font-size:18px; font-weight:normal;"><?= wp_date("d/m/Y H:i:s"); ?> (UTC+2)</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<div class="butt" data-period='intraday'>1 Jour</div>
|
||||
<!--<div class="butt" data-period='intraday'>1 Jour</div>-->
|
||||
<div class="butt active" data-period='5'>5 Jours</div>
|
||||
<div class="butt" data-period='30'>1 mois</div>
|
||||
<div class="butt" data-period='182'>6 mois</div>
|
||||
|
|
|
|||
|
|
@ -78,47 +78,6 @@ function getIntradayData() {
|
|||
]
|
||||
);
|
||||
}
|
||||
|
||||
$baseUrl = 'https://www.alphavantage.co/query?apikey=' . $token . '&function=GLOBAL_QUOTE&symbol=LOUP.PA';
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $baseUrl);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (!curl_errno($ch)) {
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($http_code !== 200) {
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Code HTTP de l\'erreur : ' . $http_code);
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Erreur cURL');
|
||||
die();
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$stock = json_decode($response, true);
|
||||
|
||||
if (!isset($stock['Global Quote'])) {
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Champs requis manquant.');
|
||||
return;
|
||||
}
|
||||
|
||||
$wpdb->replace(
|
||||
'wp_financialdata',
|
||||
array(
|
||||
'name' => 'stock',
|
||||
'data' => json_encode($stock['Global Quote']),
|
||||
),
|
||||
array(
|
||||
'%s',
|
||||
'%s',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function email($email, $subject, $message)
|
||||
|
|
|
|||
61
crons/FinancialStock.php
Normal file
61
crons/FinancialStock.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
require_once(__DIR__ . '/../wp-load.php');
|
||||
|
||||
getStockDatas();
|
||||
|
||||
function getStockDatas()
|
||||
{
|
||||
if (date('H:i:s') > date('H:i:s', strtotime('17:30:00')))
|
||||
return;
|
||||
|
||||
global $wpdb;
|
||||
$token = "A0RACEYVTKIGRF5M";
|
||||
|
||||
$baseUrl = 'https://www.alphavantage.co/query?apikey=' . $token . '&function=GLOBAL_QUOTE&symbol=LOUP.PA';
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $baseUrl);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (!curl_errno($ch)) {
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($http_code !== 200) {
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Code HTTP de l\'erreur : ' . $http_code);
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Erreur cURL');
|
||||
die();
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$stock = json_decode($response, true);
|
||||
|
||||
if (!isset($stock['Global Quote'])) {
|
||||
email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Champs requis manquant.');
|
||||
return;
|
||||
}
|
||||
|
||||
$wpdb->replace(
|
||||
'wp_financialdata',
|
||||
array(
|
||||
'name' => 'stock',
|
||||
'data' => json_encode($stock['Global Quote']),
|
||||
),
|
||||
array(
|
||||
'%s',
|
||||
'%s',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function email($email, $subject, $message)
|
||||
{
|
||||
$headers[] = 'From: Groupe LDC <nepasrepondre@ldc.fr>';
|
||||
wp_mail($email, $subject, $message, $headers);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue