oneforge/forexquotes

库用于获取并解析实时外汇报价和货币转换

6.1.2 2022-08-10 18:49 UTC

README

php-forex-quotes 是一个用于获取实时外汇报价的 1Forge PHP 库。请参阅 /examples 文件夹中的 REST 和 WebSocket 实现示例。

1Forge Data

目录

需求

安装

composer require oneforge/forexquotes

或者在您的 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 报价流式传输仅适用于付费计划。

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

});

贡献

感谢您考虑贡献!任何问题、错误修复、建议、改进或其他任何形式的帮助都将受到欢迎。请随时打开一个问题或创建一个 pull request。

支持和联系

如果您有任何问题或请求,请通过 contact@1forge.com 联系我。

许可和条款

此库在 MIT 许可证下提供,没有任何保证。