[Kmymoney] Auto update of currencie and stock prices

Joe W. Byers ecjbosu at aol.com
Sat Oct 26 13:40:45 UTC 2013


On 10/26/2013 12:06 AM, Thomas Baumgart wrote:
> Hi,
>
> On Wednesday 23 October 2013 22:00:22 Koos Pol wrote:
>
>> Good evening all,
>>
>> Is it possible to automatically update the prices of currencies and stocks?
>> For instance by cron? Or update once a week but also download the prices
>> for all intermediate days? I find myself firing up KMM everynight just to
>> keep an eye on my stock portfolio. (granted, I should probably use a stock
>> program for this ;-)
> No, unfortunately this is currently not supported, though thoughts have
> already been spent as part of the Alkimia project. Even some source code for
> such feature already exists but is not integrated/used yet.
>
>
>
> _______________________________________________
> KMyMoney mailing list
> KMyMoney at kde.org
> https://mail.kde.org/mailman/listinfo/kmymoney
My workaround is using the following perl script on linux and the import 
into Kmymoney.  Put your symbols into @syms.  I would like to pass a 
parameter to read a text or xml file of the ticker symbols, but this is 
low on my priority.  I also pasted in a scirpt that will backfill dates 
not currently in kymoney.

Have fun.

Joe


#!/usr/bin/perl -w

#*************************************************************************** 

# fy-qif.pl - description
# -------------------
# begin : Sat 10 Feb 2012
# copyright : (C) 2012 by Joe W. Byers
# email : ecjbosu at aol.com
#
#***************************************************************************/ 

#
#*************************************************************************** 

#* *
#* This program 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 2 of the License, or *
#* (at your option) any later version. *
#* *
#***************************************************************************/ 


# Simple script to download security prices from finance.yahoo and create a
# qif format for KMyMoney2.
# Run by ''./fy-qif.pl' .
# You are required to specify a directory and file location in line 57.
# You should edit the list of security symbols in line 42.
# This file can be scheduled as a cron job if needed

# Output format -
# !Type:Prices
# "HJU8.BE",61.62,"23.12.09"
# ^

# This uses perl-Finance-YahooQuote
# Copyright (C) 2002 Dirk Eddelbuettel <edd at debian.org>, and GPL'ed
# Based on the original example by Dj Padzensky
#
# $Id: yahooquote,v 1.2 2002/12/24 17:50:28 edd Exp $

#Todo: create a file read to read a file

#use strict;
use Getopt::Long;
use Finance::YahooQuote;
@syms=(WMB,AAON,CSCO,EP,FLVCX,FSCGX,ISSC,MSFT,NOEQX,NOSIX,NTCHX,PG,RHT,SLR,FCNTX,FPURX,FJPNX,FSENX,OSMVX,ALU,TCLFX,FSLBX,FDFAX,FDIVX,ARTMX,EPD,FDGFX,OBFVX,TCLFX,OBBC,FDIKX,FDGFX); 


my $verbose = 0;
#GetOptions("verbose" => \$verbose);

#die "Usage: $0 [--verbose] symbol [symbol ...]\n" if $#ARGV == -1;

my @h = ("Symbol","Name","Last","Trade Date","Trade Time","Change","% 
Change",
      "Volume","Avg. Daily Volume","Bid","Ask","Prev. Close","Open",
      "Day's Range","52-Week Range","EPS","P/E Ratio","Div. Pay Date",
      "Div/Share","Div. Yield","Mkt. Cap","Exchange");

$Finance::YahooQuote::TIMEOUT = 30;

my @q = getquote(@syms);
$file = "/var/datadl/quotes.csv";
open(FH, ">> $file") || die $!;
foreach $a (@q) {
print FH "!Type:Prices\n";
   foreach (0..$#h) {
     if ($verbose) {
       print "$h[$_]: $$a[$_]\n";
     } else {
       print FH "\"$$a[$_]\"," if $h[$_] =~ /(Symbol)/m;
       print FH "\"$$a[$_]\"\n" if $h[$_] =~ /(Trade Date)/m;
#      print FH "$$a[$_]\n" if $h[$_] =~ /(Symbol)/m;
       print FH "$$a[$_]," if $h[$_] =~ /(Last)/m;
     }
   }
   print FH "^\n";
}
close(FH);

backfill history of uquoted.
#!/usr/bin/perl -w

#*************************************************************************** 

# fy-qif.pl - description
# -------------------
# begin : Sat 10 Feb 2012
# copyright : (C) 2012 by Joe W. Byers
# email : ecjbosu at aol.com
#
#***************************************************************************/ 

#
#*************************************************************************** 

#* *
#* This program 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 2 of the License, or *
#* (at your option) any later version. *
#* *
#***************************************************************************/ 


# Simple script to download security prices from finance.yahoo and create a
# qif format for KMyMoney2.
# Run by ''./fy-qif.pl' .
# You are required to specify a directory and file location in line 57.
# You should edit the list of security symbols in line 42.
# This file can be scheduled as a cron job if needed

# Output format -
# !Type:Prices
# "HJU8.BE",61.62,"23.12.09"
# ^

# This uses perl-Finance-YahooQuote
# Copyright (C) 2002 Dirk Eddelbuettel <edd at debian.org>, and GPL'ed
# Based on the original example by Dj Padzensky
#
# $Id: yahooquote,v 1.2 2002/12/24 17:50:28 edd Exp $

#Todo: create a file read to read in security symbols

#use strict;
use Getopt::Long;
use Finance::QuoteHist::Yahoo;
use HTTP::Date;
use DateTime;
use DateTime::Format::Flexible;

#@syms=qw("WMB AAON");
# CSCO EP FLVCX FSCGX ISSC MSFT NOEQX NOSIX NTCHX PG RHT SLR
#        FCNTX FPURX FJPNX FSENX OSMVX ALU TCLFX FSLBX FDFAX FDIVX ARTMX 
EPD FDGFX OBFVX TCLFX
#        OBBC FDIKX FDGFX");
$padlen = 2;


#print "@syms";

my $verbose = 0;
my $q = new Finance::QuoteHist::Yahoo (
     symbols    => [qw("WMB AAON CSCO EP FLVCX FSCGX ISSC MSFT NOEQX 
NOSIX NTCHX PG RHT SLR
         FCNTX FPURX FJPNX FSENX OSMVX ALU TCLFX FSLBX FDFAX FDIVX ARTMX 
EPD FDGFX OBFVX TCLFX
         OBBC FDIKX FDGFX")],
         start_date => '1/1/2010',
     end_date   => 'today'
     );

$file = "/var/datadl/quoteshist.csv";
open(FH, ">> $file") || die $!;


#values
foreach $row ($q->quotes()) {
   print FH "!Type:Prices\n";
     ($symbol, $date, $close) = @$row;
#print "$symbol\n";
       print FH "Y$symbol" . ",";
       $yr=substr($date,0,4);
       $mm = substr($date,5,2);
       $mm = sprintf("%0${padlen}d", $mm);
       $dd = substr($date,8,2);
       #$dd=sprintf("%0${padlen}d", $d);
       #print "$date\n";
       print FH "  $mm/$dd/$yr" . "\n";
       print FH "I$close\n";
       print FH "^\n";

#  print @$row["$symbol"]; print "=="; print @$row[ "$date"] ;

}
close(FH);
-- 
*Joe W. Byers*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kmymoney/attachments/20131026/e96108d3/attachment.html>


More information about the KMyMoney mailing list