以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 期货人生 (http://weistock.com/bbs/list.asp?boardid=7) ---- [原创]QT (http://weistock.com/bbs/dispbbs.asp?boardid=7&id=52968) |
-- 作者:z7c9 -- 发布时间:2013/6/12 17:57:37 -- [原创]QT #include <QCoreApplication> int main(int argc, char *argv[]) QDate startDate = QDate(2013,6,1); int b = startDate.daysTo(endDate); qDebug() << startDate; for(int i=1;i<b;++i){ qDebug() << endDate; return a.exec(); |
-- 作者:z7c9 -- 发布时间:2013/6/12 22:19:03 -- #include <QCoreApplication> void readFromEnd(QString path) qint8 c; while(nextend>start){ int main(int argc, char *argv[]) readFromEnd("d:/AL01.csv"); return a.exec(); |
-- 作者:z7c9 -- 发布时间:2013/6/17 21:21:48 -- #include <QCoreApplication> int main(int argc, char *argv[]) MimeMessage message; message.setSender(new EmailAddress("888888@139.com", "888888")); MimeText text; text.setText("888888"); message.addPart(&text); smtp.connectToHost(); } |
-- 作者:z7c9 -- 发布时间:2013/6/17 21:22:37 -- #include <QCoreApplication> //测试注册表读写 QSettings settings(path,QSettings::NativeFormat); settings.setValue("myid",12345); qDebug() << settings.value("myid").toInt(); //测试INI文件读写 QSettings settings(path,QSettings::IniFormat); settings.setValue("myid",12345); qDebug() << settings.value("myid").toInt(); //测试全局变量读写 //测试数据库读写 db.setDatabaseName("mytest.db"); if(!db.open()){ //测试CSV文件读写 if(csvFile.open(QIODevice::WriteOnly)){ if(csvFile.open(QIODevice::ReadOnly)){ int main(int argc, char *argv[]){ |
-- 作者:z7c9 -- 发布时间:2013/6/23 7:15:25 -- #include "mytraderspi.h" char FRONT_ADDR[] = "tcp://sim-front1.ctp.shcifco.com:31205";
void MyTraderSpi::OnFrontConnected() void MyTraderSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) void MyTraderSpi::OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) void MyTraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) [此贴子已经被作者于2013/6/23 7:15:57编辑过]
|
-- 作者:z7c9 -- 发布时间:2013/6/23 7:19:03 -- #include <QCoreApplication> int main(int argc, char *argv[]) MyTraderSpi spi; return a.exec(); |
-- 作者:z7c9 -- 发布时间:2013/6/23 19:27:41 -- #include <QCoreApplication>
#include <QDebug>
#include <QTextCodec>
#include <QByteArray>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QByteArray encodedString;
encodedString += "合约代码,";
encodedString += "交易所代码,";
encodedString += "合约名称,";
encodedString += "合约在交易所的代码,";
encodedString += "产品代码,";
encodedString += "产品类型,";
encodedString += "交割年份,";
encodedString += "交割月,";
encodedString += "市价单最大下单量,";
encodedString += "市价单最小下单量,";
encodedString += "限价单最大下单量,";
encodedString += "限价单最小下单量,";
encodedString += "合约数量乘数,";
encodedString += "最小变动价位,";
encodedString += "创建日,";
encodedString += "上市日,";
encodedString += "到期日,";
encodedString += "开始交割日,";
encodedString += "结束交割日,";
encodedString += "合约生命周期状态,";
encodedString += "当前是否交易,,";
encodedString += "持仓类型,";
encodedString += "持仓日期类型,";
encodedString += "多头保证金率,";
encodedString += "空头保证金率";
QTextCodec *codec = QTextCodec::codecForName("GBK");
QString string = codec->toUnicode(encodedString);
qDebug() << string;
return a.exec();
}
|
-- 作者:z7c9 -- 发布时间:2013/6/23 22:38:59 -- #include "mytraderspi.h"
void TraderSpi::OnFrontConnected() void TraderSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) void TraderSpi::OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) void TraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) QFile file("d:/ooo.csv"); if(file.open(QFile::Append)) qDebug() << QString::fromLocal8Bit(title); title += "\\n"; file.write(title); QByteArray content; qDebug() << QString::fromLocal8Bit(content); content += "\\n"; file.write(content); file.close(); |
-- 作者:z7c9 -- 发布时间:2013/6/27 21:51:42 -- QDate startDate(2013,6,1); QDate endDate(2013,6,27); int b = startDate.daysTo(endDate); for(int i=0;i<=b;++i){ CThostFtdcQrySettlementInfoField *req = new CThostFtdcQrySettlementInfoField(); strcpy(req->TradingDay,startDate.addDays(i).toString("yyyyMMdd").toLocal8Bit().data()); Commander *qry = new QrySettlementInfo(traderApi,req); commandQueue->enqueue(qry); } [此贴子已经被作者于2013/6/27 21:52:07编辑过]
|
-- 作者:z7c9 -- 发布时间:2013/7/21 16:04:09 -- #include
#include #include #include #include #include QString brokerId = "8070"; QString investorId = "888888"; QString password = "888888"; QString tradeFr; QString quoteFr; QStringList instrumentIds; qint32 reqNo = 0; CThostFtdcTraderApi *tradeApi = nullptr; CThostFtdcMdApi *quoteApi = nullptr; class QuoteSpi : public CThostFtdcMdSpi { public: QuoteSpi() { quoteApi = CThostFtdcMdApi::CreateFtdcMdApi(); quoteApi->RegisterSpi(this); quoteApi->RegisterFront(quoteFrontAddr.toLocal8Bit().data()); quoteApi->Init(); } void OnFrontConnected() { CThostFtdcReqUserLoginField req; memset(&req,0,sizeof(req)); quoteApi->ReqUserLogin(&req,++reqNo); } void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { qint32 size = instrumentIds.size(); char* *ppInstrumentId = new char*[size]; for(int i=0;i ppInstrumentId[i] = new char[ba.size()]; strcpy(ppInstrumentId[i],ba.data()); } quoteApi->SubscribeMarketData(ppInstrumentId,size); delete [] ppInstrumentId; ppInstrumentId = nullptr; } void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData) { qDebug() << QString::fromLocal8Bit(pDepthMarketData->InstrumentID); qDebug() << QString::number(pDepthMarketData->LastPrice); } }; class TradeSpi : public CThostFtdcTraderSpi { public: TradeSpi() { tradeApi = CThostFtdcTraderApi::CreateFtdcTraderApi(); tradeApi->RegisterSpi(this); tradeApi->SubscribePublicTopic(THOST_TERT_RESTART); tradeApi->SubscribePrivateTopic(THOST_TERT_RESTART); tradeApi->RegisterFront(tradeFrontAddr.toLocal8Bit().data()); tradeApi->Init(); } void OnFrontConnected() { CThostFtdcReqUserLoginField req; memset(&req,0,sizeof(req)); strcpy(req.BrokerID,brokerId.toLocal8Bit().data()); strcpy(req.UserID,investorId.toLocal8Bit().data()); strcpy(req.Password,password.toLocal8Bit().data()); tradeApi->ReqUserLogin(&req,++reqNo); } void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { CThostFtdcSettlementInfoConfirmField req; memset(&req,0,sizeof(req)); tradeApi->ReqSettlementInfoConfirm(&req,++reqNo); } void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { CThostFtdcQryInstrumentField req; memset(&req,0,sizeof(req)); tradeApi->ReqQryInstrument(&req,++reqNo); } void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { if(pInstrument){ instrumentIds.append(QString::fromLocal8Bit(pInstrument->InstrumentID)); } if(bIsLast){ QuoteSpi *quoteSpi = new QuoteSpi(); } } }; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); TradeSpi *tradeSpi = new TradeSpi(); return a.exec(); } [此贴子已经被作者于2013/7/21 16:04:46编辑过]
|