E*Trade Portfolio Transaction Import

Keith Iosso kiosso at alumni.princeton.edu
Thu Apr 8 04:29:05 EDT 2004


> 	Is anybody able to import E*Trade portfolio transactions? E*Trade seems
> to download as CSV or direct to quicken.  I would like to import easily
> into Gnucash, but haven't figured it out.  
> 

OK, I think I've got it.  I can download a CSV file from E*Trade and have 
hosed up a crude perl script that seems to create a useable qif file and the 
importer makes nice transactions from it.   The perl script follows in the hope 
that it might be helpful to others.  

Script:
#!/usr/bin/perl
#
# Convert one specific format of investment CSV file into QIF. 
#
# Input:
#"Account Number","Trade Date",Symbol,Cusip,Action,Quantity,Price,Amount,"Net
Amount"
#1234-5678,02-02-2004,RHAT,1-11-1,Buy,100.00000,17.58000,1758.00000,1767.99000
#...

# Output:
#!Type:Invst (one per file)
#D02/02/2004 (all the rest are per transaction)
#NBuy
#YRHAT
#I17.5800
#Q100.00000
#O9.99000
#T1767.99000
#^

#invocation: csv2qif.perl <inputfilename.csv >outputfilename.qif

print "!Type:Invst\n";

$line = <>;	# lose the first line, assuming it's a comment

while (<>) {
   @field = split(/,/);
   $field[1] =~ s|-|/|g;
   print "D$field[1]\n";
   print "N$field[4]\n";
   print "Y$field[2]\n";
   print "M$field[2]\n";
   print "I$field[6]\n";
   print "Q$field[5]\n";
   $commission = sprintf("%.2f", abs($field[8] - $field[7]));
   print "O$commission\n";
   print "T$field[8]";	#\n is included 
   print "^\n";
}




More information about the gnucash-user mailing list