php-forex-quotes is a 1Forge PHP Library for fetching realtime forex quotes. See the examples for REST and WebSocket implementation in the /examples folder.
- PHP >= 6.0.1
- An API key which you can obtain for free at https://1forge.com/register
composer require oneforge/forexquotes
Or in your composer.json
"require": {
"oneforge/forexquotes": "~6.0"
},
<?php
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();
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();
});
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.
Please contact me at contact@1forge.com if you have any questions or requests.
This library is provided without warranty under the MIT license.