本文整理匯總了PHP中exchange::nearestTradeDay方法的典型用法代碼示例。如果您正苦於以下問題:PHP exchange::nearestTradeDay方法的具體用法?PHP exchange::nearestTradeDay怎麽用?PHP exchange::nearestTradeDay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exchange
的用法示例。
在下文中一共展示了exchange::nearestTradeDay方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create_portfolio
function create_portfolio($form)
{
# extract and clean all the data
global $pdo;
$pf_desc = $pdo->quote($form['pf_desc']);
$uid = $_SESSION['uid'];
$exchange = new exchange($form['exchange']);
$exch = $exchange->getID();
$parcel = $pdo->quote($form['parcel']);
$start_date = sprintf("%04d-%02d-%02d", $form['start_date']['Y'], $form['start_date']['M'], $form['start_date']['d']);
$opening_balance = $pdo->quote($form['opening']);
if (isset($form['hide'])) {
$hide = 't';
} else {
$hide = 'f';
}
if (isset($form['auto'])) {
$auto = 't';
} else {
$auto = 'f';
}
$stop_loss = $form['stop_loss'];
$tax_rate = $form['tax_rate'];
$commission = $form['commission'];
$start_date = $exchange->nearestTradeDay($start_date);
try {
$query = "select nextval('portfolios_pfid_seq') as pfid;";
$result = $pdo->query($query);
$row = $result->fetch(PDO::FETCH_ASSOC);
$next_pfid = $row['pfid'];
} catch (PDOException $e) {
tr_warn('sell_stock:' . $query . ':' . $e->getMessage());
return false;
}
// need to create the portfolio and add the first entry into summary as a transaction so that if one fails both do
try {
$pdo->beginTransaction();
$query = "insert into portfolios (pfid, name, uid, exch, opening_balance, parcel, working_date, hide_names, stop_loss, auto_stop_loss, tax_rate, commission) values ({$next_pfid}, {$pf_desc}, '{$uid}', '{$exch}', {$opening_balance}, {$parcel}, '{$start_date}', '{$hide}', '{$stop_loss}', '{$auto}', '{$tax_rate}', '{$commission}');";
$pdo->exec($query);
$query = "insert into pf_summary (pfid, date, cash_in_hand, holdings) values ({$next_pfid}, '{$start_date}', {$opening_balance}, 0);";
$pdo->exec($query);
$pdo->commit();
} catch (PDOException $e) {
$pdo->rollBack();
tr_warn('create_portfolio:' . $query . ':' . $e->getMessage());
}
}