horisystems/fxdatapi

该SDK为用PHP编程语言编写的应用程序提供了方便的访问货币API的方法。

v1.0.9 2023-10-28 15:55 UTC

This package is auto-updated.

Last update: 2024-09-28 18:00:12 UTC


README

Build Status Latest Stable Version Total Downloads License

该SDK为用PHP编程语言编写的应用程序提供了方便的访问货币API的方法。

要求

PHP 7.x.x 及以上版本。

依赖

该库需要以下扩展才能正常工作

如果您使用Composer,这些依赖项应该会自动处理。如果您手动安装,请确保这些扩展可用。

开发

有关在macOS、Linux、Unix和Windows上安装Composer的说明,请参阅此处

安装依赖项

composer install

安装

通过运行以下命令安装货币API PHP SDK:

composer require horisystems/fxdatapi

使用示例

## create a file called currency_api.php
<?php
use Fxdatapi\Fxdatapi;

// Initialize the Fxdatapi SDK
$fxdatapi = new Fxdatapi();

// Set your username and password for the Currency API
$username = 'your_username';
$password = 'your_password';

// Log in to the API and obtain a token (if necessary)
$loginResult = $fxdatapi->login($username, $password);
if ($loginResult) {
    echo "Login successful.\n";
} else {
    die("Login failed.\n");
}

// Set currency conversion details
$date = '2023_04_05';
$baseCurrency = 'GBP';
$targetCurrency = 'EUR';
$amount = 1000;

// Set the date for which you want to retrieve the currencies
$day = '05';
$month = '04';
$year = '2023';

// Set the UUID of the currency you want to retrieve
$uuid = 'currency_uuid';

// Set the date for which you want to retrieve the daily average
$dailyAverageDate = '2023_04_10';

// Set the date range for which you want to retrieve the weekly average
$weeklyAverageFromDate = '2023_04_03';
$weeklyAverageToDate = '2023_04_07';

// Set the UUID of the performance you want to retrieve
$performanceId = 'performance_id';

// Set the UUID of the signal you want to retrieve
$signalId = 'signal_id';

// Call the convert method to perform the currency conversion
$conversionResult = $fxdatapi->convert($username, $date, $baseCurrency, $targetCurrency, $amount);
if ($conversionResult) {
    echo "Conversion result: " . json_encode($conversionResult) . "\n";
} else {
    echo "Currency conversion failed: " . $conversionResult['error'] . "\n";
}

// Call the convertAll method to convert the base currency to all available target currencies
$convertAllResult = $fxdatapi->convertAll($username, $baseCurrency, $amount, $date);
if ($convertAllResult) {
    echo "Conversion to all currencies successful:\n";
    echo json_encode($convertAllResult) . "\n";
} else {
    echo "Conversion to all currencies failed: " . $convertAllResult['error'] . "\n";
}

// Call the getCurrencies method to get the available currencies for the given date
$currenciesResult = $fxdatapi->getCurrencies($username, $day, $month, $year);
if ($currenciesResult) {
    echo "Currencies for " . $day . "/" . $month . "/" . $year . ":\n";
    echo json_encode($currenciesResult) . "\n";
} else {
    echo "Failed to retrieve currencies for the given date.\n";
}

// Call the getCurrency method to get the details of the specific currency for the given date
$currencyResult = $fxdatapi->getCurrency($uuid, $username, $day, $month, $year);
if ($currencyResult) {
    echo "Currency details for " . $day . "/" . $month . "/" . $year . ":\n";
    echo json_encode($currencyResult) . "\n";
} else {
    echo "Failed to retrieve currency details for the given date.\n";
}

// Call the getHistoricalData method to get historical data for all currencies for the given date
$historicalDataResult = $fxdatapi->getHistoricalData($username, $date, $day, $month, $year);
if ($historicalDataResult) {
    echo "Historical data for " . $date . ":\n";
    echo json_encode($historicalDataResult) . "\n";
} else {
    echo "Failed to retrieve historical data for the given date.\n";
}

// Call the getHistoricalDataForCurrency method to get historical data for a specific currency
$historicalDataForCurrencyResult = $fxdatapi->getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date);
if ($historicalDataForCurrencyResult) {
    echo "Historical data for currency " . $uuid . " on " . $date . ":\n";
    echo json_encode($historicalDataForCurrencyResult) . "\n";
} else {
    echo "Failed to retrieve historical data for the given currency and date.\n";
}

// Call the getDailyAverage method to get the daily average for the given date
$dailyAverageResult = $fxdatapi->getDailyAverage($dailyAverageDate);
if ($dailyAverageResult) {
    echo "Daily average for " . $dailyAverageDate . ":\n";
    echo json_encode($dailyAverageResult) . "\n";
} else {
    echo "Failed to retrieve daily average for the given date.\n";
}

// Call the getWeeklyAverage method to get the weekly average for the given date range
$weeklyAverageResult = $fxdatapi->getWeeklyAverage($weeklyAverageFromDate, $weeklyAverageToDate);
if ($weeklyAverageResult) {
    echo "Weekly average from " . $weeklyAverageFromDate . " to " . $weeklyAverageToDate . ":\n";
    echo json_encode($weeklyAverageResult) . "\n";
} else {
    echo "Failed to retrieve weekly average for the given date range.\n";
}

// Call the getMonthlyAverage method to get the monthly average for the given year and month
$monthlyAverageResult = $fxdatapi->getMonthlyAverage($monthlyAverageYear, $monthlyAverageMonth);
if ($monthlyAverageResult) {
    echo "Monthly average for " . $monthlyAverageYear . " and " . $monthlyAverageMonth . ":\n";
    echo json_encode($monthlyAverageResult) . "\n";
} else {
    echo "Failed to retrieve monthly average for the given year and month.\n";
}

// Call the getMarginsSpreads method to get the margins and spreads for the given date
$marginsSpreadsResult = $fxdatapi->getMarginsSpreads($username, $day, $month, $year);
if ($marginsSpreadsResult) {
    echo "Margins and spreads for " . $day . "/" . $month . "/" . $year . ":\n";
    echo json_encode($marginsSpreadsResult) . "\n";
} else {
    echo "Failed to retrieve margins and spreads for the given date.\n";
}

// Call the getMarginSpread method to get the details of the specific margin or spread for the given date
$marginSpreadResult = $fxdatapi->getMarginSpread($uuid, $username, $day, $month, $year);
if ($marginSpreadResult) {
    echo "Margin or spread details for " . $day . "/" . $month . "/" . $year . ":\n";
    echo json_encode($marginSpreadResult) . "\n";
} else {
    echo "Failed to retrieve margin or spread details for the given date.\n";
}

// Call the getAllPerformances method to get all performances
$getAllPerformancesResult = $fxdatapi->getAllPerformances($username);
if ($getAllPerformancesResult) {
    echo "Performances list:\n";
    echo json_encode($getAllPerformancesResult) . "\n";
} else {
    echo "Failed to retrieve performances.\n";
}

// Call the getPerformanceById method to get the details of a specific performance
$getPerformanceByIdResult = $fxdatapi->getPerformanceById($performanceId, $username);
if ($getPerformanceByIdResult) {
    echo "Performance details for " . $performanceId . ":\n";
    echo json_encode($getPerformanceByIdResult) . "\n";
} else {
    echo "Failed to retrieve performance details for the given ID.\n";
}

// Call the getAllSignals method to get all signals
$getAllSignalsResult = $fxdatapi->getAllSignals($username);
if ($getAllSignalsResult) {
    echo "Signals list:\n";
    echo json_encode($getAllSignalsResult) . "\n";
} else {
    echo "Failed to retrieve signals.\n";
}

// Call the getSignalById method to get the details of a specific signal
$getSignalByIdResult = $fxdatapi->getSignalById($signalId, $username);
if ($getSignalByIdResult) {
    echo "Signal details for " . $signalId . ":\n";
    echo json_encode($getSignalByIdResult) . "\n";
} else {
    echo "Failed to retrieve signal details for the given ID.\n";
}

?>

执行 currency_api.php 文件

php currency_api.php

设置货币API账户

在此订阅用户账户。

使用货币API

您可以通过阅读API文档来了解货币API的功能。如需进一步帮助,请随时联系我们

许可证

本项目受BSD 3-Clause License许可。

版权

版权所有 (c) 2023 Hori Systems Limited