資源簡介
上海期貨交易所的免費行情接口CTP封裝成DLL,可以給delphi、C#等調用,用于實時接收上海期貨交易所、大連商品期貨交易所,鄭州期貨交易所的行情
代碼片段和文件信息
//?MdApi.cpp?:?定義?DLL?應用程序的導出函數。
//
#include?“stdafx.h“
#include?“CtpApi.h“
#include?
//#include? //動態數組支持賦值
//using?namespace?std;
//?UserApi對象
CThostFtdcMdApi*?pUserApi;
//?請求編號
int?iRequestID?=?0;
//回調函數
CBOnRspError?cbOnRspError=0;
CBOnHeartBeatWarning?cbOnHeartBeatWarning=0;
CBOnFrontConnected?cbOnFrontConnected=0;
CBOnFrontDisconnected?cbOnFrontDisconnected=0;
CBOnRspUserLogin?cbOnRspUserLogin=0;
CBOnRspUserLogout?cbOnRspUserLogout=0;
CBOnRspSubMarketData?cbOnRspSubMarketData=0;
CBOnRspUnSubMarketData?cbOnRspUnSubMarketData=0;
CBOnRtnDepthMarketData?cbOnRtnDepthMarketData=0;
//連接
extern?“C“?{
CTPAPI_API?void??Connect(char?*pszFlowPath)
{
CThostFtdcMdSpi*?pUserSpi?=?new?CMdSpi();
//?初始化UserApi
pUserApi?=?CThostFtdcMdApi::CreateFtdcMdApi(pszFlowPath); //?創建UserApi
pUserApi->RegisterSpi(pUserSpi); //?注冊事件類
//pUserApi->RegisterFront(FRONT_ADDR); //?connect
//pUserApi->Init();
//pUserApi->Join();
}
///初始化
///@remark?初始化運行環境只有調用后接口才開始工作
CTPAPI_API?void?Init()
{
pUserApi->Init();
}
///等待接口線程結束運行
///@return?線程退出代碼
CTPAPI_API?int?Join()?
{
return?pUserApi->Join();
}
CTPAPI_API?void?Release()
{
pUserApi->Release();
}
///注冊前置機網絡地址
///@param?pszFrontAddress:前置機網絡地址。
///@remark?網絡地址的格式為:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。?
///@remark?“tcp”代表傳輸協議,“127.0.0.1”代表服務器地址。”17001”代表服務器端口號。
CTPAPI_API?void?RegisterFront(char?*pszFrontAddress)?
{
pUserApi->RegisterFront(pszFrontAddress);
}
///注冊名字服務器網絡地址
///@param?pszNsAddress:名字服務器網絡地址。
///@remark?網絡地址的格式為:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。?
///@remark?“tcp”代表傳輸協議,“127.0.0.1”代表服務器地址。”12001”代表服務器端口號。
///@remark?RegisterNameServer優先于RegisterFront
CTPAPI_API?void?RegisterNameServer(char?*pszNsAddress)
{
pUserApi->RegisterNameServer(pszNsAddress);
}
///注冊名字服務器用戶信息
///@param?pFensUserInfo:用戶信息。
CTPAPI_API?void?RegisterFensUserInfo(CThostFtdcFensUserInfoField?*?pFensUserInfo)
{
pUserApi->RegisterFensUserInfo(?pFensUserInfo);
}
//登錄
CTPAPI_API?int?ReqUserLogin(TThostFtdcBrokerIDType?BROKER_IDTThostFtdcInvestorIDType?UserIDTThostFtdcPasswordType Password)
{
CThostFtdcReqUserLoginField?req;
memset(&req?0?sizeof(req));
strcpy_s(req.BrokerID?BROKER_ID);
strcpy_s(req.UserID?UserID);
strcpy_s(req.Password?Password);
return?pUserApi->ReqUserLogin(&req?++iRequestID);
}
//CTPAPI_API?int?ReqUserLogin(CThostFtdcReqUserLoginField?*pReqUserLoginField?int?nRequestID)
//{
// return?pUserApi->ReqUserLogin(pReqUserLoginField?nRequestID);
//}
///登出請求
CTPAPI_API?int??ReqUserLogout(TThostFtdcBrokerIDType?BROKER_IDTThostFtdcInvestorIDType?INVESTOR_ID)
{
CThostFtdcUserLogoutField?req;
memset(&req0sizeof(req));
strcpy_s(req.BrokerIDBROKER_ID);
strcpy_s(req.UserIDINVESTOR_ID);
return?pUserApi->ReqUserLogout(&req++iRequestID);
}
//CTPAPI_API?int??ReqUserLogout(CThostFtdcUserLogoutField?*pUserLogout?int?nReque
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5032??2013-12-16?22:41??CtpApi\ApiMain.cpp
?????文件???????3175??2013-12-14?21:42??CtpApi\CtpApi.cpp
?????文件???????3821??2013-12-14?22:18??CtpApi\CtpApi.h
?????文件???????5201??2013-12-14?21:42??CtpApi\CtpApi.vcxproj
?????文件???????1664??2013-12-14?21:42??CtpApi\CtpApi.vcxproj.filters
?????文件????????143??2013-12-11?21:11??CtpApi\CtpApi.vcxproj.user
?????文件??????59066??2013-12-16?22:41??CtpApi\Debug\ApiMain.obj
?????文件???????2880??2013-12-16?22:41??CtpApi\Debug\cl.command.1.tlog
?????文件??????30732??2013-12-16?22:41??CtpApi\Debug\CL.read.1.tlog
?????文件???????1278??2013-12-16?22:41??CtpApi\Debug\CL.write.1.tlog
?????文件?????????41??2013-12-16?22:42??CtpApi\Debug\CtpApi.lastbuildstate
?????文件???????2310??2013-12-16?22:42??CtpApi\Debug\CtpApi.log
?????文件??????39651??2013-12-14?22:18??CtpApi\Debug\CtpApi.obj
?????文件????4128768??2013-12-11?21:22??CtpApi\Debug\CtpApi.pch
?????文件???????2604??2013-12-16?22:42??CtpApi\Debug\CtpApi.write.1.tlog
?????文件???????8836??2013-12-14?22:07??CtpApi\Debug\dllmain.obj
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:42??CtpApi\Debug\li
?????文件??????????2??2013-12-16?22:41??CtpApi\Debug\li
............此處省略66個文件信息
評論
共有 條評論