Market sentiment dashboard using Curl and PHP

In this article I will show you how to create a little Dashboard of  Market Sentiment results taken on differents IG Trading web-pages. And feed it in a HTML table for Dashboard.

The use of Curl in PHP will permit you to create Dashboard of data from different Websites, in the same page.

DEMO: See it in action: http://www.pc-dream.it/curl.php




Warning: Don't use the following script for Trading! 

Firtly I would like to "read" the market sentiment on IG symbols webpages like the following:

https://www.ig.com/it/indici/mercati-indici/germany-30

Then I need to scrap from each page two informations:
- Percentage of customer wich have positions open Short/long
- Direction of the position: Short or Long


  1. To do so I will use Curl function of PHP. The following script will extract all text of 'ma__title' class, then the symbol name of Index or currency...
  2. You also need to copy and integrate dom parser functions to "read" the html page and extract some text: you can download here: http://simplehtmldom.sourceforge.net/ but you just need to include the following file: simple_html_dom.php in your code.


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url[$x]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);
curl_close($ch);

$html = new simple_html_dom();
$html->load($response);

echo "  <tr>";
echo "<td class='tg-us36'>";
foreach($html->find('.ma__title') as $symbol)
echo "<a href='$url[$x]' target='_blank'>". $symbol->plaintext ."</a>";
echo "</td>";

$symbol=$symbol->plaintext;

Each url you provide in $url[$x] array will be read and the results will be append in  HTML in a FOR LOOP

At each row, you can calculate an action depending of the market sentiment, i.e. if you would like to BUY each time Sentiment percentage is above 70% you can add the following scritp:

foreach($html->find('.information-popup strong') as $result) {
if ($precent<71) {echo 'CLOSE';}
else{
if ($result->plaintext == 'ha posizioni short') echo '<b>SELL</b>';
if ($result->plaintext == 'ha posizioni long') echo '<b>BUY</b>';
}
}

Notice that you can create trading bots in TagUI which can go to your PHP dashboard and read the "Action" and schedule it each hour or 30' ...


FULL CODE SOURCE: https://github.com/adegard/php/blob/master/curl.php



Feel free to ask some question if you have any problem!
Goog Web-scraping!

🎥Macro Recorder TagIE : RPA internet Automation💻 in AutoHotKey

🚩 🚩 🚩 TagIE : https://github.com/adegard/TagIE.ahk