DRK/BTC DRK/USD quote

Lzeppelin

Active member
I think it'd be cool if we could get a DRK/BTC or DRK/$CURRENCY quote on this forum. I'm thinking maybe something underneath the user bar and above the path bar. Bonus points for a drop down for other currencies.
 
I think it'd be cool if we could get a DRK/BTC or DRK/$CURRENCY quote on this forum. I'm thinking maybe something underneath the user bar and above the path bar. Bonus points for a drop down for other currencies.

Love the idea. Will definitely look into it. Currently I'm trying to make the forum look better aesthetically as priority number one. Then I have some big plans for this site. Definitely like this idea though!
 
Cool, this coin is so innovative and awesome. I can't wait for the community to grow!

Also almost back up to pre-crash levels :D

Edit: do you mind if I look into this and maybe write up some PHP?
 
Last edited by a moderator:
Sorry for the double post but I have some code, I'll look at it more tomorrow. Basically right now you can see it working on http://162.248.5.147/info.php I have it getting the latest price from poloniex and cryptsy then averaging them. I also have the latest from btc-e and bitstamp to give me a price in USD for DRK. The google currency conversion doesn't do anything yet but it's there so the ground work is set up. Here is my code so far:
PHP:
<?php

  $cryptsyResponse = file_get_contents('http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=155');
  $decoded = json_decode($cryptsyResponse);
  $cryptsyPrice = (double)$decoded->return->markets->DRK->lasttradeprice;

$poloniexResponse = file_get_contents('https://poloniex.com/public?command=returnTicker');

$temp = json_decode($poloniexResponse, true);

$poloniexPrice = (double)$temp['BTC_DRK'];

if (empty($poloniexPrice))
{
$priceInBTC = floatval($cryptsyPrice);
}

if (empty($cryptsyPrice))
{
$priceInBTC = floatval($poloniexPrice);
}

if (!empty($poloniexPrice) && !empty($cryptsyPrice))
{

$priceInBTC = (floatval($poloniexPrice) + floatval($cryptsyPrice)) / 2;
}

echo "BTC/DRK " . $priceInBTC; 

$amount = urlencode(100);
  $from_Currency = urlencode(USD);
  $to_Currency = urlencode(GBP);
  $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
  $get = explode("<span class=bld>",$get);
  $get = explode("</span>",$get[1]);  
  $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);


$BTCeTicker = file_get_contents('https://btc-e.com/api/2/btc_usd/ticker');
$BTCeDecoded = json_decode($BTCeTicker);
$BTCePrice = (double)$BTCeDecoded->ticker->avg;

$bitstampTicker = file_get_contents('https://www.bitstamp.net/api/ticker');
$bitstampDecoded = json_decode($bitstampTicker, true);
$bitstampPrice = (double)$bitstampDecoded['last'];

$bitcoinPrice = (floatval($bitstampPrice) + floatval($BTCePrice)) / 2;
$priceDRKUSD = $priceInBTC * $bitcoinPrice;

echo "<br>";
echo "USD/DRK " . $priceDRKUSD;

?>

feel free to tip me DRK :p
 
Last edited by a moderator:
Very cool idea, thanks LZeppelin, funny my son's new fascination is the Hindenburg, LOL (Yes I know the band ;) )

I sent you a dark, it's not much but I don't have much :( Let us know if we can use this on other sites. I'm planning on selling my husband's short stories for DarkCoin just to get attention for a novel he wrote. But it's not finished yet :) It'd be nice to have this on the site though :)

You must not have your darksend beta up and running, LOL. It didn't send, so I did it again. Hope you get it :)
 
Last edited by a moderator:
Very cool idea, thanks LZeppelin, funny my son's new fascination is the Hindenburg, LOL (Yes I know the band ;) )

I sent you a dark, it's not much but I don't have much :( Let us know if we can use this on other sites. I'm planning on selling my husband's short stories for DarkCoin just to get attention for a novel he wrote. But it's not finished yet :) It'd be nice to have this on the site though :)

You must not have your darksend beta up and running, LOL. It didn't send, so I did it again. Hope you get it :)

Thanks! I'd love it to be used elsewhere. I made some improvements to the script (I also re-imaged my VPS so the live demo probably didn't work :p) anyway here is the code:

I have it broken up into 3 files because that's how the caching tutorial I followed had it but you can put everything in one file if you want.

main.php is:

PHP:
<?php
include('top-cache.php');
  $cryptsyResponse = file_get_contents('http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=155');
  $decoded = json_decode($cryptsyResponse);
  $cryptsyPrice = (double)$decoded->return->markets->DRK->lasttradeprice;
$poloniexResponse = file_get_contents('https://poloniex.com/public?command=returnTicker');
$temp = json_decode($poloniexResponse, true);
$poloniexPrice = (double)$temp['BTC_DRK'];
if (empty($poloniexPrice))
{
$priceInBTC = floatval($cryptsyPrice);
}
if (empty($cryptsyPrice))
{
$priceInBTC = floatval($poloniexPrice);
}
if (!empty($poloniexPrice) && !empty($cryptsyPrice))
{
$priceInBTC = (floatval($poloniexPrice) + floatval($cryptsyPrice)) / 2;
}
echo "BTC/DRK " . $priceInBTC;
$amount = urlencode(100);
  $from_Currency = urlencode(USD);
  $to_Currency = urlencode(GBP);
  $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
  $get = explode("<span class=bld>",$get);
  $get = explode("</span>",$get[1]);
  $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
$BTCeTicker = file_get_contents('https://btc-e.com/api/2/btc_usd/ticker');
$BTCeDecoded = json_decode($BTCeTicker);
$BTCePrice = (double)$BTCeDecoded->ticker->avg;
$bitstampTicker = file_get_contents('https://www.bitstamp.net/api/ticker');
$bitstampDecoded = json_decode($bitstampTicker, true);
$bitstampPrice = (double)$bitstampDecoded['last'];
if (empty($bitstampPrice))
{
$bitcoinPrice = floatval($BTCePrice);
}
if (empty($BTCePrice))
{
$bitcoinPrice = floatval($bitstampPrice);
}
if (!empty($BTCePrice) && !empty($bitstampPrice))
{
$bitcoinPrice = (floatval($bitstampPrice) + floatval($BTCePrice)) / 2;
}
$priceDRKUSD = $priceInBTC * $bitcoinPrice;
echo "<br>";
echo "USD/DRK " . $priceDRKUSD;
include('bottom-cache.php');
?>

top-cache.php is:

PHP:
<?php
$url = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $url);
$file = $break[count($break) - 1];
$cachefile = 'cached-'.substr_replace($file ,"",-4).'.html';
$cachetime = 90;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
    echo "<!-- Cached copy, generated ".date('H:i', filemtime($cachefile))." -->\n";
    include($cachefile);
    exit;
}
ob_start(); // Start the output buffer
?>

bottom-cache.php is:

PHP:
<?php
// Cache the contents to a file
$cached = fopen("$cachefile", 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
?>

You need write permission in the script's directory for the caching to work, which I highly recommend without it you will get banned with any kind of serious load for making too many api calls. Right now the cache is refresh every 90 seconds. This can be used for any other alt with minor code tweaks. Also I have vestigial google currency conversion code in there so you could trivially add currencies.

Sadly this forum software while flashy and sleek does not give you direct access to the templates in PHP rather just in html so for use on this site this has to be re-implemented in javascript, which I might try to help with.

Edit: Actually the name is for LullabyZeppelin, I was looking for a cool screen name on a random generator and it generated that. I liked it and started using it but found it was to long for a bunch of places so I started going by Lzeppelin :p

Edit2: Great idea, I love short stories especially ones of the mindfuck variety ;)
 
Last edited by a moderator:
See? I don't know it all! LullabyZeppelin, that's actually very cool :)
I found this story my hubby wrote on an old drive. written a while ago. we used to play anarchy online, and that was the theme. It's a fan fiction I guess, but fun! maybe you'd take a look?

http://www.steemjammer.com :)
 
I think it'd be cool if we could get a DRK/BTC or DRK/$CURRENCY quote on this forum. I'm thinking maybe something underneath the user bar and above the path bar. Bonus points for a drop down for other currencies.
+1

Any news on this?
 
I'm thinking of doing a full page with a price ticker, mining pools pie charts (@chaeplin), and some other stuff. It will all be hosted on the forums with everything easy to get to.
It's actuality quite involved for something so simple. I'll keep this thread updated!
 
Lzeppelin I know I'm bumping a seriously old thread but I haven't forgot about this. It's still something I'd like to incorporate somehow.

Here's my take on the code before caching. (Just a quick concept)

PHP:
<!DOCTYPE=HTML>
<HTML>
<body>

<h1>Concept Price Ticker from API</h1>

<p>Will incorporate into forums eventually...</p>


<?php

/* Below is the code to pull the darkcoin price from mintpal. */

$mintpal = file_get_contents('https://api.mintpal.com/v1/market/stats/DRK/BTC');
$mintpalDecode = json_decode($mintpal);
$drk2btc = (double)$mintpalDecode[0]->last_price;

/*Below is the code for Coinbase spot price. */

$spotCoinbase = file_get_contents('https://coinbase.com/api/v1/prices/spot_rate');
$spotDecoded = json_decode($spotCoinbase);
$btcUSD = (double)$spotDecoded->{'amount'};

/*Below is the code for retreving a usd amount for Darkcoin and knocking
off decimal places for easy readability. */

$darkUSD = round(($btcUSD * $drk2btc), 2);

/*Below is printing out the data in a human readable format. */
echo "Current Bitcoin Price $" . $btcUSD, "<br>";
echo "Current Darkcoin Price $" . $darkUSD, "<br>";
echo "Current DRK/BTC " . $drk2btc, "<br>";

/*Below is when it was last updated */
echo "<br>";
echo "Updated at " . date('g:ia M d, Y') ."\n";
?>

</body>
</HTML>

It still would need to be cached and have some error checking but it's definitly possible to add at a later date in a form of a widget or header similar to the admin panel header.
 
Back
Top