forked from mcafeeryan/portfolio_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.pl
executable file
·75 lines (55 loc) · 1.55 KB
/
get_data.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl -w
use Getopt::Long;
use Time::ParseDate;
use Time::CTime;
use FileHandle;
use stock_data_access;
$close=1;
$notime=0;
$open=0;
$high=0;
$low=0;
$close=0;
$vol=0;
$from=0;
$to=0;
$plot=0;
&GetOptions( "notime"=>\$notime,
"open" => \$open,
"high" => \$high,
"low" => \$low,
"close" => \$close,
"vol" => \$vol,
"from=s" => \$from,
"to=s" => \$to, "plot" => \$plot);
if (defined $from) { $from=parsedate($from); }
if (defined $to) { $to=parsedate($to); }
$usage = "usage: get_data.pl [--open] [--high] [--low] [--close] [--vol] [--from=time] [--to=time] [--plot] SYMBOL\n";
$#ARGV == 0 or die $usage;
$symbol = shift;
push @fields, "timestamp" if !$notime;
push @fields, "open" if $open;
push @fields, "high" if $high;
push @fields, "low" if $low;
push @fields, "close" if $close;
push @fields, "volume" if $vol;
my $sql;
$sql = "select " . join(",",@fields) . " from ".GetStockPrefix()."StocksDaily";
$sql.= " where symbol = '$symbol'";
$sql.= " and timestamp >= $from" if $from;
$sql.= " and timestamp <= $to" if $to;
$sql.= " order by timestamp";
my $data = ExecStockSQL("TEXT",$sql);
if (!$plot) {
print $data;
} else {
open(DATA,">_plot.in") or die "Cannot open temporary file for plotting\n";
print DATA $data;
close(DATA);
open(GNUPLOT, "|gnuplot") or die "Cannot open gnuplot for plotting\n";
GNUPLOT->autoflush(1);
print GNUPLOT "set title '$symbol'\nset xlabel 'time'\nset ylabel 'data'\n";
print GNUPLOT "plot '_plot.in' with linespoints;\n";
STDIN->autoflush(1);
<STDIN>;
}