Пример #1
0
function abandonNowStocks()
{
    $holding = new holdings();
    $holding->set_variable("holdings_last_action", ABANDON_AT_CLOSE);
    $holding->set_variable("holdings_abandon_marked", 0);
    $symbols = array();
    $hids = array();
    $hasAbandon = false;
    while ($holding->loadNext()) {
        $symbol = $holding->get_variable('holdings_ticker_symbol');
        $tid = $holding->get_variable('holdings_ticker_id');
        $hid = $holding->get_variable('holdings_id');
        if (strlen($symbol) <= 0) {
            $ticker = new ticker();
            $ticker->set_variable("ticker_id", $tid);
            if ($ticker->load()) {
                $symbol = $ticker->get_variable("ticker_symbol");
            }
        }
        array_push($symbols, strtoupper($symbol));
        array_push($hids, $hid);
        $hasAbandon = true;
    }
    if ($hasAbandon) {
        print_r($symbols);
        print_r($hids);
        $results = finance_google::retrieveCurrentPrice($symbols);
        $updateHolding = new holdings();
        foreach ($results as $key => $value) {
            if ($key == "filesize") {
                continue;
            }
            $updateHolding->reset_query();
            $ticker = $key;
            $price = floatval($value);
            if ($price > 0) {
                echo "\nTICKER:" . $ticker . " PRICE=" . $price . "\n";
                $index = array_search($ticker, $symbols);
                $hid = $hids[$index];
                $updateHolding->set_variable("holdings_id", $hid);
                if (!$updateHolding->load()) {
                    echo "WRONG::" . $ticker . " NOT RECOGNIZED IN DB\n\n";
                    continue;
                }
                $updateHolding->set_variable("holdings_stop_price", $price);
                echo "\nChanging Stop Price for " . $ticker . " to " . $price . ". Opening Price at end of day.\n";
                $updateHolding->set_variable("holdings_abandon_marked", 1);
                $updateHolding->set_variable("holdings_abandon_hide", 1);
                $updateHolding->set_variable('holdings_abandon_date', date('Y-m-d H:i:s'));
                $updateHolding->set_variable("holdings_ticker_symbol", $ticker);
                $updateHolding->update();
            }
        }
    }
}
Пример #2
0
 private function updateTickers()
 {
     $results = finance_google::retrieveCurrentPrice($this->symbolsWithExtra);
     $date = date('Y-m-d H:i:s');
     $ticker = new ticker();
     foreach ($results as $key => $value) {
         $ticker->reset_query();
         $ticker->set_variable('ticker_symbol', $key);
         if ($ticker->load()) {
             $stockUpdates = explode(",", $value);
             $last = $stockUpdates[0];
             echo "\n UPDATING " . $key . " " . $last;
             $ticker->set_variable('last', $last);
             $change = str_replace('"', "", $stockUpdates[1]);
             $ticker->set_variable('change_today_percent', $change);
             $ticker->set_variable('last_update', $date);
             $ticker->update();
         }
     }
     // UPDATE HISTORY EVERY 5 MIN WARNING:: DEPENDANT ON CRON ONLY RUNNING once a minute
     $hour = intval(date('G'));
     $minutes = intval(date('i'));
     echo "\nTesting Use Google for HOUR: " . $hour . " MINUTE:" . $minutes;
     $useGoogle = $hour >= 9 && $minutes >= 31 || $hour >= 10;
     $eod = new eod(updater::EOD_ID);
     $phpdate = strtotime($eod->get_variable('eod_date'));
     $mysqldate = date('H:i:s Y-m-d', $phpdate);
     $currentdate = date('H:i:s Y-m-d', strtotime("-4 minutes"));
     if (strtotime($mysqldate) <= strtotime($currentdate)) {
         echo "\nupdating history\n";
         $this->updateHistoryAndBorders($useGoogle);
         $eod->set_variable('eod_date', date('Y-m-d H:i:s'));
         $eod->update();
     } else {
         echo "\nNOT updating history\n";
         print_r($mysqldate);
         echo "\n";
         print_r($currentdate);
     }
     /*
     		 $hour = intval(date('G'));
     		 $minutes = intval(date('i'));
     		 $isZero = ($minutes % TIME_BETWEEN_HISTORY_UPDATES_IN_MINUTES) == 0;
     		 $isDuringDay = ($hour >= 9 && $minutes >= 31) || ($hour >= 10);
     		 $useGoogle = ($hour >= 9 && $minutes >= 31) || ($hour >= 10);
     		 echo "\ntesting checks\n";
     		 if (!empty($isZero) && $isDuringDay){
     		 }
     		 * */
 }