Skip to content

Instantly share code, notes, and snippets.

@zinntikumugai
Created December 14, 2018 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zinntikumugai/1ff8ae055177a74008230a6984d811bb to your computer and use it in GitHub Desktop.
Save zinntikumugai/1ff8ae055177a74008230a6984d811bb to your computer and use it in GitHub Desktop.

BELL/JPY

install

composer require mpyw/co:^1.5

run

php index.php
<?php
//$ composer require mpyw/co:^1.5
require __DIR__ . '/vendor/autoload.php';
use mpyw\Co\Co;
use mpyw\Co\CURLException;
function curl($url, $ops = []) {
$ch = curl_init();
curl_setopt_array($ch,
array_replace([
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
], $ops));
return $ch;
}
$urls = [
"bitebtc"=> function(){
$data = yield curl("https://bitebtc.com/api/v1/ticker/?market=BELL_btc");
return json_decode($data)->result;
},
"bitflyer" => function() {
$data = yield curl("https://api.bitflyer.com/v1/ticker");
return json_decode($data);
}
];
$datas = Co::wait($urls);
/*
bell -> btc
btc -> jpy
*/
$price = $datas["bitebtc"]->price;
$price *= $datas["bitflyer"]->ltp;
echo $datas["bitebtc"]->price." bell/btc".PHP_EOL;
echo $datas["bitflyer"]->ltp." btc/jpy".PHP_EOL;
echo $price." JPY";
@zinntikumugai
Copy link
Author

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment