PHP Classes

PHP Forex Quotes: Get foreign exchange rates quotes for currencies

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 66 All time: 10,365 This week: 560Up
Version License PHP version Categories
forexquotes 1.0MIT/X Consortium ...5.4Finances, PHP 7
Description 

Author

This package can get foreign exchange rates quotes for currencies.

It can send HTTP requests to the 1forge.com API to get the list of supported currency symbols.

The class can also get quotes for exchange of given currencies.

Picture of Jacob Davis
  Performance   Level  
Name: Jacob Davis <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 4474563 in United States United States
Week rank: 180 Up22 in United States United States Up

Documentation

php-forex-quotes

php-forex-quotes is a PHP Library for fetching realtime forex quotes. See the examples for REST and WebSocket implementation in the /examples folder.

<a href="#">1Forge Data</a>

Table of Contents

Requirements

  • PHP >= 6.0.1
  • An API key which you can obtain for free at http://1forge.com/forex-data-api

Installation

composer require oneforge/forexquotes

Or in your composer.json

"require": {
    "oneforge/forexquotes": "^6.0"
},

Usage

Instantiate the client

<?php

use OneForge\ForexQuotes\ForexDataClient;

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

Get the list of available symbols:

$client->getSymbols(); 

Get quotes for specified symbols:

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

Convert from one currency to another:

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

Check if the market is open:

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

Check your usage / quota limit:

$client->quota();

Stream quote updates:

WebSocket quote streaming is only available on paid plans.

//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();

});

Contributing

Thank you for considering contributing! Any issues, bug fixes, suggestions, improvements or help in any other way is always appreciated. Please feel free to open an issue or create a pull request.

Support and Contact

Please contact me at contact@1forge.com if you have any questions or requests.

License and Terms

This library is provided without warranty under the MIT license.


  Files folder image Files (7)  
File Role Description
Files folder imageexamples (2 files)
Files folder imagelib (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (7)  /  examples  
File Role Description
  Accessible without login Plain text file REST-example.php Example Example script
  Accessible without login Plain text file websocket-example.php Example Example script

  Files folder image Files (7)  /  lib  
File Role Description
  Accessible without login Plain text file ForexDataClient.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:66
This week:0
All time:10,365
This week:560Up