套件發表會

Crypto Monitor

自我介紹

  • Peter

  • GitHub

  • 目前在ITRI服務

  • 後端開發者

  • 3+ years PHP 後端程式開發

  • PHP 5.3 → PHP 7+

  • No framework→Slim→Laravel

  • 2 years 開源專案貢獻者

套件說明

Monitor the crypto currency rate via CoinAPI service.

緣起

這其實是一個合作案

但是,目前只有我做...

PayCrypto

Dependencies

"require": {
        "php" : ">=7.1",
        "scriptfusion/porter": "^4",
        "connectors/http": "^2",
        "joomla/di": "^1"
},
.....

使用方式

申請API Key

Coin API

安裝

composer require paycrypto/crypto-monitor

初始化Instance

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Joomla\DI\Container;
use ScriptFUSION\Porter\Porter;
use PayCrypto\CryptoMonitor;
use PayCrypto\Connector\CryptoConnector;
use PayCrypto\Resource\GetSpecificRate;
use PayCrypto\Resource\GetAllRate;
use PayCrypto\Resource\GetAssets;
use ScriptFUSION\Porter\Specification\ImportSpecification;

Get specific rate

// Get specific rate

$apiKey = 'your-coin-api-key';

$container = new Container;
$container->set(CryptoMonitor::class, 
    new CryptoMonitor(new CryptoConnector($apiKey)));
$porter = new Porter($container);
$specificRate = new GetSpecificRate($apiKey, 'BTC', 'USD');

$rates = $porter->importOne(
    new ImportSpecification($specificRate));

var_dump($rates);

Get specific rate

array(4) {
  'time' =>
  string(28) "2018-07-07T08:40:30.2799370Z"
  'asset_id_base' =>
  string(3) "BTC"
  'asset_id_quote' =>
  string(3) "USD"
  'rate' =>
  double(6579.7459800358)
}

Get all rate

// Get all rates

$container = new Container;
$container->set(CryptoMonitor::class,
    new CryptoMonitor(
    new CryptoConnector($apiKey)));

$porter = new Porter($container);

$specificRate = new GetAllRate($apiKey, 'BTC');

$rates = $porter->import(
    new ImportSpecification($specificRate));

Get all rate

foreach ($rates as $rateRecord) {
    echo $rateRecord['asset_id_quote'] . PHP_EOL;
    echo $rateRecord['rate'] . PHP_EOL;
    echo $rateRecord['time'] . PHP_EOL;
}

Get all rate

ENTER
134271480.5127
2018-07-07T09:07:05.1780475Z
EGOLD
1219512.195122
2018-07-07T09:07:05.1780475Z

Get assets

$container = new Container;
$container->set(CryptoMonitor::class, 
    new CryptoMonitor(
    new CryptoConnector($apiKey)));

$porter = new Porter($container);
$assets = new GetAssets($apiKey);

$assets = $porter->import(
    new ImportSpecification($assets));

Get assets


foreach ($assets as $assetRecord) {
    var_dump($assetRecord['asset_id']);
    var_dump($assetRecord['name']);
    var_dump($assetRecord['type_is_crypto']);
}

Get assets

/home/lee/crypto-monitor/example.php:59:
string(3) "ZDR"
/home/lee/crypto-monitor/example.php:60:
string(3) "ZDR"
/home/lee/crypto-monitor/example.php:61:
int(1)
/home/lee/crypto-monitor/example.php:59:
string(4) "ZEST"
/home/lee/crypto-monitor/example.php:60:
string(4) "ZEST"
/home/lee/crypto-monitor/example.php:61:
int(1)

LICENSE

MIT License

Continuous Integration

Travis CI

Special thanks

Code review

Thanks !

crypto-monitor

By peter279k

crypto-monitor

  • 1,418