Just back from some hours sleep...
Actually I'm using the highest bid price from coinmarket.io but want to use latest trade price. Any idea how I can grab it?
For the amount of mined coins I'm using
http://explorer.klondikecoin.com/chain/KlondikeCoin/q/totalbcAnd BTC/USD:
http://api.bitcoinaverage.com/ticker/global/USD/(last)
atm I get the following error when my cron job tries to update prices of the other coins from Cryptsy:
PHP Warning: file_get_contents(http://pubapi.cryptsy.com/api.php?method=marketdatav2): failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway
Think Cryptsy has kicked my IP. Ive opened a ticket, hope they will allow. Ive offed some advertisement link.
Looks like the same data as me except I'm using the average bid/ask price.
You can get the latest price like this: check out
http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('https://www.coinmarket.io/market/KDCBTC');
$last_price = $html->find('.ticker-KDCBTC', 0);
echo $last_price->innertext;
The code I'm using for the market cap page on my site is below in case any of it is useful. I'm not using cron but instead caching the requests for max 30 sec which is why it is slow on the first load.
function is_cached($file) {
if (file_exists($file)) {
$created = filemtime($file);
return ((time() - $created) < 30);
} else {
return false;
}
}
if (is_cached('kdc-market-cap.json')) {
$data = json_decode(file_get_contents('kdc-market-cap.json'), true);
$usd = $data['usd'];
$btc = $data['btc'];
} else {
$orderbook = json_decode(file_get_contents('https://www.coinmarket.io/ajax/orderbook/KDCBTC'), true);
$total_mined = file_get_contents('http://explorer.klondikecoin.com/chain/klondikecoin/q/totalbc');
$usd_btc = json_decode(strtok(file_get_contents('http://api.bitcoinaverage.com/ticker/global/USD/'), '}') . '}', true);
$btc = ($orderbook['orders']['askprice'] + $orderbook['orders']['bidprice']) / 2 * $total_mined;
$usd = '$' . number_format($usd_btc['last'] * $btc, 2);
$data = json_encode(Array('btc' => $btc, 'usd' => $usd));
file_put_contents('kdc-market-cap.json', $data);
}
Found this re: Cryptsy API:
Security Note: Since implementation of our new security layer, some API clients are getting denied access. If possible, you should program your bot to accept cookies to pass the security test. If you are still unable to connect, then contact us with your IP address so that we may whitelist your application.
Probably best to use CURL as answered here:
http://stackoverflow.com/questions/1797510/file-get-contents-receive-cookies or just get them to whitelist you.