コード例 #1
0
 public function updateFromYahoo()
 {
     $date = date('Y-m-d H:i:s');
     $stocks = array();
     $symbol = strtoupper($this->get_variable('ticker_symbol'));
     $stocks[] = $symbol;
     $results = finance::retrieveCurrentPrice($stocks, "l1hgp2");
     foreach ($results as $key => $value) {
         if (strtoupper($key) != $symbol) {
             continue;
         }
         $stockUpdates = explode(",", $value);
         $this->set_variable('last', $stockUpdates[0]);
         $this->set_variable('today_high', $stockUpdates[1]);
         $this->set_variable('today_low', $stockUpdates[2]);
         $change = str_replace('"', "", $stockUpdates[3]);
         $change = str_replace('%', "", $change);
         $change = str_replace('+', "", $change);
         $this->set_variable('change_today_percent', $change);
         $this->set_variable('last_update', $date);
         $this->update();
     }
 }
コード例 #2
0
     }
     if ($tt == BACKDRAFT_TRADE && $action != ABANDON) {
         continue;
     }
     if ($action == ABANDON_HARD_STOP) {
         continue;
     }
     if ($action == ABANDON_AT_CLOSE) {
         continue;
     }
     echo "\nAdding Ticker Symbol for " . $symbol . " to price update list.\n";
     array_push($symbols, strtoupper($symbol));
     array_push($hids, $hid);
 }
 //$results = finance_google::retrieveCurrentPrice($symbols);
 $results = finance::retrieveCurrentPrice($symbols, "o");
 $updateHolding = new holdings();
 foreach ($hids as $updateHid) {
     $updateHolding->reset_query();
     $updateHolding->set_variable("holdings_id", $updateHid);
     if ($updateHolding->load()) {
         $symbol = strtoupper($updateHolding->get_variable('holdings_ticker_symbol'));
         $tid = $holding->get_variable('holdings_ticker_id');
         $price = floatval($results[$symbol]);
         if ($price > 0) {
             $updateHolding->set_variable("holdings_stop_price", $price);
             echo "\n<br>Changing Stop Price for " . $symbol . " to " . $price . ". Opening Price after Abandon.\n<br>";
             $updateHolding->update();
         } else {
             $str = "holdings_abandon_date LIKE '" . date("Y-m-d") . "%'";
             echo "\nNOT Changing Stop Price for " . $symbol . " to " . $price . ". Opening Price after Abandon. SOMETHiNG WRONG!! " . $str . "\n<br>";
コード例 #3
0
 public function updateHistoryAndBorders($useGoogle)
 {
     echo "\n\nUpdating History and highs and lows\n\n";
     if ($useGoogle) {
         $results = finance_google::retrieveHighsLowsPrice($this->tickerSymbols);
     }
     $results2 = finance::retrieveCurrentPrice($this->tickerSymbols, "gh");
     $date = date('Y-m-d H:i:s');
     $ticker = new ticker();
     foreach ($results2 as $key => $value) {
         $ticker->reset_query();
         $ticker->set_variable('ticker_symbol', $key);
         if ($ticker->load()) {
             $tickerClose = $ticker->get_variable('last_close');
             $tickerId = $ticker->get_variable('ticker_id');
             $last = $ticker->get_variable('last');
             $yahooArr = explode(",", $value);
             if ($yahooArr[0] == 0) {
                 $yahooArr[0] = $last;
             }
             if ($yahooArr[1] == 0) {
                 $yahooArr[1] = $last;
             }
             $lasthigh = floatval($ticker->get_variable('today_high'));
             // Yahoo is broken
             //$currenthigh = max($lasthigh, floatval ($yahooArr[1]));
             // TEST CODE
             echo "\nYAHOO HIGH: " . ($yahoohigh = max($lasthigh, floatval($yahooArr[1])));
             $currenthigh = $yahoohigh;
             // END TEST CODE
             $googleHigh = $last;
             if ($useGoogle) {
                 $googleHigh = floatval($results[$key]['high']);
                 if ($googleHigh > 0) {
                     echo "\n Updating Last High " . $key . " " . $googleHigh;
                     $ticker->set_variable('last_high', $googleHigh);
                     $ticker->update();
                     $currenthigh = max($currenthigh, $googleHigh);
                 }
             }
             $lastlow = $ticker->get_variable('today_low');
             // Yahoo is broken
             //$currentlow = min($lastlow, floatval ($yahooArr[0]));
             // TEST CODE
             $yahoolow = min($lastlow, floatval($yahooArr[0]));
             $yahoolow = $yahoolow == 0 ? $lastlow : $yahoolow;
             $currentlow = $yahoolow;
             // END TEST CODE
             $googleLow = $last;
             if ($useGoogle) {
                 $googleLow = floatval($results[$key]['low']);
                 if ($googleLow < 10000) {
                     if ($currentlow <= 0) {
                         $currentlow = $googleLow;
                         $ticker->set_variable('today_low', $currentlow);
                     }
                     $currentlow = min($googleLow, $currentlow);
                     $ticker->set_variable('last_low', $googleLow);
                     $ticker->update();
                     echo "\n Updating Last Low " . $key . " " . $googleLow . " And today low " . $currentlow;
                 }
             }
             $lastupdate = date('Y-m-d', strtotime($ticker->get_variable('last_highlow_update')));
             $today = date('Y-m-d');
             echo "\n\nTESTING HIGH and LOW of " . $key . " as " . $currenthigh . " : " . $currentlow . "\n";
             $doUpdate = false;
             if ($currenthigh != 0 && ($today != $lastupdate || $currenthigh > $lasthigh)) {
                 echo "\nset high " . $currenthigh;
                 $ticker->set_variable('yahoo_high', round($yahoohigh, 2));
                 $ticker->set_variable('today_high', round($currenthigh, 2));
                 $doUpdate = true;
             }
             if ($currentlow != 0 && ($today != $lastupdate || $currentlow < $lastlow)) {
                 echo "\nset low " . $currentlow;
                 $ticker->set_variable('yahoo_low', round($yahoolow, 2));
                 $ticker->set_variable('today_low', round($currentlow, 2));
                 $doUpdate = true;
             }
             if ($doUpdate) {
                 if ($today != $lastupdate) {
                     echo "\nset last ";
                     $ticker->set_variable('last_highlow_update', $today);
                 }
                 $ticker->update();
             }
             // add ticker history
             /*
             
             $tickerHistory = new ticker_history();
             $tickerHistory->set_variable('history_price', $last);
             $tickerHistory->set_variable('history_date', $date);
             $tickerHistory->set_variable('history_ticker_id', $tickerId);
             if ($googleHigh > 0)
             $tickerHistory->set_variable('history_lasthigh', $googleHigh);
             else
             $tickerHistory->set_variable('history_lasthigh', $last);
             
             if ($googleLow < 10000)
             $tickerHistory->set_variable('history_lastlow', $googleLow);
             else
             $tickerHistory->set_variable('history_lastlow', $last);
             $tickerHistory->addStochInfoAndCreate($last);
             *
             */
             //ticker_history::addStochInfoAndCreate($key, $tickerId);
             // remove oldest history
             $tickerHistory = new ticker_history();
             $tickerHistory->set_variable('history_ticker_id', $tickerId);
             $numHistory = $tickerHistory->countAll('', '', 'history_id');
             $tickerHistory->reset_query();
             $limit = NUM_HISTORY_TO_KEEP;
             if ($numHistory > $limit) {
                 $limit = $numHistory - $limit;
                 $tickerHistory->delete(" WHERE history_ticker_id='" . $tickerId . "' ORDER BY history_date ASC LIMIT " . $limit);
             }
         }
     }
 }