Adding to existing database

#2
Assuming you have downloaded the bhav copy, the following perl script could help. Beware - this is a couple of years old code. Should work but no promises. If you run into issues, let me know. I had used this before - maybe I could make it work again.

Tried attaching the file but reported "Invalid file" error. So, pasting here.

Code:
use strict;
use warnings;

my $symbol;
my $series;
my $open;
my $high;
my $low;
my $close;
my $last;
my $prevclose;
my $tottrdqty;
my $tottrdval;
my $timestamp;
my @files;
my $file;

my $broker = Win32::OLE->new('Broker.Application');
$broker->LoadDatabase( "D:\\AmiBroker\\EOD" );

chdir "E:\\NSEdata\\raw";

@files=<cm06NOV2012*.csv>;

foreach $file(@files)
{
    print "Procesing file $file\n";
    open(IFILE,"<",$file);
    while (<IFILE>)
    {
        ($symbol,$series,$open,$high,$low,$close,$last,$prevclose,$tottrdqty,$tottrdval,$timestamp) = split(',',$_);
        if ($series eq "EQ")
        {
					print "Symbol $symbol with series $series found...\n";
					my $stock = $broker->stocks->add($symbol) or die "Adding stock errored out";
					my $quote = $stock->quotations->add($timestamp) or die "Adding quote errored out";
					$quote->{open} = $open;
					$quote->{high} = $high;
					$quote->{low} = $low;
					$quote->{close} = $close;
					$quote->{volume} = $tottrdqty;
					$quote->{aux1} = $last;
					$quote->{aux2} = $prevclose;
        }
    }
    close IFILE;
	$broker->SaveDatabase;
}
$broker->Quit;
 

amitrandive

Well-Known Member
#3
Assuming you have downloaded the bhav copy, the following perl script could help. Beware - this is a couple of years old code. Should work but no promises. If you run into issues, let me know. I had used this before - maybe I could make it work again.

Tried attaching the file but reported "Invalid file" error. So, pasting here.

Code:
use strict;
use warnings;

my $symbol;
my $series;
my $open;
my $high;
my $low;
my $close;
my $last;
my $prevclose;
my $tottrdqty;
my $tottrdval;
my $timestamp;
my @files;
my $file;

my $broker = Win32::OLE->new('Broker.Application');
$broker->LoadDatabase( "D:\\AmiBroker\\EOD" );

chdir "E:\\NSEdata\\raw";

@files=<cm06NOV2012*.csv>;

foreach $file(@files)
{
    print "Procesing file $file\n";
    open(IFILE,"<",$file);
    while (<IFILE>)
    {
        ($symbol,$series,$open,$high,$low,$close,$last,$prevclose,$tottrdqty,$tottrdval,$timestamp) = split(',',$_);
        if ($series eq "EQ")
        {
					print "Symbol $symbol with series $series found...\n";
					my $stock = $broker->stocks->add($symbol) or die "Adding stock errored out";
					my $quote = $stock->quotations->add($timestamp) or die "Adding quote errored out";
					$quote->{open} = $open;
					$quote->{high} = $high;
					$quote->{low} = $low;
					$quote->{close} = $close;
					$quote->{volume} = $tottrdqty;
					$quote->{aux1} = $last;
					$quote->{aux2} = $prevclose;
        }
    }
    close IFILE;
	$broker->SaveDatabase;
}
$broker->Quit;
TechQuant

Thanks will try and let you know if facing any issues.
 

sr114

Well-Known Member
#4
Assuming you have downloaded the bhav copy, the following perl script could help. Beware - this is a couple of years old code. Should work but no promises. If you run into issues, let me know. I had used this before - maybe I could make it work again.

Tried attaching the file but reported "Invalid file" error. So, pasting here.

Code:
use strict;
use warnings;

my $symbol;
my $series;
my $open;
my $high;
my $low;
my $close;
my $last;
my $prevclose;
my $tottrdqty;
my $tottrdval;
my $timestamp;
my @files;
my $file;

my $broker = Win32::OLE->new('Broker.Application');
$broker->LoadDatabase( "D:\\AmiBroker\\EOD" );

chdir "E:\\NSEdata\\raw";

@files=<cm06NOV2012*.csv>;

foreach $file(@files)
{
    print "Procesing file $file\n";
    open(IFILE,"<",$file);
    while (<IFILE>)
    {
        ($symbol,$series,$open,$high,$low,$close,$last,$prevclose,$tottrdqty,$tottrdval,$timestamp) = split(',',$_);
        if ($series eq "EQ")
        {
					print "Symbol $symbol with series $series found...\n";
					my $stock = $broker->stocks->add($symbol) or die "Adding stock errored out";
					my $quote = $stock->quotations->add($timestamp) or die "Adding quote errored out";
					$quote->{open} = $open;
					$quote->{high} = $high;
					$quote->{low} = $low;
					$quote->{close} = $close;
					$quote->{volume} = $tottrdqty;
					$quote->{aux1} = $last;
					$quote->{aux2} = $prevclose;
        }
    }
    close IFILE;
	$broker->SaveDatabase;
}
$broker->Quit;

Simply make a format file according the columns and import via ascii

rgds
 

Similar threads