Skip to content

Instantly share code, notes, and snippets.

@ptantiku
Created March 13, 2014 19:53
Show Gist options
  • Save ptantiku/9535638 to your computer and use it in GitHub Desktop.
Save ptantiku/9535638 to your computer and use it in GitHub Desktop.
Download stock data from BLS
<?php
# Downloading stock data, one file per date
# required packages: php5-cli wget
# downloaded files have format of: name, date(yymmdd), open, high, low, close, volume(stocks), value(baht)
$start_year = 2003;
for($y=$start_year; $y<=2014; $y++){
for($m=1; $m<=12; $m++ ){
for($d=1; $d<=31; $d++){
$t = strtotime("$y-$m-$d");
if($t===FALSE || $t>strtotime("now") || date('m',$t)!=$m) break;
$dow = intval(date('N', $t)); //1-Monday, 7-Sunday
if(1<=$dow && $dow<=5){
$url = sprintf('http://realtime.bualuang.co.th/myeasy/realtime/quotation/txt/%02d%02d%4d.txt',$d,$m,$y);
system("wget $url");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment