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(); } } } }
public static function addStochInfoAndCreate($ticker, $tid) { $parts = finance_google::retrieveSlowDAndParts($ticker); echo "\nUpdating history for " . $ticker . " TID:" . $tid; $tickerHistory = new ticker_history(); $tickerHistory->set_variable('history_price', $parts['last']); $date = date("Y-m-d h:i:s", $parts['date']); $tickerHistory->set_variable('history_date', $date); $tickerHistory->set_variable('history_ticker_id', $tid); $tickerHistory->set_variable('history_lasthigh', $parts['high']); $tickerHistory->set_variable('history_lastlow', $parts['low']); $tickerHistory->set_variable('history_r1', $parts['r1']); $tickerHistory->set_variable('history_r2', $parts['r2']); $tickerHistory->set_variable('history_fastk', $parts['fastK']); $tickerHistory->set_variable('history_slowk', $parts['slowK']); $tickerHistory->set_variable('history_slowd', $parts['slowD']); $tickerHistory->createNew(); }
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); } } } }