1package Finance::Quote::Oslobors; 2 3use strict; 4use JSON qw( decode_json ); 5use HTTP::Request::Common; 6 7our $VERSION = '1.51'; # VERSION 8 9use vars qw( $OSLOBORS_COMPONENTS_URL ); 10 11$OSLOBORS_COMPONENTS_URL = "https://www.oslobors.no/ob/servlets/components?type=table&source=feed.omff.FUNDS&view=REALTIME&columns=ITEM%2C+PRICECHANGEPCT%2C+PRICE%2C+DATE%2C+QUOTATIONCURRENCY&filter=ITEM_SECTOR%3D%3Ds"; 12 13sub methods { return (oslobors => \&oslobors); } 14 15{ 16 my @labels = qw/date isodate method source currency price p_change/; 17 sub labels { return (oslobors => \@labels); } 18} 19 20sub oslobors { 21 my $quoter = shift; 22 my @symbols = @_; 23 my %funds; 24 25 my $ua = $quoter->user_agent; 26 27 my ($url, $reply, $data); 28 29 foreach my $symbol (@symbols) { 30 $url = $OSLOBORS_COMPONENTS_URL . $symbol; 31 $reply = $ua->request(GET $url); 32 unless($reply->is_success) { 33 $funds{$symbol, "success"} = 0; 34 $funds{$symbol, "errormsg"} = "HTTP request failed"; 35 } else { 36 $data = JSON::decode_json($reply->content)->{"rows"}[0]{"values"}; 37 38 $quoter->store_date(\%funds, $symbol, { isodate => sprintf("%s-%s-%s", $data->{"DATE"} =~ /(\d\d\d\d)(\d\d)(\d\d)/)}); 39 $funds{$symbol, 'method'} = 'oslobors'; 40 $funds{$symbol, 'currency'} = $data->{"QUOTATIONCURRENCY"}; 41 $funds{$symbol, 'success' } = 1; 42 $funds{$symbol, 'price' } = $data->{"PRICE"}; 43 $funds{$symbol, 'source' } = 'Finance::Quote::Oslobors'; 44 $funds{$symbol, 'symbol' } = $symbol; 45 $funds{$symbol, 'p_change'} = $data->{"PRICECHANGEPCT"}; 46 } 47 } 48 49 return wantarray() ? %funds : \%funds; 50} 51 521; 53 54=head1 NAME 55 56Finance::Quote::Oslobors - Obtain fund quotes from Oslo stock exchange 57 58=head1 SYNOPSIS 59 60 use Finance::Quote; 61 $q = Finance::Quote->new; 62 %fundinfo = $q->fetch("oslobors","FUND-TICKER.OSE"); 63 64=head1 DESCRIPTION 65 66This module obtains information about mutual fund prices from 67www.oslobors.no. 68 69=head1 FUND TICKER SYMBOLS 70 71The fund ticker symbols can be found by searching for the fund, 72and visit its page. The symbol will be visible in the URL, for 73instance OD-HORIA.OSE. The .OSE part is necessary. 74 75The package does not understand Oslo stock symbols. 76 77=head1 LABELS RETURNED 78 79The module returns date, method, source, currency, price and p_change. 80The prices are updated on bank days. 81 82=head1 SEE ALSO 83 84Finance::Quote 85 86=cut 87