/**
  * Default Page.
  *
  * @Route("/{codigo}/show", name="cotacao_show")
  * @Method("GET")
  * @Template("RoyopaSicinBundle:Cotacao:show.html.twig")
  */
 public function showAction($codigo)
 {
     $client = new \Scheb\YahooFinanceApi\ApiClient();
     $ativo = $client->search($codigo);
     if (count($ativo['ResultSet']['Result']) == 0) {
         return new Response('Ativo não encontrado.');
     }
     $ativo = $ativo['ResultSet']['Result'][0];
     $dataInicial = new \DateTime('now');
     $interval = new \DateInterval('P3M');
     $interval->invert = 1;
     $dataInicial = $dataInicial->add($interval);
     $chart = new Highchart(Highchart::HIGHSTOCK);
     $chart->chart->renderTo = "container";
     $chart->rangeSelector->selected = 1;
     $chart->title->text = "AAPL Stock Price";
     $chart->series[] = array('name' => "AAPL", 'data' => new HighchartJsExpr("data"), 'tooltip' => array('valueDecimals' => 2));
     //Get historical data
     $data = $client->getHistoricalData($ativo['symbol'], $dataInicial, new \DateTime('now'));
     return array('ativo' => $ativo, 'entities' => $data['query']['results'], 'chart' => $chart);
 }
 public static function getStockList($stocks)
 {
     $client = new \Scheb\YahooFinanceApi\ApiClient();
     return colect($client->getQuotesList($stocks));
 }
Beispiel #3
0
 public function getHistoricalData()
 {
     $quotes = array();
     $client = new \Scheb\YahooFinanceApi\ApiClient();
     try {
         sleep(0.8);
         $hist_data1 = $client->getHistoricalData($this->ticker, new \DateTime("-1 year"), new \DateTime("-1 day"));
         sleep(0.8);
         $hist_data2 = $client->getHistoricalData($this->ticker, new \DateTime("-2 years"), new \DateTime("-1 year"));
         $data1 = $hist_data1['query']['results']['quote'];
         $data2 = $hist_data2['query']['results']['quote'];
         $data = array_merge($data1, $data2);
         foreach ($data as $datum) {
             $quotes[strtotime($datum['Date']) * 1000] = round($datum['Close'], 2);
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     return $quotes;
 }
 private function curlRequest($query)
 {
     $url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22AAPL%22%29&env=store://datatables.org/alltableswithkeys';
     $client = new \Scheb\YahooFinanceApi\ApiClient();
     $data = $client->getQuotes($query);
     return $data["query"]["results"]["quote"];
 }
Beispiel #5
0
}
function is_market_closed($date)
{
    $year = $date->format('Y');
    // federal holidays
    $federal_holidays = [adjust_fixed_holiday($year . '-01-01'), date('Y-m-d', strtotime("third Monday of January {$year}")), date('Y-m-d', strtotime("third Monday of February {$year}")), date("Y-m-d", strtotime("+" . (easter_days($year) - 2) . " days", strtotime("{$year}-03-21 12:00:00"))), date('Y-m-d', strtotime("last Monday of May {$year}")), adjust_fixed_holiday($year . '-07-04', 'last friday'), date('Y-m-d', strtotime("first Monday of September {$year}")), date('Y-m-d', strtotime("last Thursday of November {$year}")), adjust_fixed_holiday($year . '-12-25')];
    if (in_array($date->format('Y-m-d'), $federal_holidays)) {
        $date->modify('next day');
    }
    // saturday or sunday
    if (is_weekend($date)) {
        $date->modify('next monday');
    }
    return $date->format('Y-m-d');
}
$client = new \Scheb\YahooFinanceApi\ApiClient();
$mutual_funds = ['FPHAX', 'FRXIX'];
$funds = [];
foreach ($mutual_funds as $mutual_fund) {
    $symbol = $mutual_fund;
    $start_date = new DateTime('2015-09-01');
    $end_date = new DateTime('NOW');
    $history_nav = $client->getHistoricalData($symbol, $start_date, $end_date);
    $current_nav = $client->getQuotes($symbol);
    $current_nav = $current_nav['query']['results']['quote']['LastTradePriceOnly'];
    //print '<pre>';
    //print_r($history_nav);
    //print '</pre>';
    //exit;
    $interval = DateInterval::createFromDateString('first day of next month');
    $period = new DatePeriod($start_date, $interval, $end_date, DatePeriod::EXCLUDE_START_DATE);