Exemple #1
0
#!/usr/bin/php
<?php 
require_once dirname(__FILE__) . '/lib.inc.php';
// echo isin2value_tlx('AU3TB0000101', 'http://eurotlx.com/it/strumenti/dettaglio/%ISIN%');
print_r(isin2bond_tlx('AU3TB0000101', 'http://eurotlx.com/it/strumenti/dettaglio/%ISIN%'));
 public function run($context)
 {
     // printf("ISIN;Emissione;Scadenza;Cadenza;Stacco;Tasso\n");
     $updated_count = 0;
     foreach ($context->stocks as $stock) {
         if ($stock->tipo != 'obbligazione' || !$stock->attivo) {
             continue;
         }
         // print_r($stock);
         $bond = new Bond();
         if ($bond->find_by_id($stock->isin)) {
             if ($bond->scadenza != EPOCH_ZERO && $bond->emissione != EPOCH_ZERO && $bond->stacco != EPOCH_ZERO) {
                 continue;
             }
         }
         // printf("%s;%s;%s;%s;%s;%s\n",
         //	 $bond->isin,
         //	 $bond->emissione,
         //	 $bond->scadenza,
         //	 $bond->cadenza,
         //	 $bond->stacco,
         //	 $bond->tasso
         // );
         switch ($stock->mercato) {
             case "eurotlx":
             case "tlx":
                 $params = isin2bond_tlx($stock->isin, $context->preferences->isin_lookup_eurotlx);
                 break;
         }
         if ($params === FALSE) {
             continue;
         }
         $bond_new = new Bond($params);
         $bond_new->isin = $stock->isin;
         if (!empty($bond_new->scadenza) && $bond->scadenza != $bond_new->scadenza || !empty($bond_new->emissione) && $bond->emissione != $bond_new->emissione || !empty($bond_new->stacco) && $bond->stacco != $bond_new->stacco) {
             // printf("%s;%s;%s;%s;%s;%s\n",
             //	 $bond->isin,
             //	 $bond->emissione,
             //	 $bond->scadenza,
             //	 $bond->cadenza,
             //	 $bond->stacco,
             //	 $bond->tasso
             // );
             //
             // printf("%s;%s;%s;%s;%s;%s\n\n",
             //	 $bond_new->isin,
             //	 $bond_new->emissione,
             //	 $bond_new->scadenza,
             //	 $bond_new->cadenza,
             //	 $bond_new->stacco,
             //	 $bond_new->tasso
             // );
             // print_r($bond_new);
             $bond_new->_force_create = TRUE;
             $bond_new->_ignore = TRUE;
             $bond_new->save();
             $updated_count++;
         }
     }
     printf("%s updated %d bonds\n", get_called_class(), $updated_count);
 }
Exemple #3
0
echo "Reading preferences...";
$preference_factory = new Preference();
$preferences = $preference_factory->find_all()[0];
// print_r($preferences);
echo "done\n";
$stock_factory = new Stock();
$stocks = $stock_factory->find_all(array('where_clause' => "`tipo`='obbligazione'", 'limit' => 1500));
foreach ($stocks as $stock) {
    if (!$stock->attivo) {
        continue;
    }
    // print_r($stock);
    $bond = new Bond();
    if (!$bond->find_by_id($stock->isin)) {
        switch ($stock->mercato) {
            case "eurotlx":
                $bond = new Bond(isin2bond_tlx($stock->isin, $preferences->isin_lookup_eurotlx));
                $bond->isin = $stock->isin;
                break;
            case "tlx":
                $bond = new Bond(isin2bond_tlx($stock->isin, $preferences->isin_lookup_eurotlx));
                $bond->isin = $stock->isin;
                break;
        }
        print_r($bond);
        $bond->_force_create = TRUE;
        $bond->_ignore = TRUE;
        $bond->save();
    }
}
printf("%d tracked stocks\n", count($stocks));