function update_all_daily_data() { $status = ''; $query = mysql_query("SELECT * FROM stocks"); while ($array = mysql_fetch_array($query)) { $stock = new Stock($array); if (update_stock_daily($stock->getTicker())) { $status .= 'Successfully Updated all stock info for ' . $stock->getTicker() . '<br />'; } else { $status .= 'Failed to update stock ' . $stock->getTicker() . '<br />'; } } return $status; }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php error_reporting(E_ALL ^ E_NOTICE); require_once 'model.php'; require_once 'php-ofc-library/open-flash-chart-object.php'; require_once 'php-ofc-library/open-flash-chart.php'; require_once 'php-ofc-library/ofc_candle.php'; $ticker = $_REQUEST['s']; //update_stock_info($ticker); update_stock_daily($ticker); update_stock_info($ticker); $stock = get_stock($ticker); $t = $_REQUEST['t']; if ($t == "") { $t = 20; } $tid = $_REQUEST['tid']; $sa = $_REQUEST['sa']; $sb = $_REQUEST['sb']; $sc = $_REQUEST['sc']; $sd = $_REQUEST['sd']; $se = $_REQUEST['se']; $chart_url = urlencode('chart.php?t=' . $t . '&tid=' . $stock->getId() . '&sa=' . $sa . '&sb=' . $sb . '&sc=' . $sc . '&sd=' . $sd . '&se=' . $se); if ($_REQUEST['do'] == 'processTrade') { $trade = new Trade(); $message = $trade->buildFromPost(); if ($message == "") { $trade->persist(); $message = "Successfully added trade."; include 'html/green_messagebox.php'; } else {
/** * Will only deactivate if latest trade was 0 and last 5 days was also 0. */ function deactivateStock($stock_id) { $stock = new Stock($stock_id, false); //Make sure stock exists. if ($stock->getId() < 0) { return ""; } //Don't do anything if already inactive if ($stock->getStatus() == STATUS_INACTIVE) { return $stock->getTicker() . "(" . $stock->getId() . ") was already inactive."; } if (update_stock_info($stock->getTicker())) { //Only need to get new data if was updated. $stock = new Stock($stock_id, false); } if ($stock->getLastTrade() > 0.05) { return ""; } update_stock_daily($stock->getTicker()); $stock = new Stock($stock_id, true); $arr = $stock->getDailyData(); if (sizeof($arr) < 5) { //If in here, we don't have enough data which means stock is probably a weird derivative. $stock->setStatus(STATUS_INACTIVE); $stock->persist(); return "Removed Stock " . $stock->getTicker() . " (" . $stock->getId() . ") due to not enough daily data."; } //Make sure has been less than 0.05 for quite some time. if ($arr[0]->getClose() < 0.05 && $arr[1]->getClose() < 0.05 && $arr[2]->getClose() < 0.05 && $arr[3]->getClose() < 0.05) { $stock->setStatus(STATUS_INACTIVE); $stock->persist(); return "Removed Stock " . $stock->getTicker() . " (" . $stock->getId() . ") due to a last closing price of \$" . $stock->getLastTrade(); } return ""; }
} $start = $start + 1; echo $start; } else { if ($_REQUEST['do'] == 'updateStockDailyData') { $start = $_REQUEST['s']; if ($start == "") { $start = 0; } $query = mysql_query("SELECT ticker FROM stocks WHERE status = '" . STATUS_ACTIVE . "' LIMIT {$start},1") or die(mysql_error() . "DD:" . $start); if (mysql_num_rows($query) < 1) { echo -1; return; } while ($array = mysql_fetch_array($query)) { update_stock_daily($array['ticker']); } $start = $start + 1; echo $start; } else { if ($_REQUEST['do'] == 'deactivateStocks') { $start = $_REQUEST['s']; if ($start == -1) { $query = mysql_query("SELECT id FROM stocks ORDER BY id DESC LIMIT 1"); $array = mysql_fetch_array($query); echo $array['id'] + 1; return; } echo $start . "||" . deactivateStock($start); } else { if ($_REQUEST['do'] == 'showNewPortfolio') {