function feedMajorHolder($symbol) { global $_configs; $url = 'http://datafeed.stockbiz.vn/CompanyService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => $symbol); if ($objs = _feed_stockbiz('GetMajorHolders', $url, $params)) { if (!empty($objs['GetMajorHoldersResult'])) { $db = _db('stockbiz'); $db->query('DELETE FROM _prefix_majorholder WHERE Symbol="' . $symbol . '"'); if (!isset($objs['GetMajorHoldersResult']['MajorHolder'][0])) { $objs['GetMajorHoldersResult']['MajorHolder']['Symbol'] = $symbol; $sql = buildInsertSQL('_prefix_majorholder', $objs['GetMajorHoldersResult']['MajorHolder']); $db->query($sql); } else { $objs = $objs['GetMajorHoldersResult']['MajorHolder']; for ($i = 0; $i < count($objs); $i++) { $objs[$i]['Symbol'] = $symbol; $sql = buildInsertSQL('_prefix_majorholder', $objs[$i]); $db->query($sql); } } } } else { die; } }
function feedCompanyInfo($symbol) { global $_configs; $url = 'http://datafeed.stockbiz.vn/CompanyService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => $symbol); $objs = _feed_stockbiz('GetCompanyInfo', $url, $params); print_r($objs); }
function test_feed_main() { global $_configs; $url = 'http://datafeed.stockbiz.vn/MarketDataService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => 'BBS', 'startDate' => '2009-09-23T00:00:00', 'endDate' => '2009-09-23T00:00:00'); if ($objs = _feed_stockbiz('GetHistoricalQuotes', $url, $params)) { var_dump($objs); die; } }
function feedsector_feed_main() { global $_configs; $url = 'http://datafeed.stockbiz.vn/CompanyService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass']); if ($objs = _feed_stockbiz('GetSectors', $url, $params)) { $db = _db('stockbiz'); $objs = $objs['GetSectorsResult']['Sector']; $db->query('TRUNCATE TABLE _prefix_sector'); for ($i = 0; $i < count($objs); $i++) { $sql = buildInsertSQL('_prefix_sector', $objs[$i]); $db->query($sql); } } }
function feedIndustryBySector($sectorId) { global $_configs; $url = 'http://datafeed.stockbiz.vn/CompanyService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'sectorID' => $sectorId); if ($objs = _feed_stockbiz('GetIndustries', $url, $params)) { $db = _db('stockbiz'); $objs = $objs['GetIndustriesResult']['Industry']; //Xoa nhung industry co hien tai, de du lieu luon tuoi $db->query('DELETE FROM _prefix_industry WHERE SectorId=' . $sectorId); for ($i = 0; $i < count($objs); $i++) { $sql = buildInsertSQL('_prefix_industry', $objs[$i]); $db->query($sql); } } }
function feedLastestFinalRatiosBySymbol($symbol) { global $_configs; $url = 'http://datafeed.stockbiz.vn/FinanceService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => $symbol); if ($obj = _feed_stockbiz('GetLastestFinancialRatios', $url, $params)) { /*if ($symbol=='BBS'){ var_dump($obj); die('dasdsa'); }*/ $obj = $obj['GetLastestFinancialRatiosResult']; $db = _db('stockbiz'); $db->query('DELETE FROM _prefix_lastestfinancialratios WHERE Symbol=\'' . $symbol . '\''); $obj['Symbol'] = $symbol; $sql = buildInsertSQL('_prefix_lastestfinancialratios', $obj); $db->query($sql); //echo $db->error(); } }
function insertIntoNews($obj, $values = null) { if (!empty($obj)) { $db = _db(); /** * Kiem tra su ton tai cua ID * Neu co : * + Neu noi dung co thay doi o mot trong cac field --> cap nhap * + Khong co thay doi --> bo qua * Khong co: * + Insert moi vao */ $db->query('SELECT * FROM _prefix_news WHERE stockbiz_id=' . $obj['NewsID']); //Neu news da ton tai if ($currentObj = $db->fetch()) { $sql = 'UPDATE `_prefix_news` SET sectorid=:SECTORID, industryid=:INDUSTRYID, symbol=:SYMBOL WHERE stockbiz_id=:ID'; $db->prepare($sql); $db->bindValue(':ID', $obj['NewsID'], PARAM_INT); if (isset($values['SectorId'])) { $db->bindValue(':SECTORID', $values['SectorId'], PARAM_INT); } else { $db->bindValue(':SECTORID', $currentObj['sectorid'], PARAM_INT); } if (isset($values['IndustryId'])) { $db->bindValue(':INDUSTRYID', $values['IndustryId'], PARAM_INT); } else { $db->bindValue(':INDUSTRYID', $currentObj['industryid'], PARAM_INT); } if (isset($values['Symbol'])) { $db->bindValue(':SYMBOL', $values['Symbol'], PARAM_STR); } else { $db->bindValue(':SYMBOL', '', PARAM_STR); } $db->execute($sql); } else { global $_configs; //{Lay contnet //Van de : Khi bai viet khong co content, service tra ve noi dung gioi thieu $url = 'http://datafeed.stockbiz.vn/NewsService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'newsID' => $obj['NewsID']); $result = _feed_stockbiz('GetNewsContent', $url, $params); $content = ''; if (!empty($result)) { $content = $result['GetNewsContentResult']; } //} $sql = 'INSERT INTO `_prefix_news` (stockbiz_id,news_created,news_title,news_tagline,news_alias,introimage,intro,content,is_category, is_enabled,is_showintroimage,is_tieudiem,is_quantam,view,ordering,parent_id,hasattachedfile,attachedfileName, attachedfileextension,source,feedfrom,sectorid,industryid,symbol) VALUES(:STOCKBIZ_ID,:CREATED,:TITLE,:TAGLINE,:ALIAS,:INTROIMAGE,:INTRO,:CONTENT,:IS_CATEGORY,:IS_ENABLED,:IS_SHOWINTROIMAGE,:IS_TIEUDIEM, :IS_QUANTAM,:VIEW,:ORDERING,:PARENT_ID,:HASATTACH,:ATTACHFILE,:FILEEXT,:SOURCE,:FEEDFROM,:SECTORID,:INDUSTRYID,:SYMBOL)'; $db->query('DELETE FROM _prefix_news WHERE news_id=' . $obj['NewsID']); $db->prepare($sql); $db->bindValue(':STOCKBIZ_ID', $obj['NewsID'], PARAM_INT); $date = date('Y-m-d H:m:s', strtotime($obj['Date'])); $db->bindValue(':CREATED', $date, PARAM_STR); $db->bindValue(':TITLE', $obj['Title'], PARAM_STR); $db->bindValue(':TAGLINE', '', PARAM_STR); $db->bindValue(':ALIAS', '', PARAM_STR); if ($obj['ImageUrl'] != '') { if (file_exists(_UPLOAD_IMG_ABSPATH_ . '/tin-tuc1/' . $obj['ImageUrl'] . '.jpg') || copy('http://stockbiz.vn/Handlers/GetThumbnail.axd?i=' . $obj['ImageUrl'], _UPLOAD_IMG_ABSPATH_ . '/tin-tuc1/' . $obj['ImageUrl'] . '.jpg')) { $db->bindValue(':INTROIMAGE', '/upload/image/tin-tuc1/' . $obj['ImageUrl'] . '.jpg', PARAM_STR); $db->bindValue(':IS_SHOWINTROIMAGE', 1, PARAM_INT); } else { $db->bindValue(':INTROIMAGE', '', PARAM_STR); $db->bindValue(':IS_SHOWINTROIMAGE', 0, PARAM_INT); } } else { $db->bindValue(':INTROIMAGE', '', PARAM_STR); $db->bindValue(':IS_SHOWINTROIMAGE', 0, PARAM_INT); } $db->bindValue(':INTRO', $obj['Description'], PARAM_STR); $db->bindValue(':CONTENT', $content, PARAM_STR); $db->bindValue(':IS_ENABLED', 1, PARAM_INT); $db->bindValue(':IS_TIEUDIEM', 1, PARAM_INT); $db->bindValue(':IS_QUANTAM', 0, PARAM_INT); $db->bindValue(':VIEW', 0, PARAM_INT); $db->bindValue(':ORDERING', 0, PARAM_INT); $db->bindValue(':IS_CATEGORY', 0, PARAM_INT); $db->bindValue(':SOURCE', $obj['Source'], PARAM_STR); //1 = StockBiz $db->bindValue(':FEEDFROM', 1, PARAM_INT); if (isset($values['SectorId'])) { $db->bindValue(':SECTORID', $values['SectorId'], PARAM_INT); } else { $db->bindValue(':SECTORID', '', PARAM_INT); } if (isset($values['IndustryId'])) { $db->bindValue(':INDUSTRYID', $values['IndustryId'], PARAM_INT); } else { $db->bindValue(':INDUSTRYID', '', PARAM_INT); } if (isset($values['Symbol'])) { $db->bindValue(':SYMBOL', $values['Symbol'], PARAM_STR); } else { $db->bindValue(':SYMBOL', '', PARAM_STR); } $db->bindValue(':PARENT_ID', getNewsParentId($obj['GroupID']), PARAM_INT); $obj['HasAttachedFile'] = (bool) $obj['HasAttachedFile']; $hasAttachedFile = 0; if ($obj['HasAttachedFile'] && !empty($obj['AttachedFileName'])) { if (file_exists(_UPLOAD_FILE_ABSPATH_ . '/tin-tuc1/' . $obj['AttachedFileName']) || copy('http://stockbiz.vn/Handlers/DownloadAttachedFile.ashx?NewsID=' . $obj['NewsID'], _UPLOAD_FILE_ABSPATH_ . '/tin-tuc1/' . $obj['AttachedFileName'])) { $hasAttachedFile = 1; } } $db->bindValue(':HASATTACH', $hasAttachedFile, PARAM_INT); $db->bindValue(':ATTACHFILE', $obj['AttachedFileName'], PARAM_STR); $db->bindValue(':FILEEXT', $obj['AttachedFileExtension'], PARAM_STR); $db->execute(); } } }
function feedBalanceSheetsByYear($symbol) { global $_configs, $year; $url = 'http://datafeed.stockbiz.vn/FinanceService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => $symbol, 'year' => $year, 'count' => 1); if ($objs = _feed_stockbiz('GetLastestBalanceSheetsByYear', $url, $params)) { if (!empty($objs['GetLastestBalanceSheetsByYearResult'])) { $db = _db('stockbiz'); $db->query('DELETE FROM _prefix_financialreport WHERE Symbol="' . $symbol . '" AND Quarter=0 AND type=0'); if (!isset($objs['GetLastestBalanceSheetsByYearResult']['FinancialReport'][0])) { $obj = $objs['GetLastestBalanceSheetsByYearResult']['FinancialReport']; $obj['type'] = 0; $sql = buildInsertSQL('_prefix_financialreport', $obj); $db->query($sql); } else { $objs = $objs['GetLastestBalanceSheetsByYearResult']['FinancialReport']; for ($i = 0; $i < count($objs); $i++) { $objs[$i]['type'] = 0; $sql = buildInsertSQL('_prefix_financialreport', $objs[$i]); $db->query($sql); } } } } }
function feedNewsBySymbol($symbol, $startDate, $endDate) { global $_configs; $url = 'http://datafeed.stockbiz.vn/NewsService.asmx?WSDL'; $params = array('userName' => $_configs['stockbiz_user'], 'password' => $_configs['stockbiz_pass'], 'symbol' => $symbol, 'startDate' => $startDate, 'endDate' => $endDate); if ($objs = _feed_stockbiz('GetCompanyNews', $url, $params)) { if (!empty($objs['GetCompanyNewsResult'])) { if (!isset($objs['GetCompanyNewsResult']['News'][0])) { insertIntoNews($objs['GetCompanyNewsResult']['News'], array('Symbol' => $symbol)); } else { $objs = $objs['GetCompanyNewsResult']['News']; for ($i = 0; $i < count($objs); $i++) { insertIntoNews($objs[$i], array('Symbol' => $symbol)); } } } } }