This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 12th, 2013  |  syntax: PHP  |  size: 0.72 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * @name MtGox Ticker Script
  4.  * @author Svante Hansson
  5.  * Used to fetch current ticker data using cronjob
  6.  */
  7.  
  8. require_once('xxx/db.php');
  9. define('MTGOX_TICKER', 'http://data.mtgox.com/api/1/BTCUSD/ticker');
  10.  
  11. $ch = curl_init(MTGOX_TICKER);
  12.  
  13. curl_setopt($ch, CURLOPT_USERAGENT, "BitAlerts/0.1");
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15.  
  16. $data = curl_exec($ch);
  17. $json = json_decode($data);
  18.  
  19. if($json->result == 'success')
  20. {
  21.     $stmt = $dbh->prepare('INSERT INTO tbl_ticker_data VALUES(null, NOW(), :last_price, :last_vol)');
  22.     $stmt->bindParam(':last_price', $json->return->last->value, PDO::PARAM_STR);
  23.     $stmt->bindParam(':last_vol', $json->return->vol->value);
  24.     $stmt->execute();
  25. }
  26. ?>
clone this paste RAW Paste Data