Reputation: 13
After apiv2.bitcoinaverage.com
is not free anymore i need an other solution.
I want convert an x BTC Amount
into USD from current rate.
My Old Code:
$getrate = "https://apiv2.bitcoinaverage.com/convert/global?from=BTC&to=USD&amount=0.005";
$btcprice = array(
'price' =>
array(
'method' => 'GET',
)
);
$priceone = stream_context_create($btcprice);
$pricetwo = file_get_contents($getrate, false, $priceone);
$result = json_decode($pricetwo, true);
Can i do the same with api from https://alternative.me/crypto/api/ ?
Many Thanks
Upvotes: 1
Views: 3627
Reputation: 1391
You can do following, according to the documentation:
<?php
$getrate = "https://api.alternative.me/v2/ticker/?convert=USD";
$price = file_get_contents($getrate);
$result = json_decode($price, true);
// BTC in USD
$result = $result['data'][1]['quotes']['USD']['price'];
$quantity = 0.005;
$value = $quantity * $result;
echo 'value : ' . $value;
note(thx @AndreasHassing): if you only want Bitcoin data in the json response, use:
$getrate = "https://api.alternative.me/v2/ticker/bitcoin/?convert=USD";
Upvotes: 3