本文整理汇总了PHP中Stock::addToMarket方法的典型用法代码示例。如果您正苦于以下问题:PHP Stock::addToMarket方法的具体用法?PHP Stock::addToMarket怎么用?PHP Stock::addToMarket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock::addToMarket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_new
public static function add_new($c_name, $info, $ini_s_price, $thres_stock_val = 20, $total_stocks = 1000000)
{
$database = new Database();
$c_name = $database->escape_value($c_name);
$info = $database->escape_value($info);
$ini_s_price = $database->escape_value($ini_s_price);
$thres_stock_val = (int) $thres_stock_val;
$total_stocks = (int) $total_stocks;
$query = "INSERT INTO " . self::$table . " (c_name,info,ini_s_price,thres_stock_val,total_stocks,day_open_price,prev_day_close_price,bought_stocks) ";
$query .= " VALUES ('{$c_name}','{$info}',{$ini_s_price},{$thres_stock_val},{$total_stocks},{$ini_s_price},0,0)";
$insert = $database->query($query);
if ($insert) {
$query = "SELECT id FROM " . self::$table;
$query .= " WHERE c_name = '" . $c_name . "' LIMIT 1";
$find = $database->query($query);
if ($find) {
$sc_id = $database->fetch_array($find);
$sc_id = $sc_id['id'];
if (Stock::addToMarket($sc_id, $ini_s_price)) {
if (StockHistory::add($sc_id, $ini_s_price)) {
if (StockControl::add($sc_id)) {
return true;
} else {
Log::add("Failed to add to StockControl - {$sc_id}", LOG_MANUAL);
return false;
}
} else {
Log::add("Failed to add to StockHistory,StockControl - {$sc_id}", LOG_MANUAL);
return false;
}
} else {
Log::add("Failed to add to StockMarket,StockHistory,StockControl - {$sc_id}", LOG_MANUAL);
return false;
}
} else {
Log::add("Failed to find new stockCompany record (add in StockMarket,StockHistory,StockControl)-{$sc_id} ", LOG_MANUAL);
}
} else {
return false;
}
}
示例2: stockUpdate
public function stockUpdate()
{
$stock_control = new StockControl($this->sc_id);
$cur_price = Stock::getCurPrice($this->sc_id);
if ($stock_control->getOverride() == -1) {
$val = mt_rand(-abs($stock_control->low), -abs($stock_control->high));
$new_val = $cur_price + $val;
/*
* Check if over_value as been reached or not! if it has
* then terminate the control function
*/
if ($stock_control->over_value >= $new_val) {
$stock_control->setOverride(0);
$stock_control->writeControl();
Stock::addToMarket($this->sc_id, $new_val);
return true;
}
if ($this->threshold < $new_val) {
Stock::addToMarket($this->sc_id, $new_val);
return true;
} else {
/*
* Reached ground value so turn overide off now!
*/
$stock_control->setOverride(0);
$stock_control->writeControl();
$val = mt_rand(0, abs(2 * $stock_control->high));
$new_val = $cur_price + $val;
Stock::addToMarket($this->sc_id, $new_val);
return true;
}
} elseif ($stock_control->getOverride() == 1) {
$val = mt_rand(abs($stock_control->low), abs($stock_control->high));
$new_val = $cur_price + $val;
/*
* Check if over_value as been reached or not! if it has
* then terminate the control function
*/
if ($stock_control->over_value <= $new_val) {
$stock_control->setOverride(0);
$stock_control->writeControl();
Stock::addToMarket($this->sc_id, $new_val);
return true;
}
Stock::addToMarket($this->sc_id, $new_val);
return true;
} else {
$news = News::getNewsForStock($this->sc_id);
if (is_array($news) && !empty($news)) {
$new = array_shift($news);
if ($new['p_change'] > 0) {
if ($new['price_value'] > $cur_price) {
$val_diff = $new['price_value'] - $cur_price;
if ($val_diff > 400) {
$reduce = (int) $val_diff / mt_rand(40, 80);
$new_val = $cur_price + $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} elseif ($val_diff > 200) {
$reduce = (int) $val_diff / mt_rand(20, 40);
$new_val = $cur_price + $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} elseif ($val_diff > 100) {
$reduce = (int) $val_diff / mt_rand(10, 20);
$new_val = $cur_price + $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} else {
$reduce = mt_rand(0, 3);
$new_val = $cur_price + $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
}
} else {
News::newsDone($new['id']);
}
} else {
//Negative price changee in news
if ($new['price_value'] < $cur_price) {
$val_diff = $cur_price - $new['price_value'];
if ($val_diff > 400) {
$reduce = (int) $val_diff / mt_rand(40, 80);
$new_val = $cur_price - $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} elseif ($val_diff > 200) {
$reduce = (int) $val_diff / mt_rand(20, 40);
$new_val = $cur_price - $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} elseif ($val_diff > 100) {
$reduce = (int) $val_diff / mt_rand(10, 20);
$new_val = $cur_price - $reduce;
Stock::addToMarket($this->sc_id, $new_val);
return true;
} else {
$reduce = mt_rand(0, 3);
$new_val = $cur_price - $reduce;
/*
//.........这里部分代码省略.........