Ejemplo n.º 1
0
 function _titoli($mercato)
 {
     $conn = $this->get_connection();
     $stock_factory = new Stock();
     $stocks = $stock_factory->find_all(array('where_clause' => "`attivo` = 1 " . ($mercato !== NULL ? " AND `mercato` = '{$conn->escape($mercato)}' " : ''), 'order_by' => '`title` ASC ', 'limit' => 99999999));
     if (count($stocks) > 0) {
         $this->stocks = array_map(function ($t) {
             return "\t{\n\t\t\"isin\": \"" . $t->isin . "\",\n\t\t\"title\": \"" . $t->title . "\"\n\t}";
         }, $stocks);
     }
     $this->render(array('action' => 'titoli', 'layout' => FALSE));
 }
Ejemplo n.º 2
0
 /**
  *  @fn index
  *  @short Lists active instruments
  *  @details Action to list the catalog of active instruments, filtered by
  *  attributes like market, type, currency, and sorted by any of the columns
  *  (defaults to <code>title</code>).
  */
 public function index()
 {
     $conn = $this->get_connection();
     $stock_factory = new Stock();
     $details = array('where_clause' => (is_numeric($_REQUEST['attivo']) ? "`attivo` = {$conn->escape($_REQUEST['attivo'])} " : '`attivo` = 1 ') . (!empty($_REQUEST['mercato']) ? "AND `mercato` = '{$conn->escape($_REQUEST['mercato'])}' " : '') . (!empty($_REQUEST['tipo']) ? "AND `tipo` = '{$conn->escape($_REQUEST['tipo'])}' " : '') . (!empty($_REQUEST['divisa']) ? "AND `divisa` = '{$conn->escape($_REQUEST['divisa'])}' " : ''), 'order_by' => sprintf('`%s` %s', $this->get_sort('title'), $this->get_dir()), 'start' => $this->get_start(), 'limit' => $this->get_limit());
     $this->stocks = $stock_factory->find_all($details);
     $this->count = $stock_factory->count_all($details);
     if ($_REQUEST['tipo'] == 'obbligazione') {
         $this->bonds_only = TRUE;
         foreach ($this->stocks as $stock) {
             $stock->has_one('bond');
         }
     }
 }
Ejemplo n.º 3
0
 function add()
 {
     if ($this->request->is_post()) {
         $item = new Dividend($_POST);
         $item->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         $stock_factory = new Stock();
         $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC'));
         $this->stocks = array('-1' => 'Scegli...');
         foreach ($stocks as $stock) {
             $this->stocks[$stock->isin] = $stock->title;
         }
     }
 }
Ejemplo n.º 4
0
 function add()
 {
     if ($this->request->is_post()) {
         $transaction = new Transaction($_POST);
         // Salvo la transazione
         $transaction->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         $stock_factory = new Stock();
         $stocks = $stock_factory->find_all(array('where_clause' => "`attivo` = 1 ", 'order_by' => '`title` ASC', 'limit' => 9999));
         $this->stocks = array('' => 'Scegli...');
         foreach ($stocks as $stock) {
             $this->stocks[$stock->isin] = $stock->title;
         }
     }
 }
Ejemplo n.º 5
0
 function add()
 {
     if ($this->request->is_post()) {
         $item = new WatchlistItem($_POST);
         $item->utente = $_COOKIE['username'];
         $item->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         if (!empty($_GET['id'])) {
             $this->stock = new Stock();
             $this->stock->find_by_id($_GET['id']);
             $this->render(array('action' => 'add_by_isin'));
         } else {
             $stock_factory = new Stock();
             $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC'));
             $this->stocks = array('-1' => 'Scegli...');
             foreach ($stocks as $stock) {
                 $this->stocks[$stock->isin] = $stock->title;
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function test_find_all_where_clause()
 {
     $instance_factory = new Stock();
     $instances = $instance_factory->find_all(array('where_clause' => "`isin` = 'IT0000000000'"));
     $this->assertNotNull($instances);
     $this->assertEquals(1, count($instances));
     foreach ($instances as $instance) {
         $this->assertNotNull($instance);
         $this->assertEquals('IT0000000000', $instance->isin);
     }
     $instances = $instance_factory->find_all(array('where_clause' => "`tipo` = 'azione'"));
     $this->assertNotNull($instances);
     $this->assertEquals(2, count($instances));
     foreach ($instances as $instance) {
         $this->assertNotNull($instance);
         $this->assertEquals('azione', $instance->tipo);
     }
 }
Ejemplo n.º 7
0
    $error->date = date('Y-m-d H:i:s');
    $error->text = $errstr;
    $error->save();
}
class SchedulerContext
{
    public $stocks = array();
    public $preferences = NULL;
}
// set_error_handler('handle_errors', E_ALL | E_STRICT | E_NOTICE | ~E_DEPRECATED);
date_default_timezone_set('Europe/Rome');
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('limit' => 1500));
// print_r($stocks);
$context = new SchedulerContext();
$context->stocks = $stocks;
$context->preferences = $preferences;
if (isset($argv[1])) {
    $arg = $argv[1];
    if (is_numeric($arg)) {
        $context->level = $argv[1];
    } else {
        $context->agent_name = $arg;
    }
}
AgentPool::run_pool($context);
Ejemplo n.º 8
0
 private function get_stocks($stock_deltas)
 {
     $conn = $this->get_connection();
     $stock_factory = new Stock();
     $params = array('where_clause' => "`isin` IN ('" . implode("','", array_map($conn->escape, array_keys($stock_deltas))) . "')" . (!empty($_REQUEST['mercato']) ? "AND `mercato` = '{$conn->escape($_REQUEST['mercato'])}' " : '') . (!empty($_REQUEST['tipo']) ? "AND `tipo` = '{$conn->escape($_REQUEST['tipo'])}' " : '') . (!empty($_REQUEST['divisa']) ? "AND `divisa` = '{$conn->escape($_REQUEST['divisa'])}' " : ''), 'order_by' => sprintf('`%s` %s ', $this->get_sort('isin'), $this->get_dir()), 'start' => $this->get_start(), 'limit' => $this->get_limit());
     $stocks = $stock_factory->find_all($params);
     $results = array();
     foreach ($stocks as $stock) {
         $p = new PortfolioStock();
         $p->isin = $stock->isin;
         $p->quantita = abs($stock_deltas[$p->isin]);
         $p->stock = $stock;
         $p->removed = TRUE;
         // TODO:
         // $p->prezzo =
         $results[] = $p;
     }
     return $results;
 }
Ejemplo n.º 9
0
<?php 
ini_set('max_execution_time', 3000);
require_once dirname(__FILE__) . "/lib.inc.php";
require_once dirname(__FILE__) . "/../include/db.inc.php";
require_once dirname(__FILE__) . "/../include/" . DB_ADAPTER . "_adapter.php";
require_once dirname(__FILE__) . "/../models/preference.php";
require_once dirname(__FILE__) . "/../models/bond.php";
require_once dirname(__FILE__) . "/../models/stock.php";
date_default_timezone_set('Europe/Rome');
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;