示例#1
0
<?php

require_once __DIR__ . '/../../base.php';
$zqrs = DbConfig::getParam('zqrs', PSPACE);
$jgrq = DbConfig::getParam('prejgrq', PSPACE);
$sshq = DbConfig::getParam('sshq', PSPACE);
$i = 0;
$list = '';
echo "<pre>\n";
//*
foreach ($zqrs as $k => $row) {
    $info = Crawler_Xueqiu::getGupiaoDay($k, $prejgrq);
    if ($info) {
        $sshq[$k] = $info['close'];
    }
}
DbConfig::saveParam('sshq', $sshq, PSPACE);
// */
示例#2
0
/**
 * 保存一天的持仓记录
 * 累计计算,后续改成增量计算的,多个值计算
 *
 * 汇总头部见 dateconf[calcc]
 */
function saveDayN($jgrq, &$mon, &$totalr, &$zqrs, $checked = true)
{
    global $failedinfos;
    //获取股票当天价格
    //*
    $curcc = $mon->findByIndex('zjgf', array('date' => $jgrq), 10000, 0, array());
    foreach ($curcc as $k => $v) {
        if ($v['istotal'] == 1) {
            $okyye = $v[2] + 0;
            //可用余额
            $otzxsz = $v[3];
            //市值
        }
        $mmgu[$v[12]] = $v;
    }
    // */
    foreach ($zqrs as $k => $v) {
        $ids[] = $k . "_{$jgrq}";
    }
    $curcc = $mon->findByIndex('dayklineinfo', array('_id' => array('$in' => $ids)), 10000, 0, array());
    foreach ($curcc as $k => $v) {
        if ($v['istotal'] == 1) {
            $okyye = $v[2] + 0;
            //可用余额
            $otzxsz = $v[3];
            //市值
        }
        $infos[$v['zqdm']] = $v;
    }
    $tzxsz = 0;
    $tfdyk = 0;
    foreach ($zqrs as $k => $v) {
        $v['istotal'] = 0;
        $zqnum = $v[6];
        //证券数量
        $zxsz = 0;
        $fdyk = 0;
        $zqs = $v[8];
        //最终清算额度
        if ($zqnum != 0 && $v['pdate'] != $jgrq) {
            $info = $infos[$k];
            if (!$info && $failedinfos[$k] != 1) {
                $info = Crawler_Xueqiu::getGupiaoDay($k, $jgrq);
                //not coment after all callc
                if (!$info) {
                    echo "==getInfo failed {$k} " . $v[3] . "\n";
                    //不去尝试获取已经失败的
                    $failedinfos[$k] = 1;
                }
            }
            if ($info) {
                $v[4] = $info['close'];
                $v['pdate'] = $jgrq;
            }
        }
        if ($zqnum > 0) {
            //有的持仓
            $pre3zqdm = substr($k, 0, 3);
            if ($pre3zqdm == '204' || $pre3zqdm == '131') {
                $zxsz = 0 - $v[8];
                //回购市值用清算额
            } else {
                $zxsz = round($zqnum * $v[4], 3);
            }
            //echo $pre3zqdm." preddfd $zxsz\n";
            $v['cbj'] = round(-$zqs / $zqnum, 3);
            //if($otzxsz){
            //    $v['zcbl'] = round(100*$zxsz/$otzxsz,3);
            //}
        } elseif ($zqnum < 0) {
            //融券卖出的情况
            //暂时不处理
            //$zxsz = $zqs;
        } else {
            $zxsz = 0;
            $v[6] = 0;
            //设置为0,为显示
        }
        $fdyk = $v['fdyk'] = round($zqs + $zxsz, 3);
        //浮动盈亏
        $tfdyk += $fdyk;
        $tzxsz += $zxsz;
        $ljmr = $v['ljmr'];
        $v['zxsz'] = $zxsz;
        if ($zxsz != 0) {
            $v['ykbl'] = round($fdyk * 100 / $zxsz, 3);
        } elseif ($ljmr > 0) {
            //用累计投入做分母比较靠谱
            $v['ykbl'] = round($fdyk * 100 / $ljmr, 3);
        } else {
            // $v['ykbl'] = round($fdyk*100/$ljmr,3);
        }
        //$v[8] = round($v[8],3);
        if ($v['cdate']) {
            $v['chtime'] = App::dateDifference($v['cdate'], $v['ldate']);
        }
        //可以只存有改变的,为方便全部保存
        if ($v['ldate'] == $jgrq || $zqnum != 0) {
            //存一个最新的,保持id不变,用zero,保持一致,好添加评论
            $id = $k . '_zero';
            $v['date'] = 'lastest';
            $mon->findAndModify(array('_id' => $id), array('$set' => $v));
            if ($zqnum != 0) {
                $v['date'] = $jgrq;
                $id = $k . '_' . $jgrq;
                $mon->findAndModify(array('_id' => $id), array('$set' => $v));
            }
        }
    }
    $pretid = "total_{$jgrq}";
    $tr =& $totalr;
    //$tr[8] = round($tr[8],3);
    $tr['date'] = $jgrq;
    $kyye = $tr[8];
    $tr['zxsz'] = $tzxsz;
    //参考市值
    /*
        if($otzxsz)
            $tr['zxsz'] = $otzxsz;//参考市值
        else
            $tr['zxsz'] = $tzxsz;//参考市值
        if($okyye){
            $kyye = $okyye;
        }else{
            $kyye = $tr[8];
        }
    */
    $tr['rzye'] = round($tr['rzye'], 3);
    $tr['rqye'] = round($tr['rqye'], 3);
    $tr['kyye'] = $kyye;
    $tr['zc'] = $tr['zxsz'] + $kyye;
    //资产
    $touru = $tr['yinhangzr'] + $tr['yinhangzc'];
    $tr['yinhangtr'] = $touru;
    $tr['jsyk'] = $tr['zc'] - $touru - $tr['rzye'];
    //盈亏
    $tr['ljyk'] = $tfdyk;
    $tr['ykbl'] = round($tr['jsyk'] * 100 / $touru, 3);
    //没有处理融券余额
    $tr['cw'] = round($tr['zxsz'] * 100 / ($tr['zc'] - $tr['rzye']), 3);
    $tr['_id'] = $pretid;
    $tr['istotal'] = 1;
    //$mon->save($tr);
    $info = '';
    $info .= "{$jgrq}\n清算[{$tr[8]}]   可用 [{$kyye}] okyye[{$okyye}]\n";
    $info .= "融资余额 [{$tr['rzye']}]  融券卖出量[{$tr['rqye']}]\n";
    $info .= "市值o[{$otzxsz}]   累计 [{$tzxsz}]\n";
    $info .= "盈亏计算[{$tr['jsyk']}] 累计[{$tfdyk}]\n";
    $tr['_info'] = $info;
    $mon->findAndModify(array('_id' => $pretid), array('$set' => $tr));
    $tr['date'] = 'lastest';
    unset($tr['_id']);
    $mon->findAndModify(array('_id' => 'total_lastest'), array('$set' => $tr));
    $tr['date'] = $jgrq;
    echo "\n\n======\n{$info}";
}