App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Suffix/TGE.pm  view on Meta::CPAN

                            'RC' => 'rob',   # Robusta Coffee
                            'SG' => 'raw',   # Raw Sugar
                            'SL' => 'silk',  # Raw Silk
                            'VG' => 'vege'); # Vegetables

App::Chart::Weblink->new
  (pred => $pred,
   name => __('TGE _Contract Specifications'),
   desc => __('Open web browser at the Tokyo Grain Exchange contract specifications for this commodity'),
   proc => sub {
     my ($symbol) = @_;
     my $commodity = App::Chart::symbol_commodity ($symbol);
     my $code = $commodity_to_weblink{$commodity} || return undef;
     my $lang = App::Chart::Glib::Ex::MoreUtils::lang_select (ja => 'japanese',
                                                  en => 'english');
     return "http://www.tge.or.jp/$lang/contract/cont_s_$code.shtml";
   });

#-----------------------------------------------------------------------------
# misc

# return ISO date string of last trading for SYMBOL, or possibly a day or
# two after (because public holidays are not accounted for)
#
sub symbol_expiry {
  my ($symbol) = @_;
  my $mdate = symbol_mdate($symbol) // return undef;

  my $commodity = App::Chart::symbol_commodity ($symbol);
  # if ($commodity eq 'CO') {
  #     # corn
  #     # 15th calendar day of the month preceding the delivery month
  #     #       (receive-list (year month day)
  #     #        (mdate->ymd mdate)
  #     #        (ymd->tdate year (1- month) 15)))
  #   }
  #   when (['NG','RB','SB']) {
  #     # non-gm soybeans, azuki
  #     # 2 business days prior to delivery day; delivery day
  #     # is the business day prior to the last business day of
  #     # the delivery month or 24th for December
  #     #     (receive-list (year month day)
  #     #      (mdate->ymd mdate)
  #     #      (- (if (= 12 month)
  #     #          (ymd->tdate year month 24)
  #     #          (- (mdate->tdate (1+ mdate)) 2))
  #     #       2))
  #   }
  #   when (['NG','RB','SB']) {
  #     # arabica, robusta, soybean meal
  #     # 10 business days prior to the last business day of
  #     # the delivery month
  #     #     (- (mdate->tdate (1+ mdate)) 11)
  #   }
  #   when ('SG') {
  #     # raw sugar
  #     # last business day two months prior to delivery month
  #     #    (1- (mdate->tdate (1- mdate))))
  #   }
  #   default {
  #     # unknown, lets guess the last day of the contract month,
  #     # this won't be right but at least won't be early
  #     #       (1- (mdate->tdate (1+ mdate))))))
  #   }
  # }

  # FIXME:
  return undef;
}

# see table in http://www.tge.or.jp/japanese/price/prisel.js.php
# ENHANCE-ME: maybe download and parse that page
my %commodity_to_nav
  = ('CO' => 'tou',  # corn
     'SM' => 'dai',  # soybean meal
     'SB' => 'ipd',  # soybeans
     'NG' => 'ngd',  # non-gmo soybeans
     'RB' => 'azu',  # azuki
     'AC' => 'ara',  # arabica coffee
     'RC' => 'rob',  # robusta coffee
     'SG' => 'sot',  # raw sugar
     'SL' => 'rsl',  # raw silk
     'VG' => 'veg'); # vegetables

#-----------------------------------------------------------------------------
# download
#
# This uses the "download" under the price data page
#
#     http://www.tge.or.jp/english/price/pri_sel_01.shtml
#
# There's two files for each commodity,
#
#     http://www.tge.or.jp/data/down_load/co01.csv
#     http://www.tge.or.jp/data/down_load/co01040610050609.zip
#
# The csv is only about 600 bytes, it has just the most recent day and is
# used when that's all that's needed to update (which will be the case if
# you're updating every day).
#
# The zip is about 35kbytes and has the same most recent day as the csv,
# plus the past 12 months.  The filename is a date range
# (XX01yymmddyymmdd.zip), but there's only one file, you can't get an
# arbitrary range.
#
# The zip filename is formed from today's date, or a day or two earlier,
# but if we don't hit it that way there's a fallback to fetch and parse the
# actual download page.  The pattern in the filename is pretty clear, so
# perhaps that fallback is unnecessary.
#
# There's an ETag / Last-Modified on the year file, but it's hardly needed
# since the dates are in the name.

App::Chart::DownloadHandler->new
  (name   => __('TGE'),
   pred   => $pred,
   proc   => \&download,
   backto => undef,
   available_tdate => \&available_tdate,
   by_commodity    => 1);



( run in 1.182 second using v1.01-cache-2.11-cpan-39bf76dae61 )