From abc5b592843b5482ddbeb576ee7fba46f2fc5e39 Mon Sep 17 00:00:00 2001 From: wumu <mayi@mayi.com> Date: 星期四, 11 九月 2025 23:14:11 +0800 Subject: [PATCH] 250911 --- analysisbyrediscache.cpp | 636 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 631 insertions(+), 5 deletions(-) diff --git a/analysisbyrediscache.cpp b/analysisbyrediscache.cpp index 7d41b52..88841fd 100644 --- a/analysisbyrediscache.cpp +++ b/analysisbyrediscache.cpp @@ -3,6 +3,11 @@ #include <QDateTime> #include <QDebug> #include <QElapsedTimer> +#include <QFile> +#include <QJsonArray> +#include <QJsonDocument> +#include <QJsonObject> +#include <QNetworkReply> AnalysisByRedisCache::AnalysisByRedisCache(QWidget *parent) : QMainWindow(parent), @@ -10,7 +15,8 @@ { ui->setupUi(this); - ui->dateEdit->setDate(QDate::currentDate().addMonths(-1)); + ui->dateEdit->setDate(QDate::currentDate().addMonths(-1)); // 鍒濆鍖栧紑濮嬫煡璇㈡椂闂� + ui->dateEdit_end->setDate(QDate::currentDate()); // 鍒濆鍖栫粨鏉熸椂闂� if(m_dbCache.initMySQL("127.0.0.1",3306,"root","root","stock_plan")){ qDebug()<<"mysql conn ok"; @@ -26,6 +32,21 @@ m_model = new QStandardItemModel(this); ui->tableView->setModel(m_model); + + m_modelResult = new QStandardItemModel(this); + ui->tableView_2->setModel(m_modelResult); + + QStringList labels; + labels<<"鑲$エ鍚嶅瓧"<<"甯傚��"<<"鏀剁洏浠�"<<"娑ㄨ穼骞�"<<"鎺� 鍚�"<<"浜ゆ槗鏃堕棿"<<"鎺掑悕鍙樺寲"<<"浜ゆ槗棰�"<<"搴曢儴鍙嶈浆鏃堕棿"<<"涓�闃崇┛鍥涚嚎鏃堕棿"; + m_model->setHorizontalHeaderLabels(labels); + m_modelResult->setHorizontalHeaderLabels(labels); + + //ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + //ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui->tableView->resizeColumnToContents(0); + ui->tableView->resizeColumnToContents(4); + // 鍒濆鍖栫埇铏浉鍏崇殑Http + loadHttpInit(QUrl("https://xueqiu.com/S/SZ002466")); } AnalysisByRedisCache::~AnalysisByRedisCache() @@ -35,9 +56,11 @@ void AnalysisByRedisCache::on_pushButton_loadDataSQLRedis_clicked() { + ui->label_load->setText("缂撳瓨鍔犺浇涓�..."); QString begin_date = ui->dateEdit->text(); + QString end_date = ui->dateEdit_end->text(); QString limit_str = ui->comboBox->currentText(); - QString sql = QString("select * from stock_day_info where time_trade > '%1' limit %2;").arg(begin_date).arg(limit_str); + QString sql = QString("select * from stock_day_info where time_trade > '%1' and time_trade <= '%3' limit %2;").arg(begin_date).arg(limit_str).arg(end_date); qDebug()<<"sql:"<<sql; QElapsedTimer timer; timer.start(); @@ -50,8 +73,507 @@ // 绗簩娆℃煡璇㈠簲璇ヤ粠缂撳瓨鑾峰彇 timer.restart(); result = m_dbCache.query(sql); - qDebug() << "Cached query executed in" << timer.elapsed() << "ms"; + qint64 resTime = timer.elapsed(); + qDebug() << "Cached query executed in" << resTime << "ms"; m_result = result; + ui->label_load->setText(QString("缂撳瓨鍔犺浇%2鏉�,鑰楁椂%1ms").arg(QString::number(resTime)).arg(QString::number(result.size()))); + +} + +// 婊戝姩绐楀彛璁$畻鎺掑悕鍙樺寲 +void AnalysisByRedisCache::calcWindowRank(int start) +{ + + // 婊戝姩绐楀彛鎺掑悕锛�6涓2+鐨勫墠100 + QVector<int> ranks; + for(int i=start;i<m_model->rowCount();++i){ + ranks.append(m_model->item(i,4)->text().toInt()); + if(i >= 6+start){ + // 鍏堢粺璁℃帓鍚嶈鏁� + int cntBig=0, cntSmall=0; + for(int j=0;j<ranks.size();++j){ + if(ranks.at(j) > 100){ + cntBig++; + }else{ + cntSmall++; + } + } + // 缁熻瀵规瘮 + if(cntSmall == 2 && ranks.back() <= 100){ + // 灏嗗綋鍓�6涓厓绱犲畾涓虹鍚堢殑绐楀彛锛岃儗鏅壊璁剧疆涓虹传鑹� + for(int k=0;k<6;++k){ + m_model->item(i-k,4)->setData(QColor("red"),Qt::BackgroundColorRole); + } + } + + // 娓呴櫎绐楀彛绗竴涓厓绱� + ranks.pop_front(); + } + + } + +} + +void AnalysisByRedisCache::loadHttpInit(QUrl url) +{ + // 澶勭悊鏁版嵁鐖彇鐨勬搷浣� + // 妯℃嫙娴忚鍣ㄧ殑鍙傛暟 + QString userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"; + m_cookie = "__utma=1.731742638.1647403301.1699341909.1700229030.32; device_id=196eef62baf016c7d95a22752d9bdbab; smidV2=20240414233939e95389ecf7ecd2f4d08524ce770aacd500753aa68e9640320; s=c611de27gr; cookiesu=651726298794778; xq_a_token=220b0abef0fac476d076c9f7a3938b7edac35f48; xqat=220b0abef0fac476d076c9f7a3938b7edac35f48; xq_r_token=1d46f0ed628506486164e5055a4993f9b54b2f4c; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTcyOTIxMjc4NCwiY3RtIjoxNzI3NDkwOTU3MjA0LCJjaWQiOiJkOWQwbjRBWnVwIn0.C_GmKEhTaaioDMLWkgZyMXDl4duYEVmsdJHsTi7gbcNz0Tohc-uxHsaw0yBT5k-qmbrJ_RaLMCSxy06v14-R3dwL-MsiKRHxHa5qvQZN4BjEgvPRkqqvPgE_fkPLte8qQOEgd5iVkhr-4mjip0-9WCeXYiH7DygxFOBXGlgoPtpPzAtOTm5TWJmXh0ipDsIZxfNOl8jipXYaIdkv_kqLul5gqiBi5qqnwONDa24Zx-Kvpm8ySWiPFBLzZBqTuRBs4oKAMpSdOiYGLVL7dcSDDZyWqAexmrN4f19hkmd6gBHL4dCczRMDGYc1e98sQtlbZ5lgeEuuM24jjcuwCxsxXQ; u=651726298794778; Hm_lvt_1db88642e346389874251b5a1eded6e3=1727099939,1727251802,1727488707,1727491020; HMACCOUNT=1628106D67895387; acw_tc=2760828017275244258732552e9880f861be6db0c40facbdd5f223490decc2; acw_sc__v2=66f7ee8290dc3f63112948801ef331b8c97ccb35; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1727524485; .thumbcache_f24b8bbe5a5934237bbc0eda20c1b6e7=t00N841S/BEpxTGOoJrbm0blWik12om0ew/whcq/V2DNtyEA8um7J+yzeGOli+6iP/TrvrH0YKH2kHlsmDb5EQ%3D%3D; ssxmod_itna=YqAOBKYve+x0ODfxBcDB4DKM7RtAA4454DkDIEC+GAqGNK3DZDiqAPGhDC8RzeL4Ko7+e2aeQvSeopd5pYDk0Ge5TB0PIjaIDB3DEx06TCCQxiiSDCeDIDWeDiDG4Gm4qGtDpxG=DjDytZ9TtDm4GWGqDmDGYBWqDgDYQDGwIXD7QDIqtW07tQDDNQKpAKDiYeHlL5uMRMtOrK7DtDjdTD/3+kZCbCcPwVFeFO=nPcDB6wxBjZRq00Un+g4mNqLYf4IDAxQuYKtgheYYoAfDhTKhhLSGx4tGY4+GDKSiMS2DDAIvdKeD; ssxmod_itna2=YqAOBKYve+x0ODfxBcDB4DKM7RtAA4454DkDIEC+GDA69mqD/YttDFhxMltFKApT7bCMH+bytp7GQQyCbBWukeAF3+jxeN2wLjbQAFcdwbeNeoohjQ4qtEnLg4TKyX2LqVL=CGaV=GqZZqbDby8DFnFbgWiZEH8zoBzBCbzqWeqwoPq7/TpL=gIRY8sVhEpnWWHQU8sz+S8=+8oRerHq0wtQnSzyQDK7Dmvr3a+VY7fezRmxKF=bDeqexYUbuuzw2eR3In9evW6tzHbQY6vp=AIOUc9l6vc0vOl9plD6D07zGGQ41uxpii2Y5s7KvYQDWGYExD7=DYKKeD=="; + QByteArray cookieByte = m_cookie.toUtf8(); + QList<QNetworkCookie> list; + list.push_back(QNetworkCookie(cookieByte)); + + QVariant var; + var.setValue(list); + // 璁剧疆瑕佽闂殑缃戝潃 + //m_request.setUrl(QUrl("https://xueqiu.com/S/SZ002466")); + m_request.setUrl(url); + // 璁剧疆璇锋眰澶达紝鐢ㄦ埛浠g悊锛岀敤鏉ユā鎷熸祻瑙堝櫒 + m_request.setHeader(QNetworkRequest::UserAgentHeader,userAgent); + // 璁剧疆cookie + //m_request.setHeader(QNetworkRequest::CookieHeader, var); + + // 鏌ョ湅manager閮芥敮鎸佸摢浜涘崗璁� + qDebug()<<"缂撳瓨鍒嗘瀽---鏀寔鐨勫崗璁�:"<<m_manager.supportedSchemes(); + // 鍏宠仈淇″彿妲斤紝褰撹姹傜鐞嗗璞″畬鍏ㄦ墦寮�缃戦〉涔嬪悗锛屼細灏嗘暟鎹粰妲藉嚱鏁板鐞� + connect(&m_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(showAplyData(QNetworkReply*))); + +} + +void AnalysisByRedisCache::showAplyData(QNetworkReply *reply) +{ + qDebug()<<"缂撳瓨鍒嗘瀽--鏀跺埌鍝嶅簲"; + // 灏嗗搷搴旂殑鏁版嵁锛屼竴鎶婅鍙栧畬锛屾斁鍒板瓧鑺傛暟缁勯噷闈㈡潵澶勭悊 + QByteArray buffer = reply->readAll(); + + // 灏嗘暟鎹啓鍒版枃浠朵腑锛屾柟渚胯瀵熸暟鎹唴瀹� +// QFile file("data.txt"); +// file.open(QIODevice::ReadWrite | QIODevice::Text); +// QTextStream out(&file); +// out << buffer << endl; +// file.close(); + + // 涓嬮潰浣跨敤JSON杩涜鏁版嵁澶勭悊 + if(reply->url() == QUrl("https://xueqiu.com/")){ + qDebug()<<"鍙戠幇棣栭〉url"; + qDebug()<<buffer; + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/chart/kline.json") != -1){ + qDebug()<<"鏌ョ湅涓偂鎯呭喌:"; + getStockOne(buffer); + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/quote/list.json?page=1&size=100&order=desc&order_by=percent&market=CN&ind_code") != -1){ + qDebug()<<"鏍规嵁琛屼笟鑾峰彇鑲$エ淇℃伅"<<reply->url(); + QString industryCode = reply->url().toString().split("=").back(); + qDebug()<<"琛屼笟淇℃伅:"<<industryCode; + //getStockByIndustry(buffer,industryCode); + + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/quote/list.json") != -1){ + qDebug()<<"鑾峰彇鎵�鏈夋勃娣辫偂绁� 鍙互骞叉椿浜�"; + //getStockAllCode(buffer); + }else if(reply->url().toString().indexOf("https://stock.xueqiu.com/v5/stock/screener/industries.json") != -1){ + qDebug()<<"鑾峰彇琛屼笟淇℃伅"; + //getIndustryInfo(buffer); + } + + reply->deleteLater(); +} + +void AnalysisByRedisCache::buttomToUpPolicySlot(QString symbol) +{ + /* + 澶嶇洏涔嬪墠鐨勬湀绾跨獊鐮存儏鍐碉紝鏀鹃噺涓婃定锛�5鍊嶅乏鍙筹紝骞朵笖鍦�60鏃ュ潎绾夸笂鍐查珮锛屼笉鍥炶惤锛屽ぇ姒傜巼鍙互缁х画鍐� + 鍏虫敞濂藉啿鐨勫舰鎬侊紝鍔犱笂寰堝ソ鐨勬崲鎵嬬巼80%+锛岀敋鑷�100%+锛岃鏄庡厖鍒嗘崲鎵嬩簡锛岀獊鐮翠細鏇村ソ锛屾湁灏变細璧氬鍊� + 骞朵笖澶氭棩鏌ョ湅锛屾瘮渚嬪�间竴鐩村湪鏀惧ぇ锛岃鏄庡緢闈犺氨锛屽氨鏄湁涓�涓暟鍊兼瘮渚嬬殑鐖崌杩囩▼锛岄偅灏卞彲浠ラ噸浠撲拱鍏ョ瓑鏀剁泭浜嗭紝鍙互缁樺埗涓�鏉℃洸绾挎潵瑙傚療鎯呭喌 + */ + + qDebug()<<"鎵ц搴曢儴鍙嶈浆绛栫暐"; + //emit sendInfoMess("<font size=12 color=pink>鎵ц搴曢儴鍙嶈浆绛栫暐 </font>"); + int curRow = ui->tableView->currentIndex().row(); +// QString symbol = m_model->item(curRow,1)->text(); + + //QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + int numsCnt = 300; + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); + qDebug()<<urlStr; + //qDebug()<<"褰撳墠鑲$エ:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 4; // 绗簲涓彍鍗曢」 + m_request.setUrl(QUrl(urlStr)); + m_manager.get(m_request); +} + +void AnalysisByRedisCache::oneUpCrossFourSlot(QString symbol) +{ + /* 涓�闃崇┛鍥涚嚎 + K绾垮嚭鐜颁簡澶ч槼绾垮苟涓旇疮绌�4鏉″潎绾匡紝璇存槑鍦ㄧ寷娑ㄤ簡锛屽苟涓旈噺鑳戒篃璺熶笂鐨勮瘽锛屽氨璇存槑寮哄姴 + + 鏃銆佸懆K銆佹湀K灏卞緢鏄庢樉銆� + 澶ц秼鍔夸互鍛ㄣ�佹湀涓轰富锛岄�傚悎涓暱绾垮鐞� + --------------------------- + 涔熼潪甯搁�傚悎瓒呯煭绾跨殑澶勭悊锛�30鍒嗐��60鍒嗐��120鍒嗙殑澶х┛闃崇嚎涔熷緢鏄庢樉 + --------------------------- + 灏辨槸寮�鐩樹环鍜屾敹鐩樹环鍖呭惈浜嗕竴涓尯闂达紝杩欎釜鍖洪棿鍐呴兘鎶奙a5 Ma10 Ma20 Ma30缁欏寘浣忎簡锛岃鏄庤Е鍙戜簡涓�闃崇┛鍥涚嚎 + */ + qDebug()<<"涓�闃崇┛鍥涚嚎绛栫暐"; + //emit sendInfoMess("<font size=12 color=pink>鎵ц涓�闃崇┛鍥涚嚎绛栫暐 </font>"); + int curRow = ui->tableView->currentIndex().row(); +// QString symbol = m_model->item(curRow,1)->text(); + + //QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); + qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 鍙栧綋鍓嶆椂闂存埑 + int numsCnt = 200; + QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd,ma,boll,market_capital").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); + qDebug()<<urlStr; + //qDebug()<<"褰撳墠鑲$エ:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); + // 涓嬩竴姝ュ氨鏄牴鎹畊rl璇锋眰鍒扮殑鏁版嵁锛岃繘琛屽垎鏋� + m_menuIndex = 6; // 绗竷涓彍鍗曢」 + m_request.setUrl(QUrl(urlStr)); + m_manager.get(m_request); + +} + +void AnalysisByRedisCache::updateAllFindTimeSlot() +{ + qDebug()<<"瑙﹀彂浜嗘洿鏂扮瓥鐣ユ椂闂存搷浣�"; + for(auto kv:m_codes.keys()){ + qDebug()<<"code:"<<kv<<m_codes[kv]; + //buttomToUpPolicySlot(kv); + oneUpCrossFourSlot(kv); + } +} + +// 鍗曚釜鑲$エ鐨� JSON鏍煎紡澶勭悊 +void AnalysisByRedisCache::getStockOne(QByteArray &buffer) +{ + QJsonDocument jd = QJsonDocument::fromJson(buffer); + if(jd.isObject()){ + QJsonObject jObject = jd.object(); + QJsonArray jArr = jObject.value("data").toObject().value("item").toArray(); // 閫氳繃閿�煎鍙栧�� + int cnt = jArr.count(); + qDebug()<<"鏁扮粍size:"<<cnt; + QString symbol = jObject.value("data").toObject().value("symbol").toString(); + QString code = symbol; // 鑲$エ浠e彿 +// QLineSeries *series = new QLineSeries; // QLineSeries 鎶樼嚎鐨勭被锛孮SplineSeries 涓哄渾婊戞洸绾跨被 +// series->setName(symbol); // 璁剧疆鎶樼嚎鍚嶅瓧 +// //series->setColor(QColor(255,0,0)); // 璁剧疆棰滆壊 r,g,b 绾㈢豢钃濅笁鍘熻壊锛岄殢鎰忕粍鍚� +// QSplineSeries *sp = new QSplineSeries; +// sp->setName(symbol); +// QSplineSeries *spVolume = new QSplineSeries; +// spVolume->setName(symbol.append("--volume")); +// QSplineSeries *spAmount = new QSplineSeries; +// spVolume->setName(symbol.append("--amount")); + + int ma10_20_flag = 0; // 鏍囪MA閲戝弶銆佹鍙夌殑鎯呭喌 0:鍒濆鍊硷紝1锛氶噾鍙夛紝-1锛氭鍙� + long long oldVolume = 0; // MACD: 鑰佺殑鎴愪氦閲� + int macd_buy = 0; // 涔板叆鏍囧織 + double buy_price = 0; // 涔板叆浠锋牸 + double rate_all = 0; // 鏀剁泭鐧惧垎姣� + for(int i=0;i<cnt;++i){ + qint64 timestamp = jArr.at(i).toArray().at(0).toVariant().toLongLong(); + double close = jArr.at(i).toArray().at(5).toVariant().toDouble(); + long long volume = jArr.at(i).toArray().at(1).toVariant().toLongLong()/100; + + long long amount = jArr.at(i).toArray().at(9).toVariant().toLongLong()/100000000; + QString curDateTime = QDateTime::fromMSecsSinceEpoch(timestamp).toString("yyyy-MM-dd"); + //qDebug()<<curDateTime<<close<<volume<<amount; +// series->append(timestamp,close); // 鎶樼嚎鏁版嵁娣诲姞 +// sp->append(timestamp,close); // 鏇茬嚎鏁版嵁娣诲姞 +// spVolume->append(timestamp,volume); +// spAmount->append(timestamp,amount); + if(m_menuIndex == 2){ + // MA ma10浜a20 閲戝弶锛宮a10浜a60 姝诲弶 + double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); + double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); + //qDebug()<<"MA5-10-20-30"<<ma5<<ma10<<ma20<<ma30; + if(i>0){ + double ma5_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); + double ma10_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); + double ma20_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); + double ma30_old = jArr.at(i-1).toArray().at(15).toVariant().toDouble(); + +// if(ma5_old > ma20_old && ma5 <= ma20){ +// // 姝诲弶 +// qDebug()<<"MA5-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; +// }else if(ma5_old < ma20_old && ma5 >= ma20){ +// // 閲戝弶 +// qDebug()<<"MA5-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// } + + if(ma10_old > ma20_old && ma10 <= ma20){ + // 姝诲弶 + qDebug()<<"MA10-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; + if(buy_price == 0) buy_price = close; + double tmp_rate = (close-buy_price)/buy_price; + rate_all += tmp_rate; + +// QString info = QString("<font size=8 color=green> %3 %6 MA10-20姝诲弶:%1 浠锋牸:%2 鐩堝埄姣�:%4 鎬荤泩鍒�:%5</font>").arg(curDateTime).arg(close).arg(code) +// .arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)).arg(m_codeNames[code]); +// emit sendInfoMess(info); + //buy_price = close; // 姝诲弶涔板叆鐨勬儏鍐� + }else if(ma10_old < ma20_old && ma10 >= ma20){ + // 閲戝弶 + buy_price = close; // 閲戝弶涔板叆鐨勬儏鍐� + + qDebug()<<"MA10-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// if(buy_price == 0) buy_price = close; +// double tmp_rate = (close-buy_price)/buy_price; +// rate_all += tmp_rate; +// QString info = QString("<font size=8 color=red> %3 %4 MA10-20閲戝弶:%1 浠锋牸:%2 </font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]); + //.arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)); + //emit sendInfoMess(info); + + } + } + }else if(m_menuIndex == 3){ + // MACD绛栫暐 缁撳悎鎴愪氦閲忔潵鍒ゆ柇浼氭洿濂�:涔板叆鐐规垚浜ら噺缁х画鏀惧ぇ鍒欐寔鏈夛紝缂╁皬鍒欑鍦� + double dea = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double dif = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double macd = jArr.at(i).toArray().at(14).toVariant().toDouble(); + + if(macd_buy == 1 && oldVolume > volume){ + QString info = QString("<font size=8 color=green> %4 MACD 鎴愪氦閲忓垵娆¤椤� 绂诲満1:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + //emit sendInfoMess(info); + macd_buy = 0; + oldVolume = 0; + + } + if(i > 0){ + double dea_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); + double dif_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); + double macd_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); + + if(dif_old > dea_old && dif <= dea){ + // 姝诲弶 + qDebug()<<"MACD姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd ; + QString info=QString("<font size=8 color=green> %4 MACD姝诲弶:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + //emit sendInfoMess(info); + }else if(dif_old < dea_old && dif >= dea){ + // 閲戝弶 + qDebug()<<"MACD閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd <<"寤鸿璁板綍褰撳墠閲戝弶MACD鐨勫�硷紝鑻ュ悗闈㈡湁浣庝簬姝ゅ�硷紝鍏虫敞绂诲満鎻愮ず"; + QString info=QString("<font size=9 color=red> %4 MACD閲戝弶:%1 浠锋牸:%2 MACD=%3 寤鸿璁板綍褰撳墠閲戝弶MACD鐨勫�硷紝鑻ュ悗闈㈡湁浣庝簬姝ゅ�硷紝鍏虫敞绂诲満鎻愮ず </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + //emit sendInfoMess(info); + + macd_buy = 1; + oldVolume = volume; + } + } + }else if(m_menuIndex == 4 || m_menuIndex == 6){ + // 搴曢儴鍙嶈浆绛栫暐,鎻愬墠鐨勬劅鐭ョ殑鏃堕棿浼氭洿鏃╋紝寰楀埌鏇村ソ鐨勯鍒よ秼鍔� + // qDebug()<<"搴曢儴鍙嶈浆绛栫暐"; + if(i > 0){ + { + double volume_cur = jArr.at(i).toArray().at(1).toDouble(); + double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); + double volume_rate = volume_cur / volume_old; + if(volume_rate > 2){ + qDebug()<<"搴曢儴鍙嶈浆绛栫暐:閲忚兘姣�"<<volume_rate<<code <<curDateTime<<"浠锋牸:" <<close; + QString info = QString("<font size=8 color=red> %4 搴曢儴鍙嶈浆绛栫暐:閲忚兘 鏃堕棿:%1 浠锋牸:%2 閲忚兘姣斿��=%3 </font>").arg(curDateTime).arg(close).arg(volume_rate).arg(code); + //emit sendInfoMess(info); + + //淇敼鍙戠幇鐨勬渶鏂版椂闂� + updateFindTime(m_codes[code],curDateTime,7); // 涓嬫爣涓�7 + } + } + + + { + // 涓�闃崇┛鍥涚嚎 + + double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); + double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); + + double open = jArr.at(i).toArray().at(2).toVariant().toDouble(); + long long market_cap = jArr.at(i).toArray().at(22).toVariant().toLongLong(); + + double volume_rate = 0; + if(i > 0){ // 璁$畻閲忚兘姣� + double volume_cur = jArr.at(i).toArray().at(1).toDouble(); + double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); + volume_rate = volume_cur / volume_old; + } + + if(ma5 >= open && ma10 >= open && ma20 >= open && ma30 >= open + && ma5 <= close && ma10 <= close && ma20 <= close && ma30 <= close){ + qDebug()<<"涓�闃崇┛鍥涚嚎:"<< code <<curDateTime<<" 浠锋牸:"<<close << "閲忚兘姣�:"<<volume_rate; + if(volume_rate > 4){ + // QString info = QString("<font size=8 color=blue> %3 %4 涓�闃崇┛鍥涚嚎:%1 浠锋牸:%2 閲忚兘姣�:%5 鍛ㄦ湡:%6 甯傚��:%7浜�</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) + // .arg(m_dateType).arg(market_cap/100000000.0); + //emit sendInfoMess(info); + }else{ + // QString info = QString("<font size=8 color=red> %3 %4 涓�闃崇┛鍥涚嚎:%1 浠锋牸:%2 閲忚兘姣�:%5 鍛ㄦ湡:%6 甯傚��:%7浜�</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) + // .arg(m_dateType).arg(market_cap/100000000.0); + //emit sendInfoMess(info); + } + + //淇敼鍙戠幇鐨勬渶鏂版椂闂� + updateFindTime(m_codes[code],curDateTime,8); // 涓嬫爣涓�8 + + } + } + } + + }else if(m_menuIndex == 5){ + // 澶氱瓥鐣ュ叡鎸�:閲忚兘銆丮ACD銆丮A銆丅OLL + + int cnt = 0; + // 閲忚兘 + if(i > 0){ + double volume_cur = jArr.at(i).toArray().at(1).toDouble(); + double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); + double volume_rate = volume_cur / volume_old; + if(volume_rate > 2){ + cnt++; + qDebug()<<"澶氱瓥鐣ュ叡鎸�:閲忚兘姣�"<<volume_rate<<code <<curDateTime<<"浠锋牸:" <<close; + QString info = QString("<font size=8 color=red> %4 澶氱瓥鐣ュ叡鎸�:閲忚兘绛栫暐 鏃堕棿:%1 浠锋牸:%2 閲忚兘姣斿��=%3 鍏辨尟鍊�:%5</font>").arg(curDateTime).arg(close).arg(volume_rate).arg(code).arg(cnt); + //emit sendInfoMess(info); + } + } + + // MACD绛栫暐 缁撳悎鎴愪氦閲忔潵鍒ゆ柇浼氭洿濂�:涔板叆鐐规垚浜ら噺缁х画鏀惧ぇ鍒欐寔鏈夛紝缂╁皬鍒欑鍦� + double dea = jArr.at(i).toArray().at(16).toVariant().toDouble(); + double dif = jArr.at(i).toArray().at(17).toVariant().toDouble(); + double macd = jArr.at(i).toArray().at(18).toVariant().toDouble(); + + if(macd_buy == 1 && oldVolume > volume){ + QString info = QString("<font size=8 color=green> %4 MACD 鎴愪氦閲忓垵娆¤椤� 绂诲満1:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + //emit sendInfoMess(info); + macd_buy = 0; + oldVolume = 0; + + } + if(i > 0){ + double dea_old = jArr.at(i-1).toArray().at(16).toVariant().toDouble(); + double dif_old = jArr.at(i-1).toArray().at(17).toVariant().toDouble(); + double macd_old = jArr.at(i-1).toArray().at(18).toVariant().toDouble(); + + if(dif_old > dea_old && dif <= dea){ + // 姝诲弶 + qDebug()<<"MACD姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd ; + QString info=QString("<font size=8 color=green> %4 MACD姝诲弶:%1 浠锋牸:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); + //emit sendInfoMess(info); + }else if(dif_old < dea_old && dif >= dea){ + // 閲戝弶 + cnt++; + qDebug()<<"MACD閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close <<"MACD="<<macd <<"寤鸿璁板綍褰撳墠閲戝弶MACD鐨勫�硷紝鑻ュ悗闈㈡湁浣庝簬姝ゅ�硷紝鍏虫敞绂诲満鎻愮ず"; + QString info=QString("<font size=9 color=red> %4 MACD閲戝弶:%1 浠锋牸:%2 MACD=%3 鍏辨尟鍊�:%5 </font>").arg(curDateTime).arg(close).arg(macd).arg(code).arg(cnt); + //emit sendInfoMess(info); + + macd_buy = 1; + oldVolume = volume; + } + } + + + // MA ma10浜a20 閲戝弶锛宮a10浜a60 姝诲弶 + double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); + double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); + //qDebug()<<"MA5-10-20-30"<<ma5<<ma10<<ma20<<ma30; + if(i>0){ + double ma5_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); + double ma10_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); + double ma20_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); + double ma30_old = jArr.at(i-1).toArray().at(15).toVariant().toDouble(); + +// if(ma5_old > ma20_old && ma5 <= ma20){ +// // 姝诲弶 +// qDebug()<<"MA5-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; +// }else if(ma5_old < ma20_old && ma5 >= ma20){ +// // 閲戝弶 +// qDebug()<<"MA5-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// } + + if(ma10_old > ma20_old && ma10 <= ma20){ + // 姝诲弶 + qDebug()<<"MA10-20姝诲弶:"<<curDateTime<<" 浠锋牸:"<<close; + if(buy_price == 0) buy_price = close; + double tmp_rate = (close-buy_price)/buy_price; + rate_all += tmp_rate; + +// QString info = QString("<font size=8 color=green> %3 %6 MA10-20姝诲弶:%1 浠锋牸:%2 鐩堝埄姣�:%4 鎬荤泩鍒�:%5</font>").arg(curDateTime).arg(close).arg(code) +// .arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)).arg(m_codeNames[code]); + //emit sendInfoMess(info); + //buy_price = close; // 姝诲弶涔板叆鐨勬儏鍐� + }else if(ma10_old < ma20_old && ma10 >= ma20){ + // 閲戝弶 + cnt++; + buy_price = close; // 閲戝弶涔板叆鐨勬儏鍐� + + qDebug()<<"MA10-20閲戝弶:"<<curDateTime<<" 浠锋牸:"<<close; +// QString info = QString("<font size=8 color=red> %3 %4 MA10-20閲戝弶:%1 浠锋牸:%2 鍏辨尟鍊�:%5 </font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(cnt); + //.arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)); + //emit sendInfoMess(info); + + } + } + + }else if(m_menuIndex == 6){ + // 涓�闃崇┛鍥涚嚎 + + double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); + double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); + double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); + double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); + + double open = jArr.at(i).toArray().at(2).toVariant().toDouble(); + long long market_cap = jArr.at(i).toArray().at(22).toVariant().toLongLong(); + + double volume_rate = 0; + if(i > 0){ // 璁$畻閲忚兘姣� + double volume_cur = jArr.at(i).toArray().at(1).toDouble(); + double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); + volume_rate = volume_cur / volume_old; + } + + if(ma5 >= open && ma10 >= open && ma20 >= open && ma30 >= open + && ma5 <= close && ma10 <= close && ma20 <= close && ma30 <= close){ + qDebug()<<"涓�闃崇┛鍥涚嚎:"<< code <<curDateTime<<" 浠锋牸:"<<close << "閲忚兘姣�:"<<volume_rate; + if(volume_rate > 4){ +// QString info = QString("<font size=8 color=blue> %3 %4 涓�闃崇┛鍥涚嚎:%1 浠锋牸:%2 閲忚兘姣�:%5 鍛ㄦ湡:%6 甯傚��:%7浜�</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) +// .arg(m_dateType).arg(market_cap/100000000.0); + //emit sendInfoMess(info); + }else{ +// QString info = QString("<font size=8 color=red> %3 %4 涓�闃崇┛鍥涚嚎:%1 浠锋牸:%2 閲忚兘姣�:%5 鍛ㄦ湡:%6 甯傚��:%7浜�</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) +// .arg(m_dateType).arg(market_cap/100000000.0); + //emit sendInfoMess(info); + } + + } + } + + + } + if(m_menuIndex == 0){ + // 绛栫暐鍒嗘瀽 鍙兘閫変竴绉嶇嚎褰㈡暟鎹� + //emit sendChartData(series); // 鍙戦�佹姌绾挎暟鎹� +// emit sendChartData(sp); // 鍙戦�佹洸绾挎暟鎹� 鏀剁洏浠� +// emit sendChartData(spVolume); // 鍙戦�佷氦鏄撻噺鏇茬嚎 +// emit sendChartData(spAmount); // 浜ゆ槗棰濇洸绾� + }else if(m_menuIndex == 1){ + // 鏈�鏂颁环鏍� + }else if(m_menuIndex == 2){ + // MA绛栫暐 + }else if(m_menuIndex == 3){ + // MACD绛栫暐 + } + } +} + +void AnalysisByRedisCache::updateFindTime(QString name, QString trade_time, int index) +{ + for(int i=0;i<m_modelResult->rowCount();++i){ + if(m_modelResult->item(i,0)->text() == name){ // 鍖归厤鍒板悕瀛� + m_modelResult->setItem(i,index,new QStandardItem(trade_time)); // 鏇存柊鏃堕棿 + } + } } void AnalysisByRedisCache::searchAndAnalysisData(QString name) @@ -61,7 +583,12 @@ qDebug()<<"m_result size:"<<m_result.size()<<name; int rank_val = 0; + double amount_old = 0; int cnt = 0; + int bigFlag = false; + int bigRankUp = false; // 绐佺劧浠庡緢浣庣殑鎺掑悕涓婂崌鍒板ぇ鎺掑悕 + bool big_3000 = false; + bool big_2000 = false; for(auto it:m_result){ if(it["name"].toString() == name){ // qDebug()<<it["name"].toString()<<it["close"].toString()<<it["amount_rank"].toString()<<it["time_trade"].toString(); @@ -71,31 +598,122 @@ double market_capital = it["market_capital"].toDouble() / 100000000; items.append(new QStandardItem(QString::number(market_capital))); items.append(new QStandardItem(it["close"].toString())); - items.append(new QStandardItem(it["percent"].toString())); + + QStandardItem *percentItem = new QStandardItem(it["percent"].toString()); + if(percentItem->text().toDouble() > 0){ + percentItem->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞瑁呴グ棰滆壊涓虹孩鑹� + percentItem->setData(QColor("red"),Qt::TextColorRole); // 娣诲姞鏂囨湰棰滆壊涓虹孩鑹� + items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 璁剧疆鑲$エ鍚嶅瓧涓虹孩鑹� + + }else if(percentItem->text().toDouble() < 0){ + percentItem->setData(QColor("green"),Qt::DecorationRole); // 娣诲姞瑁呴グ棰滆壊涓虹孩鑹� + percentItem->setData(QColor("green"),Qt::TextColorRole); // 璁剧疆鑳屾櫙棰滆壊涓虹豢鑹� + items.at(0)->setData(QColor("green"),Qt::TextColorRole); // 璁剧疆鑲$エ鍚嶅瓧涓虹豢鑹� + } + items.append(percentItem); + //items.append(new QStandardItem(it["percent"].toString())); items.append(new QStandardItem(it["amount_rank"].toString())); items.append(new QStandardItem(it["time_trade"].toString())); QString amount_rank = it["amount_rank"].toString(); if(rank_val != 0){ double rank_rate = 1 - (amount_rank.toDouble()/rank_val); //items.append(new QStandardItem(QString::number(rank_rate))); - rank_val = amount_rank.toInt(); + QStandardItem * amount_rank_item = new QStandardItem(QString::number(rank_rate)); if(rank_rate > 0.9){ amount_rank_item->setData(QColor("red"),Qt::BackgroundColorRole); + bigFlag = true; + } + if(rank_rate > 0.7 && rank_val >= 1000 && amount_rank.toInt() < 1000){ + bigRankUp = true; + bigFlag = true; + if(rank_rate > 0.9){ + // 绱壊 + amount_rank_item->setData(QColor(170, 85, 255),Qt::BackgroundColorRole); + }else{ + // 绮夎壊 + amount_rank_item->setData(QColor("pink"),Qt::BackgroundColorRole); + } + + + + if(rank_val >= 3000){ + amount_rank_item->setData(QColor(85,170,255),Qt::BackgroundColorRole); + big_3000 = true; + } + else if(rank_val >= 2000){ + amount_rank_item->setData(QColor(85,255,255),Qt::BackgroundColorRole); + big_2000 = true; + } + + + + } items.append(amount_rank_item); + rank_val = amount_rank.toInt(); // 鍒板悗闈㈠啀璧嬪�� } if(rank_val == 0 && amount_rank.toInt() != 0){ rank_val = amount_rank.toInt(); } + double amount = it["amount"].toDouble(); + QStandardItem *amountItem = new QStandardItem(QString::number(amount/100000000)); + if(amount_old > 0){ + if(amount / amount_old >= 3){ + amountItem->setData(QColor("red"),Qt::BackgroundColorRole); + amountItem->setData(QString::number(amount / amount_old),Qt::ToolTipRole); + } + } + items.append(amountItem); + amount_old = amount; + + m_model->appendRow(items); + if(bigFlag){ + QList<QStandardItem*> items_2; + for(int i=0;i<items.size();++i){ + items_2.append(new QStandardItem(items.at(i)->text())); + if(i==6 && items.at(i)->text().toDouble() > 0.95){ + items_2.back()->setData(QColor("red"),Qt::BackgroundColorRole); + }else if(i==6 && bigRankUp){ + if(items.at(i)->text().toDouble() > 0.9){ + items_2.back()->setData(QColor(170, 85, 255),Qt::BackgroundColorRole); + }else{ + items_2.back()->setData(QColor("pink"),Qt::BackgroundColorRole); + } + + if(big_3000){ + items_2.back()->setData(QColor(85,170,255),Qt::BackgroundColorRole); + } + if(big_2000){ + items_2.back()->setData(QColor(85,255,255),Qt::BackgroundColorRole); + } + + }else if(i==7){ + // 鐪嬩氦鏄撻鍙樺寲 + } + } + m_modelResult->appendRow(items_2); + bigFlag = false; + bigRankUp = false; + big_3000 = false; + big_2000 = false; + + // 淇濆瓨鍚嶅瓧淇℃伅:code-name + m_codes.insert(it["code"].toString(),name); + } } } qDebug()<<"cnt="<<cnt; qDebug() << "Query executed in" << timer.elapsed() << "ms"; + qDebug()<<"婊戝姩绐楀彛鎺掑悕-cnt:"<<m_model->rowCount()<<cnt<<"start:"<<m_model->rowCount() - cnt + 1; + calcWindowRank(m_model->rowCount() - cnt + 1); + + // 鏇存柊鏃堕棿 + } void AnalysisByRedisCache::on_pushButton_analysisByRedis_clicked() { @@ -111,9 +729,17 @@ // 鎵归噺鍒嗘瀽 // 閲嶈妯″瀷鐨勮鏁颁负0锛屾竻绌轰竴涓嬫暟鎹� m_model->setRowCount(0); + m_modelResult->setRowCount(0); int batch_num = ui->comboBox_batchNum->currentText().toInt(); // 鎵归噺鍒嗘瀽涓偂鐨勬暟閲� // 鎷垮嚭涓偂浜ゆ槗棰濇帓鍚嶇殑鍓峃鍚嶏紝杩涜缂撳瓨鍒嗘瀽 emit getStockNamesSignal(batch_num); + qDebug()<<"鎵归噺鍒嗘瀽瀹屾垚"; } + +void AnalysisByRedisCache::on_pushButton_updateStrategyTime_clicked() +{ + // 鏇存柊绛栫暐鐨勬椂闂� + updateAllFindTimeSlot(); +} -- Gitblit v1.8.0