資源簡介
利用期貨ctp接口開發的數據接收例子。這樣的例子網上有很多,但是大部分都用不了。很多都有錯誤編譯不通過。這個是我可以完整編譯過的全部代碼,能直接從期貨公司獲取到數據。需要自己申請期貨賬號。編譯工具為vs2010或vs2012下可以順利通過
代碼片段和文件信息
#include?“MdSpi.h“
#include?
using?namespace?std;
#pragma?warning(disable?:?4996)
//?USER_API參數
extern?CThostFtdcMdApi*?pUserApi;
//?配置參數
extern?char?FRONT_ADDR[];
extern?TThostFtdcBrokerIDType BROKER_ID;
extern?TThostFtdcInvestorIDType?INVESTOR_ID;
extern?TThostFtdcPasswordType PASSWORD;
extern?char*?ppInstrumentID[];
extern?int?iInstrumentID;
//?請求編號
extern?int?iRequestID;
void?CMdSpi::OnRspError(CThostFtdcRspInfoField?*pRspInfo
int?nRequestID?bool?bIsLast)
{
cerr?<“--->>>?“< IsErrorRspInfo(pRspInfo);
}
void?CMdSpi::OnFrontDisconnected(int?nReason)
{
cerr?<“--->>>?“?< cerr?<“--->>>?Reason?=?“?<}
void?CMdSpi::OnHeartBeatWarning(int?nTimeLapse)
{
cerr?<“--->>>?“?< cerr?<“--->>>?nTimerLapse?=?“?<}
void?CMdSpi::OnFrontConnected()
{
cerr?<“--->>>?“?< ///用戶登錄請求
ReqUserLogin();
}
void?CMdSpi::ReqUserLogin()
{
CThostFtdcReqUserLoginField?req;
memset(&req?0?sizeof(req));
strcpy(req.BrokerID?BROKER_ID);
strcpy(req.UserID?INVESTOR_ID);
strcpy(req.Password?PASSWORD);
int?iResult?=?pUserApi->ReqUserLogin(&req?++iRequestID);
cerr?<“--->>>?發送用戶登錄請求:?“?<((iResult?==?0)???“成功“?:?“失敗“)?<}
void?CMdSpi::OnRspUserLogin(CThostFtdcRspUserLoginField?*pRspUserLogin
CThostFtdcRspInfoField?*pRspInfo?int?nRequestID?bool?bIsLast)
{
cerr?<“--->>>?“?< if?(bIsLast?&&?!IsErrorRspInfo(pRspInfo))
{
///獲取當前交易日
cerr?<“--->>>?獲取當前交易日?=?“?<GetTradingDay()?< //?請求訂閱行情
SubscribeMarketData();
}
}
void?CMdSpi::SubscribeMarketData()
{
int?iResult?=?pUserApi->SubscribeMarketData(ppInstrumentID?iInstrumentID);
cerr?<“--->>>?發送行情訂閱請求:?“?<((iResult?==?0)???“成功“?:?“失敗“)?<}
void?CMdSpi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField?*pSpecificInstrument?CThostFtdcRspInfoField?*pRspInfo?int?nRequestID?bool?bIsLast)
{
cerr?<}
void?CMdSpi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField?*pSpecificInstrument?CThostFtdcRspInfoField?*pRspInfo?int?nRequestID?bool?bIsLast)
{
cerr?<}
void?CMdSpi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField?*pDepthMarketData)
{
cerr?<}
bool?CMdSpi::IsErrorRspInfo(CThostFtdcRspInfoField?*pRspInfo)
{
//?如果ErrorID?!=?0?說明收到了錯誤的響應
bool?bResult?=?((pRspInfo)?&&?(pRspInfo->ErrorID?!=?0));
if?(bResult)
cerr?<“--->>>?ErrorID=“?<ErrorID?<“?ErrorMsg=“?<ErrorMsg?< return?bResult;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-17?10:53??CTPMDSAMPLE\
?????目錄???????????0??2015-07-17?10:50??CTPMDSAMPLE\Bin\
?????文件???????????6??2015-07-17?10:16??CTPMDSAMPLE\Bin\DialogRsp.con
?????文件???????????6??2015-07-17?10:16??CTPMDSAMPLE\Bin\QueryRsp.con
?????文件???????44032??2015-07-17?10:52??CTPMDSAMPLE\Bin\testMdUserApi.exe
?????文件??????414580??2015-07-17?10:52??CTPMDSAMPLE\Bin\testMdUserApi.ilk
?????文件?????1829888??2015-07-17?10:52??CTPMDSAMPLE\Bin\testMdUserApi.pdb
?????文件??????397312??2009-05-21?11:27??CTPMDSAMPLE\Bin\thostmduserapi.dll
?????文件?????1775616??2014-12-17?13:19??CTPMDSAMPLE\Bin\thosttraderapi.dll
?????文件???????????6??2012-10-25?14:05??CTPMDSAMPLE\Bin\TradingDay.con
?????目錄???????????0??2015-07-17?10:52??CTPMDSAMPLE\Debug\
?????文件????????2040??2015-07-17?10:52??CTPMDSAMPLE\Debug\cl.command.1.tlog
?????文件???????32270??2015-07-17?10:52??CTPMDSAMPLE\Debug\CL.read.1.tlog
?????文件????????1378??2015-07-17?10:52??CTPMDSAMPLE\Debug\CL.write.1.tlog
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????????2??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件????????2042??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件????????3858??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件????????1146??2015-07-17?10:52??CTPMDSAMPLE\Debug\li
?????文件???????60395??2015-07-17?10:50??CTPMDSAMPLE\Debug\MdSpi.obj
?????文件?????????410??2015-07-17?10:52??CTPMDSAMPLE\Debug\mt.command.1.tlog
?????文件?????????322??2015-07-17?10:52??CTPMDSAMPLE\Debug\mt.read.1.tlog
?????文件?????????322??2015-07-17?10:52??CTPMDSAMPLE\Debug\mt.write.1.tlog
?????文件?????????568??2015-07-17?10:50??CTPMDSAMPLE\Debug\rc.command.1.tlog
?????文件?????????294??2015-07-17?10:50??CTPMDSAMPLE\Debug\rc.read.1.tlog
?????文件?????????302??2015-07-17?10:50??CTPMDSAMPLE\Debug\rc.write.1.tlog
?????文件??????291156??2015-07-17?10:50??CTPMDSAMPLE\Debug\stdafx.obj
............此處省略52個文件信息
- 上一篇:QNX 官方完全源代碼 供學習參考 展開200M
- 下一篇:固體激光工程
評論
共有 條評論