App-Chart
view release on metacpan or search on metacpan
lib/GT/DB/Chart.pm view on Meta::CPAN
# Copyright 2008, 2009, 2010, 2011, 2012, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2023, 2024 Kevin Ryde
# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
package GT::DB::Chart;
use 5.010;
use strict;
use warnings;
use Carp;
use List::Util;
# don't "use base" since GT::DB as of 2010 doesn't have a $VERSION and
# base.pm will warn and assign $GT::DB::VERSION=-1
use GT::DB;
our @ISA = ('GT::DB');
use GT::Prices;
use GT::Conf;
use GT::DateTime;
# uncomment this to run the ### lines
#use Smart::Comments;
our $VERSION = 275;
# extra appended to GT::Prices elements giving the tdate etc corresponding
# to the $DATE element
our $DATE_T = List::Util::max ($OPEN, $HIGH, $LOW, $CLOSE, $VOLUME, $DATE) + 1;
sub new {
my ($class, $series, $hi) = @_;
return bless { series => $series,
hi => $hi,
}, $class;
}
sub disconnect {
my ($self) = @_;
if (App::Chart::DBI->can('disconnect')) { # if loaded
App::Chart::DBI->disconnect;
}
}
sub has_code {
my ($self, $symbol) = @_;
### GT-DB-Chart has_code(): $symbol
require App::Chart::Database;
return App::Chart::Database->symbol_exists ($symbol);
}
sub get_db_name {
my ($self, $symbol) = @_;
### GT-DB-Chart get_db_name(): $symbol
require App::Chart::Database;
return App::Chart::Database->symbol_name ($symbol);
}
my %timeframe_to_class = ($WEEK => 'Weeks',
$MONTH => 'Months',
$YEAR => 'Years');
sub get_prices {
my ($self, $symbol, $timeframe) = @_;
return $self->get_last_prices ($symbol, -1, $timeframe);
}
sub get_last_prices {
my ($self, $symbol, $limit, $timeframe) = @_;
### GT-DB-Chart get_last_prices(): $symbol
### $limit
### $timeframe
$timeframe ||= $DAY;
my $prices = GT::Prices->new;
$prices->set_timeframe ($timeframe);
if ($timeframe < $DAY) {
### no intraday data
return $prices;
( run in 0.620 second using v1.01-cache-2.11-cpan-39bf76dae61 )