Guest User

Untitled

a guest
Mar 27th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. $price = array();
  2. $volume = array(); //24 hours
  3.  
  4. //
  5. // Atomic
  6. //
  7. $atomicQuery = file_get_contents("https://nxt-e.com/api/stats/?coin=gpu&exchange=btc");
  8. if (isset($atomicQuery) AND $atomicQuery != "" AND $atomicQuery != false){
  9. $atomicData = json_decode($atomicQuery, true);
  10. if (isset($atomicData["CurrentPrice"]) AND $atomicData["CurrentPrice"] != "" AND $atomicData["CurrentPrice"] != 0){
  11. $price["atomic"] = $atomicData["CurrentPrice"];
  12. if ($verbose) { echo "Atomic Price :".$price["atomic"]."<br/>"; }
  13. $update = array("exchangePrice" => $price["atomic"]);
  14. $db->update("exchange", $update, "exchangeID = 2");
  15. }
  16. if (isset($atomicData["ExchangeVol24h"]) AND $atomicData["ExchangeVol24h"] != "" AND $atomicData["ExchangeVol24h"] != 0){ $volume["atomic"] = $atomicData["ExchangeVol24h"];
  17. if ($verbose) { echo "Atomic Volume :".$atomicData["ExchangeVol24h"]."<br/>"; }
  18. $update = array("exchangeVolume" => $volume["atomic"]);
  19. $db->update("exchange", $update, "exchangeID = 2");
  20. }
  21. }
  22.  
  23. //
  24. // Bittrex
  25. //
  26. $bittrexQuery = file_get_contents("https://www.bittrex.com/api/v1/public/GetTicker?market=BTC-GPUC");
  27. if (isset($bittrexQuery) AND $bittrexQuery != "" AND $bittrexQuery != false){
  28. $bittrexData = json_decode($bittrexQuery, true);
  29. if (isset($bittrexData["result"]["Ask"]) AND $bittrexData["result"]["Ask"] != "" AND $bittrexData["result"]["Ask"] != 0){ $price["bittrex"] = $bittrexData["result"]["Ask"];
  30. if ($verbose) { echo "Bittrex Price :".$price["bittrex"]."<br/>"; }
  31. $update = array("exchangePrice" => $price["bittrex"]);
  32. $db->update("exchange", $update, "exchangeID = 3");
  33. }
  34. }
  35. $bittrexQuery2 = file_get_contents("https://bittrex.com/api/v1/public/getmarketsummaries");
  36. if (isset($bittrexQuery2) AND $bittrexQuery2 != "" AND $bittrexQuery2 != false){
  37. $bittrexData = json_decode($bittrexQuery2, true);
  38. foreach ($bittrexData["result"] as $bittrexItem){
  39. if ($bittrexItem["MarketName"] == "BTC-GPUC"){
  40. if (isset($bittrexItem["BaseVolume"]) AND $bittrexItem["BaseVolume"] != "" AND $bittrexItem["BaseVolume"] != 0){
  41. $volume["bittrex"] = $bittrexItem["BaseVolume"];
  42. if ($verbose) { echo "Bittrex Volume :".$bittrexItem["BaseVolume"]."<br/>"; }
  43. $update = array("exchangeVolume" => $volume["bittrex"]);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. //
  50. // Nxt - e
  51. //
  52. $nxteQuery = file_get_contents("https://nxt-e.com/api/stats/?coin=gpu&exchange=btc");
  53. if (isset($nxteQuery) AND $nxteQuery != "" AND $nxteQuery != false){
  54. $nxteData = json_decode($nxteQuery, true);
  55. if (isset($nxteData["CurrentPrice"]) AND $nxteData["CurrentPrice"] != "" AND $nxteData["CurrentPrice"] != 0){
  56. $price["nxte"] = $nxteData["CurrentPrice"];
  57. if ($verbose) { echo "Nxt-e Price :".$price["nxte"]."<br/>"; }
  58. $update = array("exchangePrice" => $price["nxte"]);
  59. $db->update("exchange", $update, "exchangeID = 4");
  60. }
  61. if (isset($nxteData["ExchangeVol24h"]) AND $nxteData["ExchangeVol24h"] != "" AND $nxteData["ExchangeVol24h"] != 0){
  62. $volume["nxte"] = $nxteData["ExchangeVol24h"];
  63. if ($verbose) { echo "Nxte Volume :".$nxteData["ExchangeVol24h"]."<br/>"; }
  64. $update = array("exchangeVolume" => $volume["nxte"]);
  65. $db->update("exchange", $update, "exchangeID = 4");
  66. }
  67. }
  68.  
  69.  
  70.  
  71. //
  72. // Coinbase = Bitcoin
  73. //
  74. $coinbaseQuery = file_get_contents("https://coinbase.com/api/v1/prices/sell");
  75. if (isset($coinbaseQuery) AND $coinbaseQuery != "" AND $cryptorushQuery != false){
  76. $coinbaseData = json_decode($coinbaseQuery, true);
  77. if (isset($coinbaseData["total"]["amount"]) AND $coinbaseData["total"]["amount"] != "" AND $coinbaseData["total"]["amount"] != 0){
  78. $btc = $coinbaseData["total"]["amount"];
  79. $update = array("exchangePrice" => $btc);
  80. $db->update("exchange", $update, "exchangeID = 6");
  81. } else {
  82. $btc = 0;
  83. }
  84. }
  85.  
  86. $final_price = 0;
  87. $average = 0;
  88. $total_volume = 0;
  89. $sources = 0;
  90.  
  91.  
  92. foreach ($price as $priceSource => $priceValue){
  93. $total = $total+$priceValue;
  94. $sources++;
  95. }
  96.  
  97. foreach ($volume as $volumeSource => $volumeValue){
  98. $total_volume = $total+$volumeValue;
  99. }
  100.  
  101.  
  102. $total2 = 0;
  103. $sources2 = 0;
  104.  
  105. reset($price);
  106. if ($total != 0 AND $sources !=0 ){
  107. $average = $total/$sources;
  108. //handle any outliers
  109. foreach ($price as $priceSource => $priceValue){
  110. if (($priceValue-$average) > 5 || (($priceValue-$average)*-1) > 5){
  111. //skip - it deviates to far from the norm
  112. } else {
  113. $total2 += $priceValue;
  114. $sources2++;
  115. }
  116. }
  117. }
  118.  
  119. if ($total != 0 AND $sources !=0 ){
  120. $final_price = $total2/$sources2;
  121. if ($final_price < $average){
  122. $final_price = $average;
  123. }
  124.  
  125.  
  126. //insert total total
  127. $update = array("exchangePrice" => $final_price,"exchangeVolume" => $total_volume);
  128. $db->update("exchange", $update, "exchangeID = 1"); //total
  129. //update productPriceGPUC
  130. $products = $db->select("product","productActive=1");
  131. if (isset($products) AND is_array($products) AND count($products) > 0){
  132. if ($verbose) { echo "Bitcoin @ ".$btc."<br/>"; }
  133. if ($btc > 300){
  134. foreach ($products as $product){
  135. $btcConversion = $product["productPriceUSD"]/$btc; //300/600 = .5
  136. $gpuConversion = $btcConversion/$final_price;
  137. if ((int)$gpuConversion >= 1000){
  138. $update = array("productPriceGPUC" => (int)$gpuConversion);
  139. $bind = array(":productID" => $product["productID"]);
  140. $db->update("product", $update, "productID = :productID",$bind);
  141. if ($verbose) { echo $product["productName"]."[".$product["productPriceUSD"]."] @ ".$final_price." = ".$gpuConversion."<br/>"; }
  142. }
  143. }
  144. }
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment