PHP code example of oneforge / forexquotes

1. Go to this page and download the library: Download oneforge/forexquotes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oneforge / forexquotes example snippets




use OneForge\ForexQuotes\ForexDataClient;

//You can get an API key for free at 1forge.com
$client = new ForexDataClient('YOUR_API_KEY');

$client->getSymbols(); 

$client->getQuotes([
    'AUD/USD',
    'GBP/JPY'
]);

$client->convert('USD', 'EUR', 100);

if ($client->marketIsOpen())
{
    echo "Market is open";    
}

$client->quota();

//Handle incoming price updates from the server
$client->onUpdate(function($symbol, $data)
{
    echo $symbol . ": " . $data["b"] . " " .$data["a"] . " " . $data["p"]."\n";
});

//Handle non-price update messages
$client->onMessage(function($message)
{
    echo $message;
});

//Connect to the server
$client->connect(function($client)
{
    //Subscribe to a single currency pair
    $client->subscribeTo('EUR/USD');

    //Subscribe to an array of currency pairs
    $client->subscribeTo([
        'GBP/JPY',
        'AUD/CAD',
        'EUR/CHF'
    ]);

    //Subscribe to all currency pairs
    $client->subscribeToAll();

    //Unsubscribe from a single currency pair
    $client->unsubscribeFrom('EUR/USD');

    //Unsubscribe from an array of currency pairs
    $client->unsubscribeFrom([
        'GBP/JPY',
        'AUD/CAD',
        'EUR/CHF'
    ]);

    //Unsubscribe from all currency pairs
    $client->unsubscribeFromAll();

});