当前位置: 首页>>代码示例>>PHP>>正文


PHP exchange::nearestTradeDay方法代码示例

本文整理汇总了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());
    }
}
开发者ID:kombat003,项目名称:trader-dss,代码行数:47,代码来源:portfolios.php


注:本文中的exchange::nearestTradeDay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。