Giter Club home page Giter Club logo

php-forex-quotes's Introduction

php-forex-quotes

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.

1Forge Data

Table of Contents

Requirements

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 [email protected] if you have any questions or requests.

License and Terms

This library is provided without warranty under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.