oasin/cryptocurrencies-laravel
Composer 安装命令:
composer require oasin/cryptocurrencies-laravel
包简介
Laravel package for cryptocurrencies api service
README 文档
README
Laravel wrapper for the main cryptocurrencies APIs, provides an easy way to use the third-part API. Recover a gateway from the cryptocurrencies Manager and start to query the chosen API.
Requirements
The minimum requirement by Cryptocurrencies API Laravel Manager is Laravel 5.7 installed and your Web server supports PHP 7.1.
Installation
To install Cryptocurrencies API Laravel Manager package you can use a simple composer command.
composer require ilcleme/cryptocurrencies-laravel
Publish Vendor
This step is fundamental to use every API calls. After install the package you could publish the config package file, use this command:
php artisan vendor:publish --provider="Oasin\\Cryptocurrencies\\Providers\\CryptocurrenciesServiceProvider"
Now you can override the default configuration and insert you personal api key for every third-part service.
Architecture
The package contains 3 main objects that have been used to interact with the bees:
- Cryptocurrencies API Manager (
cryptocurrencies.manageris container alias on Laravel); - Gateways, that is objects implemented to query third-party APIs, everyone have a name used to retrive it from manager;
Available gateways:
- For Cryptocompare there are 4 gateways available "out-of-box", one per section available on Cryptocompare docs:
- Cryptocompare "General Information", for every api calls of "general info" section;
- Cryptocompare "Historical data", for every api calls of "Historical data" section;
- Cryptocompare "Price Data", for every api calls of "price" section;
- Cryptocompare "Top list Data", gateway for every api calls of "top list" section;
- For Coinmarketcap it is only an available gateway, through which it is possible to execute every type of request.
Usage
To use the package simply get the Cryptocurrencies API Manager instance from the container. Get the choosen Gateway based on type of query you want to do, for example to "get price of BTC in fiat currencies" use the Cryptocompare "Price Data". Use the gateway methods with right parameters to query the api. For example:
namespace App\Http\Controllers; use Oasin\Cryptocurrencies\Gateways\Cryptocompare\CryptocomparePriceGateway; class CryptoController extends Controller { public function getBTCPrice() { $manager = app('cryptocurrencies.manager'); /** @var CryptocomparePriceGateway $priceGateway */ $priceGateway = $manager->getGateway('price'); //parameters passed to the method are defined in accordance with the Cryptocompare documentation of endpoint $parameters = [ 'fsym' => 'BTC', 'tsyms' => 'USD,JPY,EUR' ]; $result = $priceGateway->getSingleSymbolPrice($parameters); return $result; } }
set a route for this controller and expect to receive a similar response:
{ "USD": 3887.35, "JPY": 412906.65, "EUR": 3399.46 }
To use Coinmarketcap gateway is the same way:
namespace App\Http\Controllers; use Oasin\Cryptocurrencies\Gateways\Coinmarketcap\CoinmarketcapGateway; class CryptoController extends Controller { public function test() { $manager = app('cryptocurrencies.manager'); /** @var CoinmarketcapGateway $coinmarketcapGateway */ $coinmarketcapGateway = $manager->getGateway('coinmarketcap'); //parameters passed to the method are defined in accordance with the Coinmarketcap documentation of endpoint $parameters = [ 'query' => ['id' => '1,2'] ]; $result = $coinmarketcapGateway->send('/v1/cryptocurrency/info', 'GET', $parameters); return $result; } }
Response expected:
{
"status": {
"timestamp": "2019-01-03T11:43:39.871Z",
"error_code": 0,
"error_message": null,
"elapsed": 4,
"credit_count": 1
},
"data": {
"1": {
"urls": {
"website": ["https://bitcoin.org/"],
"twitter": [],
"reddit": ["https://reddit.com/r/bitcoin"],
"message_board": ["https://bitcointalk.org"],
"announcement": [],
"chat": [],
"explorer": [
"https://blockchain.info/",
"https://live.blockcypher.com/btc/",
"https://blockchair.com/bitcoin/blocks"
],
"source_code": ["https://github.com/bitcoin/"]
},
"logo": "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"slug": "bitcoin",
"date_added": "2013-04-28T00:00:00.000Z",
"tags": ["mineable"],
"platform": null,
"category": "coin"
},
"2": {
"urls": {
"website": ["https://litecoin.com"],
"twitter": ["https://twitter.com/LitecoinProject"],
"reddit": ["https://reddit.com/r/litecoin"],
"message_board": ["https://litecointalk.io/"],
"announcement": ["https://bitcointalk.org/index.php?topic=47417.0"],
"chat": ["https://telegram.me/litecoin"],
"explorer": [
"http://explorer.litecoin.net/chain/Litecoin",
"https://chainz.cryptoid.info/ltc/",
"https://live.blockcypher.com/ltc/"
],
"source_code": ["https://github.com/litecoin-project/litecoin"]
},
"logo": "https://s2.coinmarketcap.com/static/img/coins/64x64/2.png",
"id": 2,
"name": "Litecoin",
"symbol": "LTC",
"slug": "litecoin",
"date_added": "2013-04-28T00:00:00.000Z",
"tags": ["mineable"],
"platform": null,
"category": "coin"
}
}
}
Gateway and API Reference
Here there is full api and gateways reference for Cryptocompare API
Here there is full api and gateways reference for Coinmarketcap API
Test
To run the package test you need to install the dev requirements (test tools) and run phpunit from the package folder
composer install --dev
vendor/bin/phpunit tests
if you want a more verbose log use this command
vendor/bin/phpunit --testdox tests
oasin/cryptocurrencies-laravel 适用场景与选型建议
oasin/cryptocurrencies-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「crypto」 「laravel」 「coinmarketcap」 「cryptocompare」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 oasin/cryptocurrencies-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oasin/cryptocurrencies-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 oasin/cryptocurrencies-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
High-level cryptographic primitives and security utilities for Maatify systems including password hashing, reversible encryption, HKDF key derivation, and key rotation.
Simple ASCII output of array data
Alfabank REST API integration
Package for view storage in laravel
User Approval Laravel Package
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-05