Sooner or later, there will be a day in your developer career when you need to power your web or mobile PHP application with real-time financial data.

How to use a very simple PHP Forex API

Sooner or later, there will be a day in your developer career when you need to power your web or mobile PHP application with real-time financial data.

Sooner or later, there will be a day in your developer career when you need to power your web or mobile PHP application with real-time financial data.

You will find many options that at first glance would seem valid, but would ultimately be invalid because: They are too complex to implement, are not updated as often as you need them (every second) or are expensive.

If this day came for you today, we have very good news. Getting data from our Rest API with PHP is as simple as:

<?php
$url = 'https://www.live-rates.com/rates'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$json = json_decode($data); // decode the JSON feed

foreach($json as $obj){
    if ($obj->currency == 'EUR/USD'){
        echo "Pair: $obj->currency\n";
           echo "Bid: $obj->bid\n";
           echo "Ask: $obj->ask\n";
           echo "Timestamp: $obj->timestamp\n";
    }
}

The previous example would get you updated prices for EUR/USD. If you want to get all the instruments, just comment the line

if ($obj->currency == 'EUR/USD'){

 

If you are looking how to import real-times JSON on your Javascript / Nodejs application, please read our Previous Post - How to Retrieve JSON forex data in Javascript.

Facebook Google LinkedIn Reddit Twitter