Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $price = array();
- $volume = array(); //24 hours
- //
- // Atomic
- //
- $atomicQuery = file_get_contents("https://nxt-e.com/api/stats/?coin=gpu&exchange=btc");
- if (isset($atomicQuery) AND $atomicQuery != "" AND $atomicQuery != false){
- $atomicData = json_decode($atomicQuery, true);
- if (isset($atomicData["CurrentPrice"]) AND $atomicData["CurrentPrice"] != "" AND $atomicData["CurrentPrice"] != 0){
- $price["atomic"] = $atomicData["CurrentPrice"];
- if ($verbose) { echo "Atomic Price :".$price["atomic"]."<br/>"; }
- $update = array("exchangePrice" => $price["atomic"]);
- $db->update("exchange", $update, "exchangeID = 2");
- }
- if (isset($atomicData["ExchangeVol24h"]) AND $atomicData["ExchangeVol24h"] != "" AND $atomicData["ExchangeVol24h"] != 0){ $volume["atomic"] = $atomicData["ExchangeVol24h"];
- if ($verbose) { echo "Atomic Volume :".$atomicData["ExchangeVol24h"]."<br/>"; }
- $update = array("exchangeVolume" => $volume["atomic"]);
- $db->update("exchange", $update, "exchangeID = 2");
- }
- }
- //
- // Bittrex
- //
- $bittrexQuery = file_get_contents("https://www.bittrex.com/api/v1/public/GetTicker?market=BTC-GPUC");
- if (isset($bittrexQuery) AND $bittrexQuery != "" AND $bittrexQuery != false){
- $bittrexData = json_decode($bittrexQuery, true);
- if (isset($bittrexData["result"]["Ask"]) AND $bittrexData["result"]["Ask"] != "" AND $bittrexData["result"]["Ask"] != 0){ $price["bittrex"] = $bittrexData["result"]["Ask"];
- if ($verbose) { echo "Bittrex Price :".$price["bittrex"]."<br/>"; }
- $update = array("exchangePrice" => $price["bittrex"]);
- $db->update("exchange", $update, "exchangeID = 3");
- }
- }
- $bittrexQuery2 = file_get_contents("https://bittrex.com/api/v1/public/getmarketsummaries");
- if (isset($bittrexQuery2) AND $bittrexQuery2 != "" AND $bittrexQuery2 != false){
- $bittrexData = json_decode($bittrexQuery2, true);
- foreach ($bittrexData["result"] as $bittrexItem){
- if ($bittrexItem["MarketName"] == "BTC-GPUC"){
- if (isset($bittrexItem["BaseVolume"]) AND $bittrexItem["BaseVolume"] != "" AND $bittrexItem["BaseVolume"] != 0){
- $volume["bittrex"] = $bittrexItem["BaseVolume"];
- if ($verbose) { echo "Bittrex Volume :".$bittrexItem["BaseVolume"]."<br/>"; }
- $update = array("exchangeVolume" => $volume["bittrex"]);
- }
- }
- }
- }
- //
- // Nxt - e
- //
- $nxteQuery = file_get_contents("https://nxt-e.com/api/stats/?coin=gpu&exchange=btc");
- if (isset($nxteQuery) AND $nxteQuery != "" AND $nxteQuery != false){
- $nxteData = json_decode($nxteQuery, true);
- if (isset($nxteData["CurrentPrice"]) AND $nxteData["CurrentPrice"] != "" AND $nxteData["CurrentPrice"] != 0){
- $price["nxte"] = $nxteData["CurrentPrice"];
- if ($verbose) { echo "Nxt-e Price :".$price["nxte"]."<br/>"; }
- $update = array("exchangePrice" => $price["nxte"]);
- $db->update("exchange", $update, "exchangeID = 4");
- }
- if (isset($nxteData["ExchangeVol24h"]) AND $nxteData["ExchangeVol24h"] != "" AND $nxteData["ExchangeVol24h"] != 0){
- $volume["nxte"] = $nxteData["ExchangeVol24h"];
- if ($verbose) { echo "Nxte Volume :".$nxteData["ExchangeVol24h"]."<br/>"; }
- $update = array("exchangeVolume" => $volume["nxte"]);
- $db->update("exchange", $update, "exchangeID = 4");
- }
- }
- //
- // Coinbase = Bitcoin
- //
- $coinbaseQuery = file_get_contents("https://coinbase.com/api/v1/prices/sell");
- if (isset($coinbaseQuery) AND $coinbaseQuery != "" AND $cryptorushQuery != false){
- $coinbaseData = json_decode($coinbaseQuery, true);
- if (isset($coinbaseData["total"]["amount"]) AND $coinbaseData["total"]["amount"] != "" AND $coinbaseData["total"]["amount"] != 0){
- $btc = $coinbaseData["total"]["amount"];
- $update = array("exchangePrice" => $btc);
- $db->update("exchange", $update, "exchangeID = 6");
- } else {
- $btc = 0;
- }
- }
- $final_price = 0;
- $average = 0;
- $total_volume = 0;
- $sources = 0;
- foreach ($price as $priceSource => $priceValue){
- $total = $total+$priceValue;
- $sources++;
- }
- foreach ($volume as $volumeSource => $volumeValue){
- $total_volume = $total+$volumeValue;
- }
- $total2 = 0;
- $sources2 = 0;
- reset($price);
- if ($total != 0 AND $sources !=0 ){
- $average = $total/$sources;
- //handle any outliers
- foreach ($price as $priceSource => $priceValue){
- if (($priceValue-$average) > 5 || (($priceValue-$average)*-1) > 5){
- //skip - it deviates to far from the norm
- } else {
- $total2 += $priceValue;
- $sources2++;
- }
- }
- }
- if ($total != 0 AND $sources !=0 ){
- $final_price = $total2/$sources2;
- if ($final_price < $average){
- $final_price = $average;
- }
- //insert total total
- $update = array("exchangePrice" => $final_price,"exchangeVolume" => $total_volume);
- $db->update("exchange", $update, "exchangeID = 1"); //total
- //update productPriceGPUC
- $products = $db->select("product","productActive=1");
- if (isset($products) AND is_array($products) AND count($products) > 0){
- if ($verbose) { echo "Bitcoin @ ".$btc."<br/>"; }
- if ($btc > 300){
- foreach ($products as $product){
- $btcConversion = $product["productPriceUSD"]/$btc; //300/600 = .5
- $gpuConversion = $btcConversion/$final_price;
- if ((int)$gpuConversion >= 1000){
- $update = array("productPriceGPUC" => (int)$gpuConversion);
- $bind = array(":productID" => $product["productID"]);
- $db->update("product", $update, "productID = :productID",$bind);
- if ($verbose) { echo $product["productName"]."[".$product["productPriceUSD"]."] @ ".$final_price." = ".$gpuConversion."<br/>"; }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment