public void Initialize() { _api = new MarketApi(_brokerID, _frontAddr); _api.OnRspError += new MarketApi.RspError((ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { Console.WriteLine("ErrorID: {0}, ErrorMsg: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg); }); _api.OnFrontConnected += new MarketApi.FrontConnected(() => { _isConnected = true; _api.UserLogin(-3, _investor, _password); }); _api.OnRspUserLogin += new MarketApi.RspUserLogin((ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { _isLogin = true; }); _api.OnRspUserLogout += new MarketApi.RspUserLogout((ref CThostFtdcUserLogoutField pRspUserLogout, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { _isLogin = false; _api.Disconnect(); }); _api.OnFrontDisconnected += new MarketApi.FrontDisconnected((int nReasion) => { _isConnected = false; }); _api.Connect(); Thread.Sleep(200); }
public void Initialize() { Console.WriteLine("CTP行情订阅初始化"); _api = new MarketApi(_brokerID, _frontAddr); _api.OnRspError += new MarketApi.RspError((ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { Console.WriteLine("ErrorID: {0}, ErrorMsg: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg); }); _api.OnFrontConnected += new MarketApi.FrontConnected(() => { Console.WriteLine("连接成功"); _api.UserLogin(-3, _investor, _password); }); _api.OnRspUserLogin += new MarketApi.RspUserLogin((ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { if (_isLogin == false) { _isLogin = true; _api.SubscribeMarketData(this._codeList); Console.WriteLine(" "); Console.WriteLine("***********************************************"); Console.WriteLine("***** CTP行情接收中,请勿关闭窗口!!! *****"); Console.WriteLine("***** CTP行情接收中,请勿关闭窗口!!! *****"); Console.WriteLine("***** CTP行情接收中,请勿关闭窗口!!! *****"); Console.WriteLine("***********************************************"); Console.WriteLine(" "); } }); _api.OnRspUserLogout += new MarketApi.RspUserLogout((ref CThostFtdcUserLogoutField pRspUserLogout, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { _isLogin = false; _api.Disconnect(); }); _api.OnFrontDisconnected += new MarketApi.FrontDisconnected((int nReasion) => { _isLogin = false; }); _api.OnHeartBeatWarning += new MarketApi.HeartBeatWarning((int nTimeLapse) => { Console.WriteLine(DateTime.Now.ToString()); _api.Connect(); }); _api.OnRspSubMarketData += new MarketApi.RspSubMarketData((ref CThostFtdcSpecificInstrumentField pSpecificInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) => { Console.WriteLine("订阅{0}成功", pSpecificInstrument.InstrumentID); Thread.Sleep(10); }); _api.OnRtnDepthMarketData += new MarketApi.RtnDepthMarketData((ref CThostFtdcDepthMarketDataField pDepthMarketData) => { try { OnReceiveHQ(pDepthMarketData); } catch (Exception e) { Console.WriteLine(e.ToString()); } }); _api.Connect(); Console.WriteLine("初始化完成"); }
/// <summary> /// 用户登录 /// </summary> /// <param name="callback">登录回调</param> /// <param name="investorID">投资者账号</param> /// <param name="password">密码</param> public void UserLogin(DataCallback callback, string investorID, string password) { int requestID = AddCallback(callback, -3); _api.UserLogin(requestID, investorID, password); }