public static function updateDoctor() { self::$log->debugLog("Begin Update Ths Doctor"); //$i = 2; $list = Refer::getStock(); foreach ($list as $item) { //if (--$i < 0 ) break; if ('sz300033' == $item['code']) { continue; } $numCode = substr($item['code'], 2); $url = "http://doctor.10jqka.com.cn/" . $numCode . '/'; self::$log->debugLog($item['name'], $item['code'], $url); $html = ThsDoctorKeeper::fetchSingleThsDoctor($url, $numCode); if ($html) { self::$log->debugLog($item['name'], $item['code'], "Fetch ThsDoctor Success"); $now = ThsDoctorKeeper::parseThsDoctorHtml($html); if ($now) { $tdd = new ThsDoctorData($item['code']); $last = $tdd->getThsDoctorData(); //print_r($last); if ($last) { $updata = ThsDoctorKeeper::mergeThsDoctorUpdate($last, $now); ThsDoctorKeeper::addThsDoctor($tdd->getDataFile(), $updata); } else { $updata = $now; ThsDoctorKeeper::putThsDoctor($tdd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update ThsDoctor Success"); } else { self::$log->errorLog($item['name'], $item['code'], "Parse ThsDoctor Failed"); self::$tmp->putTmpContent('thsdoctor.duty.failed', join(":", $item) . "|", FILE_APPEND); } $now = ThsDoctorKeeper::parseThsDoctorMesHtml($html); if ($now) { $tdmd = new ThsDoctorMesData($item['code']); $last = $tdmd->getThsDoctorMesData(); //print_r($last); if ($last) { $updata = ThsDoctorKeeper::mergeThsDoctorMesUpdate($last, $now); ThsDoctorKeeper::addThsDoctor($tdmd->getDataFile(), $updata); } else { $updata = $now; ThsDoctorKeeper::putThsDoctor($tdmd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update ThsDoctorMes Success"); } else { self::$log->errorLog($item['name'], $item['code'], "Parse ThsDoctorMes Failed"); } } else { self::$log->errorLog($item['name'], $item['code'], "Fetch ThsDoctor Failed"); self::$tmp->putTmpContent('thsdoctor.duty.failed', join(":", $item) . "|", FILE_APPEND); } } self::$log->debugLog("Finish Update Ths Doctor"); }
public static function testReferData() { $rows = Refer::getStock(); $columns = array_keys($rows[0]); for ($i = 0; $i < sizeof($columns); $i++) { $t = str_replace('_', ' ', $columns[$i]); $columns[$i] = array('title' => $t, 'data' => $columns[$i]); } echo json_encode(array('columns' => $columns, 'rows' => $rows)); }
public static function updateGbbq() { self::$log->debugLog("Begin Update Gbbq"); /* $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_000001.shtml"; $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie')); $json = DayKeeper::parseXueqiuJson($json); var_dump($json); */ $p = -1; $list = Refer::getStock(); //得到进度 $content = self::$tmp->getTmpContent('gbbq.step.process'); $content = explode('===', $content); $lastProcess = $content && $content[0] ? $content[0] : -1; foreach ($list as $item) { $p++; //if ($p >= 3 ) break; if ($p < $lastProcess) { continue; } self::$tmp->putTmpContent('gbbq.step.process', $p . '===' . $item['code'] . ' ' . $item['name']); $numCode = substr($item['code'], 2); $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_" . $numCode . ".shtml"; self::$log->debugLog($item['name'], $item['code'], $url); $html = GbbqKeeper::fetchSingleGbbq($url, $numCode); if ($html) { self::$log->debugLog($item['name'], $item['code'], "Fetch Gbbq Success"); $now = GbbqKeeper::parseGbbqHtml($html); if ($now) { $gd = new GbbqData($item['code']); $last = $gd->getGbbqData(); if ($last) { $updata = GbbqKeeper::mergeUpdate($last, $now); GbbqKeeper::addGbbq($gd->getDataFile(), $updata); } else { $updata = $now; GbbqKeeper::putGbbq($gd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update Gbbq Success"); self::$tmp->putTmpContent('gbbq.step.success', join(":", $item) . "|", FILE_APPEND); } else { self::$log->errorLog($item['name'], $item['code'], "Parse Gbbq Failed"); self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND); } } else { self::$log->errorLog($item['name'], $item['code'], "Fetch Gbbq Failed"); self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND); } } self::$log->debugLog("Finish Update Gbbq"); self::$tmp->putTmpContent('gbbq.step.process', ''); }
public static function calcRange($start, $end, $n) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_' . $n . '_Good.Table.txt'; $limiter = 2; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array('name' => '', 'code' => '', 'MaxRange' => 0, 'DayNum' => 0); $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DayData($stkL['code'], 'before'); if (!$dd->prepareData()) { continue; } $day = $dd->getDayPeriod($start, $end, $n - 1); //var_dump($day); if (!$day) { continue; } $MaxRange = -2; for ($i = 0; $i < $n / 2; $i++) { $daySlice = array_slice($day, $i, $n); if (!$daySlice) { continue; } $dMax = LogicOperation::highValue($daySlice, 'close'); $dMin = $daySlice[0]['close']; $dR = ceil(($dMax - $dMin) / $dMin * 100) / 100; $MaxRange = $MaxRange < $dR ? $dR : $MaxRange; } $stkT['MaxRange'] = $MaxRange; $stkT['DayNum'] = sizeof($day); $tdd = new ThsDoctorData($stkL['code']); $t = $tdd->prepareData() ? $tdd->getDayPeriod($start, $end) : array(); //message_score $stkT['message_score_max'] = LogicOperation::highValue($t, 'message_score'); $stkT['message_score_min'] = LogicOperation::lowValue($t, 'message_score'); $stkT['message_score_dis'] = $stkT['message_score_max'] - $stkT['message_score_min']; //basic_score $stkT['basic_score_max'] = LogicOperation::highValue($t, 'basic_score'); $stkT['basic_score_min'] = LogicOperation::lowValue($t, 'basic_score'); //total_score $stkT['total_score_max'] = LogicOperation::highValue($t, 'total_score'); $stkT['total_score_min'] = LogicOperation::lowValue($t, 'total_score'); //var_dump($stkT); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function calcDdeNum($start, $end) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_DdeNum.Table.txt'; $i = 2; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$i < 0 ) break; $stkT = array('name' => '', 'code' => '', 'DdxNum' => 0, 'DdxPer' => 0, 'DdzNum' => 0, 'DdzPer' => 0, 'TddzNum' => 0, 'TddzPer' => 0, 'TotalNum' => 0, 'TotalPer' => 0, 'DayNum' => 0); $stkT['name'] = '<a target="_blank" href="' . Url::getPhpUri('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DdeData($stkL['code']); if (!$dd->prepareData()) { continue; } $dde = $dd->getDayPeriod($start, $end, 1); //var_dump($dde); if (!$dde) { continue; } foreach ($dde as $d) { //echo $d['ddx']. '('; //echo ($d['ddx'] > 0). ')'; if ($d['ddx'] > 0) { $stkT['DdxNum']++; } if ($d['ddz'] > 0) { $stkT['DdzNum']++; } if ($d['tddz'] > 0) { $stkT['TddzNum']++; } } $stkT['DayNum'] = sizeof($dde); $stkT['DdxPer'] = ceil($stkT['DdxNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['DdzPer'] = ceil($stkT['DdzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TddzPer'] = ceil($stkT['TddzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TotalNum'] = $stkT['DdxNum'] + $stkT['TddzNum'] + $stkT['TddzNum']; $stkT['TotalPer'] = ceil($stkT['TotalNum'] / $stkT['DayNum'] / 3 * 10000) / 10000; //var_dump($stkT); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function calcMessJump() { $resultFile = self::$thisTaskDataPath . 'Pick_MessJump.Table.txt'; $limiter = 10; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array(); $tdd = new ThsDoctorData($stkL['code']); if (!$tdd->prepareData()) { continue; } $ths_2 = $tdd->getLastPeriod(1, true, 2); if (!$ths_2) { continue; } //var_dump($ths_2); $ths_x = $tdd->getLastPeriod(40, true, 10); if (!$ths_x) { continue; } //var_dump($ths_x); if ($ths_2[1]['message_score'] - $ths_2[0]['message_score'] <= 0) { continue; } $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; //message_score in yesterday and today $stkT['mess_score_yesterday'] = $ths_2[0]['message_score']; $stkT['mess_score_today'] = $ths_2[1]['message_score']; $stkT['mess_score_change'] = $ths_2[1]['message_score'] - $ths_2[0]['message_score']; //message_score in 40 days $stkT['mess_score_max_40d'] = LogicOperation::highValue($ths_x, 'message_score'); $stkT['mess_score_min_40d'] = LogicOperation::lowValue($ths_x, 'message_score'); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function updataAllDay() { self::$log->debugLog("Begin Update All Day"); /* $url = "https://xueqiu.com/stock/forchartk/stocklist.json?symbol=SH000001&period=1day&type=normal&begin=1416728848774&end=1448264848774"; $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie')); $json = DayKeeper::parseXueqiuJson($json); var_dump($json); */ self::$tmp->addTmp('day.duty.failed', true); //更新大盘指数的日线数据 normal $list = Refer::getMarket(); //$limit = 1; foreach ($list as $item) { //if ($limit-- <= 0) break; self::updateSingleDay($item, 'normal'); } //更新个股的日线数据 $list = Refer::getStock(); $rights = array('before', 'normal', 'after'); foreach ($list as $item) { foreach ($rights as $type) { self::updateSingleDay($item, $type); } } self::$log->debugLog("Finish Update All Day"); }
public static function calcV2P($start, $end) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_Vol2Price.Table.txt'; $limiter = 200; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array(); $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DayData($stkL['code'], 'before'); if (!$dd->prepareData()) { continue; } $day = $dd->getDayPeriod($start, $end, 3); if (!$day) { continue; } //var_dump($day); $s_day = 0; $s_V2P = 0; for ($i = 2; $i < count($day); $i++) { //处理当日涨跌停 $is_zt = ($day[$i]["high"] - $day[$i - 1]["close"]) / $day[$i - 1]["close"]; $is_dt = ($day[$i - 1]["close"] - $day[$i]["low"]) / $day[$i - 1]["close"]; $valid_vol = $day[$i]["volume"] / $day[$i - 1]["volume"]; //涨跌停 并且 量小于0.3 不参与计算 if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) { continue; } //处理前日涨跌停 $is_zt = ($day[$i - 1]["high"] - $day[$i - 2]["close"]) / $day[$i - 2]["close"]; $is_dt = ($day[$i - 2]["close"] - $day[$i - 1]["low"]) / $day[$i - 2]["close"]; $valid_vol = $day[$i - 1]["volume"] / $day[$i - 2]["volume"]; //涨跌停 并且 量小于0.3 不参与计算 if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) { continue; } //处理量太小不值得计算 $k1 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100; $k2 = ($day[$i]["volume"] - $day[$i - 2]["volume"]) / $day[$i - 2]["volume"] * 100; if (abs($k1) < 20 && abs($k2) < 20) { continue; } //计算V2P公式 //计算量相关 $q2 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100; if ($q2 < -100) { $q2 = -100; } if ($q2 > 100) { $q2 = 100; } //计算价格相关 $chg = $day[$i]["chg"] * 100; $q1 = $chg; if ($chg > 60) { $q1 = 16; } if ($chg <= 60 && $chg > 30) { $q1 = ($chg - 30) / 15 + 13; } if ($chg <= 30 && $chg > 10) { $q1 = ($chg - 10) / 7 + 10; } if ($chg < -60) { $q1 = -16; } if ($chg >= -60 && $chg < -30) { $q1 = ($chg + 30) / 15 - 13; } if ($chg >= -30 && $chg < -10) { $q1 = ($chg + 10) / 7 - 10; } $q1 = $q1 > 0 ? ceil($q1 + 100) : ceil($q1 - 100); $V2P = $q1 * $q2; if ($chg <= 10 && $chg >= -10) { $V2P = abs(110 * $q2); } // 统计 $s_day++; $s_V2P += $V2P; } $stkT['Vol2Price'] = $s_day ? ceil($s_V2P / $s_day) : 0; $stkT['ValidDayNum'] = $s_day; $stkT['TotalDayNum'] = count($day); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function updateGpcxwDde() { //日志文件 self::$log = new Log(LOG_PATH, __FILE__); //临时文件 self::$tmp = new Tmp(TMP_PATH); self::$tmp->addTmp('dde.gpcxw.duty.cookie', false); self::$tmp->addTmp('dde.gpcxw.duty.failed', true); self::$tmp->addTmp('dde.gpcxw.duty.process', false); self::$log->debugLog("Begin Update Gpcxw Dde"); $host = 'www.gpcxw.com'; $referer = 'baidu.com'; //首先获取cookie $url = 'http://www.gpcxw.com/ddx/000703.html'; $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); $p = -1; $list = Refer::getStock(); //得到进度 $content = self::$tmp->getTmpContent('dde.gpcxw.duty.process'); $content = explode('===', $content); $lastProcess = $content && $content[0] ? $content[0] : -1; foreach ($list as $item) { $p++; //if ($p >= 3 ) break; if ($p < $lastProcess) { continue; } self::$tmp->putTmpContent('dde.gpcxw.duty.process', $p . '===' . $item['code'] . ' ' . $item['name']); $numCode = substr($item['code'], 2); $data = 0; $dde = new DdeData($item['code']); $last = $dde->getDdeData(); //抓取页面 while (!$data) { if ($data !== 0) { sleep(1); } $data = false; //抓取最新的数据 $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = 'http://www.gpcxw.com/ddx/data2/dde.htm?code=' . $numCode; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran; self::$log->debugLog($item['name'], $item['code'], 'new', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //处理停牌 if (substr($content, 0, 7) == 'tingpai') { $data = false; break; } //读取最新的数据 $cuts = explode('==', $content); if (sizeof($cuts) != 3) { continue; } $k = explode('<=>', $cuts[1]); $k = end($k); $k = explode(' ', $k); $new = $k[0]; $k = explode('<=>', $cuts[2]); $k = end($k); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; //新增的个股 需要抓取历史数据 if (!$last) { //抓取历史的数据 $k = explode('<=>', $cuts[0]); $lastfilemtime = end($k); $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = $url; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran . '&lastfilemtime=' . $lastfilemtime . '&getlsold=1'; self::$log->debugLog($item['name'], $item['code'], 'history', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //读取历史数据 $cuts = explode('<=>', $content); if (sizeof($cuts) != 2) { continue; } $k = end($cuts); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; } $data = DdeKeeper::parseGpcxwDde($new); } //print_r($data); //处理停牌 if (!$data) { self::$log->noticeLog($item['name'], $item['code'], "TingPai"); continue; } if ($last) { $updata = DdeKeeper::mergeUpdate($last, $data); DdeKeeper::addDde($dde->getDataFile(), $updata); } else { $updata = $data; DdeKeeper::putDde($dde->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update Gpcxw Dde Success"); } self::$log->debugLog("Finish Update Gpcxw Dde"); self::$tmp->putTmpContent('dde.gpcxw.duty.process', ''); }
public static function testRefer() { echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>'; $b = Refer::getStock(); var_dump($b); }