SHARE
TWEET

Untitled

a guest Jun 12th, 2013 28 Never
  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. ?>
RAW Paste Data
Top