update code
This commit is contained in:
272
include/FTInterface.cpp
Normal file
272
include/FTInterface.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
#include "stdafx.h"
|
||||
#include "FTInterface.h"
|
||||
|
||||
CFTInterface::CFTInterface()
|
||||
{
|
||||
FTAPI::Init(); // <20><>ʼ<EFBFBD><CABC> Futu API <20><><EFBFBD><EFBFBD>
|
||||
|
||||
bConnected = false;
|
||||
m_nPagenumber = 0;
|
||||
|
||||
m_pQotApi = FTAPI::CreateQotApi();
|
||||
m_pQotApi->RegisterQotSpi(this);
|
||||
m_pQotApi->RegisterConnSpi(this);
|
||||
}
|
||||
|
||||
|
||||
CFTInterface::~CFTInterface()
|
||||
{
|
||||
if (m_pQotApi != nullptr)
|
||||
{
|
||||
m_pQotApi->UnregisterQotSpi();
|
||||
m_pQotApi->UnregisterConnSpi();
|
||||
FTAPI::ReleaseQotApi(m_pQotApi);
|
||||
m_pQotApi = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
<09><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>֮<EFBFBD><EFBFBD><F3A3ACB2>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>
|
||||
*/
|
||||
bool CFTInterface::InitConn()
|
||||
{
|
||||
return m_pQotApi->InitConnect("127.0.0.1", 11111, false);
|
||||
}
|
||||
|
||||
void CFTInterface::DisConn()
|
||||
{
|
||||
}
|
||||
|
||||
void CFTInterface::getSecurityStaticInfo(string strCode)
|
||||
{
|
||||
Qot_GetStaticInfo::Request req;
|
||||
Qot_GetStaticInfo::C2S *c2s = req.mutable_c2s();
|
||||
auto secList = c2s->mutable_securitylist();
|
||||
Qot_Common::Security *sec = secList->Add();
|
||||
sec->set_code(strCode);
|
||||
//sec->set_code("00700");
|
||||
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
|
||||
|
||||
m_ReplySerialNo = m_pQotApi->GetStaticInfo(req);
|
||||
}
|
||||
|
||||
void CFTInterface::getIpoListInfo()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
Qot_GetIpoList::Request req;
|
||||
Qot_GetIpoList::C2S *c2s = req.mutable_c2s();
|
||||
c2s->set_market(1);
|
||||
|
||||
m_GetIpoListSerialNo = m_pQotApi->GetIpoList(req);
|
||||
cout << "Request GetIpoList SerialNo: " << m_GetIpoListSerialNo << endl;
|
||||
}
|
||||
|
||||
void CFTInterface::getPlateSetSerial()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
Qot_GetPlateSet::Request req;
|
||||
Qot_GetPlateSet::C2S *c2s = req.mutable_c2s();
|
||||
c2s->set_market(1);
|
||||
c2s->set_platesettype(3);
|
||||
|
||||
m_GetPlateSetSerialNo = m_pQotApi->GetPlateSet(req);
|
||||
cout << "Request GetPlateSet SerialNo: " << m_GetPlateSetSerialNo << endl;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
////////// Futu <20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> /////////////////////////////
|
||||
void CFTInterface::OnInitConnect(FTAPI_Conn * pConn, Futu::i64_t nErrCode, const char * strDesc)
|
||||
{
|
||||
//qDebug() << "connect";
|
||||
if(nErrCode == 0 && string(strDesc) == "Succeed!")
|
||||
bConnected = true;
|
||||
}
|
||||
|
||||
|
||||
void CFTInterface::OnReply_GetStaticInfo(Futu::u32_t nSerialNo, const Qot_GetStaticInfo::Response &stRsp)
|
||||
{
|
||||
if (nSerialNo == m_ReplySerialNo)
|
||||
{
|
||||
cout << "OnReply_GetStaticInfo SerialNo: " << nSerialNo << endl;
|
||||
// print response
|
||||
// ProtoBufToBodyData and UTF8ToLocal refer to tool.h in Samples
|
||||
string resp_str;
|
||||
ProtoBufToBodyData(stRsp, resp_str);
|
||||
emit SecurityStaticInfo(QString(resp_str.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
void CFTInterface::OnReply_GetPlateSet(Futu::u32_t nSerialNo, const Qot_GetPlateSet::Response & stRsp)
|
||||
{
|
||||
//if (nSerialNo == m_GetPlateSetSerialNo)
|
||||
//{
|
||||
// string resp_str;
|
||||
// ProtoBufToBodyData_Ex(stRsp, resp_str);
|
||||
|
||||
// emit PlateSetSerial(QString(resp_str.c_str()));
|
||||
//}
|
||||
if (nSerialNo != m_GetPlateSetSerialNo) return;
|
||||
|
||||
std::string bin_data;
|
||||
ProtoBufToBodyData_Binary(stRsp, bin_data);
|
||||
//FastSerializeProto(stRsp, bin_data);
|
||||
emit PlateSetSerial(QByteArray(bin_data.data(), bin_data.size()));
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ʷ K <20><>
|
||||
void CFTInterface::getRequestHistoryKL()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
Qot_RequestHistoryKL::Request req;
|
||||
Qot_RequestHistoryKL::C2S *c2s = req.mutable_c2s();
|
||||
c2s->set_rehabtype(1);
|
||||
c2s->set_kltype(Qot_Common::KLType::KLType_1Min);
|
||||
Qot_Common::Security *sec = c2s->mutable_security();
|
||||
sec->set_code("00700");
|
||||
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
|
||||
c2s->set_begintime("2021-06-07");
|
||||
c2s->set_endtime("2021-07-01");
|
||||
|
||||
m_RequestHistoryKLSerialNo = m_pQotApi->RequestHistoryKL(req);
|
||||
}
|
||||
void CFTInterface::OnReply_RequestHistoryKL(Futu::u32_t nSerialNo, const Qot_RequestHistoryKL::Response &stRsp)
|
||||
{
|
||||
if (nSerialNo == m_RequestHistoryKLSerialNo)
|
||||
{
|
||||
cout << "OnReply_RequestHistoryKL SerialNo: " << nSerialNo << endl;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ṹ<EFBFBD><E1B9B9>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
// ProtoBufToBodyData<74><61>UTF8ToLocal<61><6C><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD>μ<EFBFBD>Sample<6C>е<EFBFBD>tool.h<>ļ<EFBFBD>
|
||||
string resp_str;
|
||||
ProtoBufToBodyData(stRsp, resp_str);
|
||||
qDebug() << QString(resp_str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||
* @praram nSerialNo <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
* @param stRsp <20>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ο<EFBFBD>Qot_StockFilter.protoЭ<6F><D0AD>
|
||||
*/
|
||||
void CFTInterface::OnReply_StockFilter(Futu::u32_t nSerialNo, const Qot_StockFilter::Response &stRsp)
|
||||
{
|
||||
if (nSerialNo != m_StockFilterSerialNo) return;
|
||||
|
||||
string resp_str;
|
||||
FastSerializeProto(stRsp, resp_str);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
|
||||
Qot_StockFilter::Response response;
|
||||
if (!response.ParseFromArray(resp_str.data(), resp_str.size())) {
|
||||
std::cerr << "Failed to parse protobuf data." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>鷵<EFBFBD><E9B7B5>״̬
|
||||
if (response.rettype() != 0) { // <20><><EFBFBD><EFBFBD> 0 <20><>ʾ<EFBFBD>ɹ<EFBFBD>
|
||||
qDebug() << QString(response.retmsg().data());
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> s2c <20>ֶ<EFBFBD>
|
||||
if (!response.has_s2c()) {
|
||||
std::cout << "No data in response." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const Qot_StockFilter::S2C& s2c = response.s2c();
|
||||
bool blastPage = s2c.lastpage();
|
||||
int nAllcount = s2c.allcount();
|
||||
if (!blastPage)
|
||||
{
|
||||
Sleep(3000); // ÿ 3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
m_nPagenumber += 100;
|
||||
getAllStock_HK();
|
||||
|
||||
qDebug() << "Startpage" << m_nPagenumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Over!";
|
||||
}
|
||||
//emit AllStock_HK(QByteArray(resp_str.data(), resp_str.size()));
|
||||
}
|
||||
|
||||
void CFTInterface::getAllStock_HK()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
Qot_StockFilter::Request req;
|
||||
Qot_StockFilter::C2S *c2s = req.mutable_c2s();
|
||||
c2s->set_begin(m_nPagenumber);
|
||||
c2s->set_num(100);
|
||||
c2s->set_market(1);
|
||||
|
||||
m_StockFilterSerialNo = m_pQotApi->StockFilter(req);
|
||||
}
|
||||
|
||||
void CFTInterface::subStock()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>Ҫ<EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>
|
||||
//Qot_Sub::Request req;
|
||||
//Qot_Sub::C2S *c2s = req.mutable_c2s();
|
||||
//auto secList = c2s->mutable_securitylist();
|
||||
//Qot_Common::Security *sec = secList->Add();
|
||||
//sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
|
||||
//c2s->add_subtypelist(Qot_Common::SubType::SubType_Basic);
|
||||
//c2s->add_subtypelist(Qot_Common::SubType::SubType_OrderBook);
|
||||
//c2s->set_isregorunregpush(true);
|
||||
//c2s->set_issuborunsub(true);
|
||||
|
||||
Qot_Sub::Request req;
|
||||
Qot_Sub::C2S *c2s = req.mutable_c2s();
|
||||
auto secList = c2s->mutable_securitylist();
|
||||
Qot_Common::Security *sec = secList->Add();
|
||||
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
|
||||
c2s->add_subtypelist(Qot_Common::SubType::SubType_OrderBook);
|
||||
c2s->set_isregorunregpush(true);
|
||||
c2s->set_issuborunsub(true);
|
||||
c2s->set_issuborderbookdetail(true);
|
||||
|
||||
for (const auto &value : m_codeList) {
|
||||
sec->set_code(value->stockCode.toStdString());
|
||||
m_SubSerialNo = m_pQotApi->Sub(req);
|
||||
}
|
||||
}
|
||||
|
||||
void CFTInterface::setReplyList(QList<QSharedPointer<ReplyCodeItem>>& replyCodes)
|
||||
{
|
||||
m_codeList = replyCodes;
|
||||
}
|
||||
|
||||
void CFTInterface::OnReply_Sub(Futu::u32_t nSerialNo, const Qot_Sub::Response &stRsp)
|
||||
{
|
||||
if (nSerialNo == m_SubSerialNo)
|
||||
{
|
||||
cout << "OnReply_Sub SerialNo: " << nSerialNo << endl;
|
||||
if (stRsp.rettype() != Common::RetType::RetType_Succeed)
|
||||
{
|
||||
cout << "Sub Failed" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CFTInterface::OnReply_GetBasicQot(Futu::u32_t nSerialNo, const Qot_GetBasicQot::Response &stRsp)
|
||||
{
|
||||
if (nSerialNo == m_GetBasicQotSerialNo)
|
||||
{
|
||||
cout << "OnReply_GetBasicQot SerialNo: " << nSerialNo << endl;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ṹ<EFBFBD><E1B9B9>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
// ProtoBufToBodyData<74><61>UTF8ToLocal<61><6C><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD>μ<EFBFBD>Sample<6C>е<EFBFBD>tool.h<>ļ<EFBFBD>
|
||||
string resp_str;
|
||||
ProtoBufToBodyData(stRsp, resp_str);
|
||||
qDebug() << QString(resp_str.c_str()) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CFTInterface::OnPush_UpdateOrderBook(const Qot_UpdateOrderBook::Response &stRsp)
|
||||
{
|
||||
processor.processOrderBook(stRsp);
|
||||
}
|
||||
Reference in New Issue
Block a user