BTC-e API - 无响应

时间:2013-11-30 03:38:21

标签: php api

这是我从BTC-e API获取买入和卖出价值的原因。 http://btc-e.com/api/documentation/

<?
function GetJsonFeed($json_url)
{
    $feed = file_get_contents($json_url);
    return json_decode($feed, true);
}
$LTC_USD = GetJsonFeed("https://btc-e.com/api/2/ltc_usd/ticker");
$LTC_USD_BUY = $LTC_USD["ticker"]["buy"];
$LTC_USD_SELL = $LTC_USD["ticker"]["sell"];

echo "Buy: $LTC_USD_BUY";
echo "Sell: $LTC_USD_SELL";
?>

然而,它似乎没有起作用。

1 个答案:

答案 0 :(得分:0)

<?php
function getTicker($type1, $type2, $cmd)
{
    if ($type1 && $type2 && $cmd) {
        $jurl="https://btc-e.com/api/2/".$type1."_".$type2."/ticker";
        $j=file_get_contents($jurl,0,null,null);$v=json_decode($j,true);
        return $v['ticker'][$cmd];
    } else {return 0;}
}

//Examples
$EUR_LTC = getTicker("ltc", "eur", "avg");
$EUR_BTC = getTicker("btc", "eur", "avg");
$USD_LTC = getTicker("ltc", "usd", "avg");
$USD_BTC = getTicker("btc", "usd", "avg");
$BTC_LTC = getTicker("ltc", "btc", "avg");
echo 'Euro to LTC: '.$EUR_LTC;
echo 'Euro to BTC: '.$EUR_BTC;
echo 'USD to LTC: '.$USD_LTC;
echo 'USD to BTC: '.$USD_BTC;
echo 'BTC to LTC: '.$BTC_LTC;
?>