本文整理汇总了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());
}
}