Skip to content
PHP Library for fetching realtime forex quotes.
PHP
Branch: master
Clone or download
bricktownseo Merge pull request #5 from 1Forge/server-updates
Version Change and Socket Server Updated
Latest commit 5f3a0d2 Nov 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Version Change and Socket Server Updated Nov 8, 2019
lib Version Change and Socket Server Updated Nov 8, 2019
.gitignore WebSocket Support Jan 9, 2018
LICENSE.md Rename license.md to LICENSE.md Jun 4, 2017
README.md Version Change and Socket Server Updated Nov 8, 2019
composer.json Version Change and Socket Server Updated Nov 8, 2019
composer.lock

README.md

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.

1Forge Data

Table of Contents

Requirements

Installation

composer require oneforge/forexquotes

Or in your composer.json

"require": {
    "oneforge/forexquotes": "3.1.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([
    'AUDUSD',
    'GBPJPY'
]);

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["bid"] . " " .$data["ask"] . " " . $data["price"]."\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('EURUSD');

    //Subscribe to an array of currency pairs
    $client->subscribeTo([
        'GBPJPY',
        'AUDCAD',
        'EURCHF'
    ]);

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

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

    //Unsubscribe from an array of currency pairs
    $client->unsubscribeFrom([
        'GBPJPY',
        'AUDCAD',
        'EURCHF'
    ]);

    //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.

You can’t perform that action at this time.