SHARE
TWEET

Untitled

a guest Jun 15th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Money Doubler</title>
  5. </head>
  6. <body>
  7.    
  8. <?php
  9. //Connect to mysql
  10. $servername = "";
  11. $username = "";
  12. $password = "";
  13. $dbname = "trades";
  14. $mysql = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($mysql->connect_error) {
  17.     die("Connection failed: " . $mysql->connect_error);
  18. }
  19.  
  20. //Variables for decoding the API URL's and setting
  21. $content =  file_get_contents("https://bittrex.com/api/v1.1/public/getticker?market=BTC-DGB");
  22. $result  = json_decode($content, true);
  23. $datareturn = $result['result'];
  24. $DGBBid = number_format($datareturn['Bid'], 8, '.', '');
  25. $DGBAsk = number_format($datareturn['Ask'], 8, '.', '');
  26. $DGBLast = number_format($datareturn['Last'], 8, '.', '');
  27.  
  28. echo "Bid price for DGB is " . $DGBBid . "<br>";
  29. echo "Ask price for DGB is " . $DGBAsk . "<br>";
  30. echo "Last price for DGB is " . $DGBLast . "<br>";
  31.  
  32. $sql = "INSERT INTO prices_dgb (last_price)
  33. VALUES (" . $DGBLast . " )";
  34.  
  35. if ($mysql->query($sql) === TRUE) {
  36.     echo "New record created successfully<br>";
  37. } else {
  38.     echo "Error: " . $sql . "<br>" . $mysql->error;
  39. }
  40.  
  41. //Pulls most recent trade ID to get last interval trade ID
  42. $query = $mysql->query("SELECT id FROM prices_dgb ORDER BY id DESC LIMIT 2");
  43. $current_trade_id = mysqli_fetch_row($query);
  44. $tid = $current_trade_id[0];
  45. echo "Current trade ID is " . $current_trade_id[0] . "<br>";
  46.  
  47. //Pulls current trade price
  48. $query = $mysql->query("SELECT last_price FROM prices_dgb WHERE id = " . $current_trade_id[0]);
  49. $price = mysqli_fetch_row($query);
  50. $current_trade_price = $price[0];
  51.  
  52. //Pulls last interval trade ID to pull last trade price
  53. $last_trade_id = $current_trade_id[0] - 1;
  54. echo "Last trade ID is " . $last_trade_id . "<br>";
  55.  
  56. //Pulls last trade price
  57. $query = $mysql->query("SELECT last_price FROM prices_dgb WHERE id = " . $last_trade_id);
  58. $price = mysqli_fetch_row($query);
  59. $last_trade_price = $price[0];
  60.  
  61. //Calculates percent difference
  62. if ($last_trade_price > $current_trade_price)
  63.     $percent_change = ((($current_trade_price / $last_trade_price) + -1)* 100);
  64. Else
  65.     $percent_change = ((1 - ($last_trade_price / $current_trade_price)) * 100);
  66.  
  67. echo "Trade price 5 minutes ago(last run) was " . $last_trade_price . ". Current bid price is " . $current_trade_price . ". This is a % " . $percent_change .  " difference";
  68.  
  69. //Insert percent difference since last check into DB
  70. $mysql->query("UPDATE prices_dgb SET percent_increase = " . $percent_change . " WHERE id = " . $tid);
  71.  
  72. if ($percent_change > 1)
  73.     Echo "<br>Percent change greater than 1% since last update!";
  74. Else
  75.     Echo "<br>Percent change less than 1% since last update!";
  76.  
  77. ?>
  78.  
  79. </body>
  80. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top