Quote/SIX.pm

filter: Statementstmt 45.1% 37 / 82 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 4 totaltotal 39.0% 48 / 123 CC 13 SCAR 46.0
CC
13
Cov
35%
six
182.0
BEGIN
1.0
BEGIN
1.0
CRAP 99.0
« Quote/Fool.pm ↑ Summary Quote/Deka.pm »
1 #!/usr/bin/perl -w
2 # vi: set ts=2 sw=2 noai expandtab ic showmode showmatch:
3  
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 # 02110-1301, USA
18  
19 package Finance::Quote::SIX;
20  
21 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use constant DEBUG => $ENV{DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use if DEBUG, 'Smart::Comments';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use JSON qw( decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use String::Util qw(trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 5 our $VERSION = '1.72_02'; # TRIAL VERSION
33  
34 5 our $DISPLAY = 'SIX - Swiss Stock Exchange';
35 5 our @LABELS = qw/last close date isodate symbol currency isin name/;
36 5 our $METHODHASH = {subroutine => \&six,
37 display => $DISPLAY,
38 labels => \@LABELS};
39  
40 10 ▶sub methodinfo {
Subroutine methodinfo: called CC=1 SCAR=0.0
Pod undocumented
41 return (
42 10 six => $METHODHASH,
43 );
44 }
45  
46 5 ▶sub labels {
Subroutine labels: called CC=1 SCAR=0.0
Pod undocumented
47 5 my %m = methodinfo();
48 5 return map {$_ => [@{$m{$_}{labels}}] } keys %m;
49 }
50  
51 5 ▶sub methods {
Subroutine methods: called CC=1 SCAR=0.0
Pod undocumented
52 5 my %m = methodinfo();
53 5 return map {$_ => $m{$_}{subroutine} } keys %m;
54 }
55  
56 0 ▶sub six {
Subroutine six: not called CC=13 SCAR=52.0
Pod undocumented
57 0 my $quoter = shift;
58 0 my @symbols = @_;
59 0 my $ua = $quoter->user_agent();
60 0 my %info;
61  
62 0 foreach my $symbol (@_) {
63 0 eval {
64 # 1. Search for the security
65 0 my $url = 'https://www.six-group.com/fqs/snap.json?select=ValorId,PortalSegment,ProductLine&where=PortalSegment=EQ|BO|FU|EP|IN&pagesize=2&match=' . $symbol;
66 0 my $reply = $ua->get($url);
67 0 my $search = JSON::decode_json $reply->content;
68  
69 ### Search : $url, $reply->code
70 ### Search : $search
71
72 # 2. Get security metadata
73 0 my $valorid = $search->{rowData}->[0][0];
74 0 ▶ die "$symbol not found" unless defined $valorid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $valorid 0 0 0
75  
76 0 $url = 'https://www.six-group.com/fqs/ref.json?select=DividendEntitlementFlag,FirstTradingDate,LastTradingDate,ISIN,IssuerNameFull,IssuerNameShort,MarketDate,NominalCurrency,NominalValue,NumberInIssue,ProductLine,SecTypeDesc,ShortName,SmallestTradeableUnit,TitleSegment,TitleSegmentDesc,TradingBaseCurrency,ValorNumber,ValorSymbol&where=ValorId=' . $valorid;
77 0 $reply = $ua->get($url);
78 0 my $metadata = JSON::decode_json $reply->content;
79
80 ### Metadata : $url, $reply->code
81 ### Metadata : $metadata
82  
83 0 my @metacols = @{$metadata->{colNames}};
84 0 my %metamap = map {$metacols[$_] => $_} (0 .. $#metacols);
85 0 my $metarow = $metadata->{rowData}->[0];
86  
87 0 $info{$symbol, 'symbol'} = $metarow->[$metamap{ValorSymbol}];
88 0 $info{$symbol, 'isin'} = $metarow->[$metamap{ISIN}];
89 0 $info{$symbol, 'name'} = $metarow->[$metamap{IssuerNameFull}];
90 0 $info{$symbol, 'currency'} = $metarow->[$metamap{TradingBaseCurrency}];
91  
92 0 $quoter->store_date(\%info, $symbol, {isodate => $metarow->[$metamap{MarketDate}]});
93  
94 0 $url = 'https://www.six-group.com/fqs/movie.json?select=AskPrice,AskVolume,BidPrice,BidVolume,ClosingDelta,ClosingPerformance,ClosingPrice,DailyHighPrice,DailyHighTime,DailyLowPrice,DailyLowTime,LatestTradeVolume,MarketMakers,MarketTime,MidSpread,OffBookTrades,OffBookTurnover,OffBookVolume,OnMarketTrades,OnMarketTurnover,OnMarketVolume,OpeningPrice,PreviousClosingPrice,SwissAtMidTrades,SwissAtMidTurnover,SwissAtMidVolume,TotalVolume,VWAP60Price,YearAgoPerformance,YearlyHighDate,YearlyHighPrice,YearlyLowDate,YearlyLowPrice,YearToDatePerformance,YieldToWorst&where=ValorId=' . $valorid;
95 0 $reply = $ua->get($url);
96 0 my $data = JSON::decode_json $reply->content;
97  
98 ### Data : $url, $reply->code
99 ### Data : $data
100  
101 0 my @datacols = @{$data->{colNames}};
102 0 my %datamap = map {$datacols[$_] => $_} (0 .. $#datacols);
103 0 my $datarow = $data->{rowData}->[0];
104  
105 0 ▶ $info{$symbol, 'ask'} = $datarow->[$datamap{AskPrice}] if $datarow->[$datamap{AskPrice}] and looks_like_number($datarow->[$datamap{AskPrice}]);
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"AskPrice"}] and &looks_like_number($$datarow[$datamap{"AskPrice"}]) 0 0 0
Condition0%0/3
$$datarow[$datamap{"AskPrice"}] and &looks_like_number($$datarow[$datamap{"AskPrice"}])
!ll&&!rl&&r
000
MC/DC0%0/2
$$datarow[$datamap{"AskPrice"}] and &looks_like_number($$datarow[$datamap{"AskPrice"}])
$$datarow[$datamap{"AskPrice"}] &looks_like_number($$datarow[$datamap{"AskPrice"}])
Truth table0%0/3
A and B
A= $$datarow[$datamap{"AskPrice"}]B= &looks_like_number($$datarow[$datamap{"AskPrice"}])
ABresult
0X0
100
111
106 0 ▶ $info{$symbol, 'close'} = $datarow->[$datamap{ClosingPrice}] if $datarow->[$datamap{ClosingPrice}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"ClosingPrice"}] 0 0 0
107 0 ▶ $info{$symbol, 'high'} = $datarow->[$datamap{DailyHighPrice}] if $datarow->[$datamap{DailyHighPrice}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"DailyHighPrice"}] 0 0 0
108 0 ▶ $info{$symbol, 'low'} = $datarow->[$datamap{DailyLowPrice}] if $datarow->[$datamap{DailyLowPrice}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"DailyLowPrice"}] 0 0 0
109 0 ▶ $info{$symbol, 'open'} = $datarow->[$datamap{OpeningPrice}] if $datarow->[$datamap{OpeningPrice}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"OpeningPrice"}] 0 0 0
110 0 ▶ $info{$symbol, 'last'} = $datarow->[$datamap{ClosingPrice}] if $datarow->[$datamap{ClosingPrice}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"ClosingPrice"}] 0 0 0
111 0 ▶ $info{$symbol, 'volume'} = $datarow->[$datamap{TotalVolume}] if $datarow->[$datamap{TotalVolume}];
Branch: 1 branch
BranchTrueFalseTotal
if $$datarow[$datamap{"TotalVolume"}] 0 0 0
112 0 $info{$symbol, 'success'} = 1;
113 };
114
115 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
116 0 my $error = "SIX failed: $@";
117 0 $info{$symbol, 'success'} = 0;
118 0 $info{$symbol, 'errormsg'} = trim($error);
119 }
120 }
121  
122 0 ▶ return wantarray() ? %info : \%info;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
123 }
124  
125 5 1;
126  
127 =head1 NAME
128  
129 Finance::Quote::SIX - Obtain quotes from the Swiss Stock Exchange
130  
131 =head1 SYNOPSIS
132  
133 use Finance::Quote;
134  
135 $q = Finance::Quote->new;
136  
137 %info = Finance::Quote->fetch('six', 'NESN');
138  
139 =head1 DESCRIPTION
140  
141 This module fetches information from the Swiss Stock Exchange,
142 https://www.six-group.com.
143  
144 This module is loaded by default on a Finance::Quote object. It's also possible
145 to load it explicitly by placing 'SIX' in the argument list to
146 Finance::Quote->new().
147  
148 =head1 LABELS RETURNED
149  
150 The following labels may be returned by Finance::Quote::SIX :
151 isin name currency date isodate ask close high low open volume success
152  
153 =head1 TERMS & CONDITIONS
154  
155 Use of www.six-group.com is governed by any terms & conditions of that site.
156  
157 Finance::Quote is released under the GNU General Public License, version 2,
158 which explicitly carries a "No Warranty" clause.
159  
160 =cut
161  
« Quote/Fool.pm ↑ Summary Quote/Deka.pm »