| 1 | # Bendigo Stock Exchange (BSX) setups. | ||
| 2 | |||
| 3 | # Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2012 Kevin Ryde | ||
| 4 | |||
| 5 | # This file is part of Chart. | ||
| 6 | # | ||
| 7 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 8 | # terms of the GNU General Public License as published by the Free Software | ||
| 9 | # Foundation; either version 3, or (at your option) any later version. | ||
| 10 | # | ||
| 11 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 12 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 14 | # details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | package App::Chart::Suffix::BEN; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Locale::TextDomain ('App-Chart'); | ||
| 23 | |||
| 24 | use App::Chart; | ||
| 25 | use App::Chart::Sympred; | ||
| 26 | use App::Chart::TZ; | ||
| 27 | use App::Chart::Weblink; | ||
| 28 | |||
| 29 | |||
| 30 | # Victoria is the same as NSW these days, but let's not assume that rare | ||
| 31 | # outbreak of interstate cooperation will be permanent (in the past the | ||
| 32 | # dates to begin or end daylight savings have varied). | ||
| 33 | # | ||
| 34 | my $timezone_bendigo = App::Chart::TZ->new | ||
| 35 | (name => __('Bendigo'), | ||
| 36 | choose => [ 'Australia/Melbourne' ], | ||
| 37 | fallback => 'EST-10'); | ||
| 38 | |||
| 39 | my $pred = App::Chart::Sympred::Suffix->new ('.BEN'); | ||
| 40 | $timezone_bendigo->setup_for_symbol ($pred); | ||
| 41 | |||
| 42 | # App::Chart::setup_source_help | ||
| 43 | # ($pred, __p('manual-node','Bendigo Stock Exchange')); | ||
| 44 | |||
| 45 | |||
| 46 | #------------------------------------------------------------------------------ | ||
| 47 | # weblink - company info | ||
| 48 | |||
| 49 | App::Chart::Weblink->new | ||
| 50 | (pred => $pred, | ||
| 51 | name => __('BSX _Company Information'), | ||
| 52 | desc => __('Open web browser at the Bendigo Stock Exchange information page for this company'), | ||
| 53 | proc => sub { | ||
| 54 | my ($symbol) = @_; | ||
| 55 | return 'http://www.bsx.com.au/markets_pricesresearch_com.asp?security=' | ||
| 56 | . secode_for_symbol ($symbol); | ||
| 57 | }); | ||
| 58 | # weblink_message __('Fetching BSX symbol codes ...') | ||
| 59 | |||
| 60 | |||
| 61 | #----------------------------------------------------------------------------- | ||
| 62 | # security codes | ||
| 63 | # | ||
| 64 | # The home page | ||
| 65 | # | ||
| 66 | # http://www.bsx.com.au | ||
| 67 | # | ||
| 68 | # has a pull-down menu of symbols, with the code numbers to be used for | ||
| 69 | # quotes and trade history. | ||
| 70 | # | ||
| 71 | # The cache here saves the code numbers for one day (the current trading | ||
| 72 | # day, bendigo time). This ensures we don't download every time, but still | ||
| 73 | # have a fresh set of codes, in case there's additions or perhaps changes. | ||
| 74 | # | ||
| 75 | # Thought was given to a more sophisticated caching scheme, for instance use | ||
| 76 | # an old code and if the quote turns out to be for something else and the | ||
| 77 | # cache isn't fresh then refill it and get the quote again. But for the | ||
| 78 | # data download it'd be a case of checking the name against the database | ||
| 79 | # name, since there's no symbol on that page, except that for the initial | ||
| 80 | # download when there's no database name yet the cache would have to be | ||
| 81 | # pre-freshened. This seems unnecessarily complicated to merely avoid | ||
| 82 | # downloading one page, especially when it's compressed to about 3kbytes if | ||
| 83 | # we've got gzip or zlib. | ||
| 84 | |||
| 85 | |||
| 86 | # return option code string, or undef if unknown | ||
| 87 | sub secode_for_symbol { | ||
| 88 | my ($symbol) = @_; | ||
| 89 | require App::Chart::Pagebits; | ||
| 90 | my $h = App::Chart::Pagebits::get | ||
| 91 | (name => __('BSX stock numbers'), | ||
| 92 | url => 'http://www.bsx.com.au', | ||
| 93 | key => 'bendigo-codes', | ||
| 94 | freq_days => 1, | ||
| 95 | timezone => $timezone_bendigo, | ||
| 96 | parse => \&secodes_parse); | ||
| 97 | return $h->{$symbol}; | ||
| 98 | } | ||
| 99 | |||
| 100 | # return hash reference { $symbol => $code, ... } | ||
| 101 | sub secodes_parse { | ||
| 102 | my ($content) = @_; | ||
| 103 | my %hash; | ||
| 104 | while ($content =~ m{<option value=\"([0-9]+)\">([A-Z]+)</option>}g) { | ||
| 105 | $hash{"$2.BEN"} = $1; | ||
| 106 | } | ||
| 107 | return \%hash; | ||
| 108 | } | ||
| 109 | |||
| 110 | 1; | ||
| 111 | __END__ |