public void Entrust(EntrustPara param) { Debug.Print(string.Format("正在下单:c={0},p={1},v={2}", param.stockcode, param.price, param.volume)); CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("market_no", Convert.ToSByte('S'), 3, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddField("entrust_direction", Convert.ToSByte('S'), 3, 4); packer.AddField("futures_direction", Convert.ToSByte('S'), 1, 4); packer.AddField("price_type", Convert.ToSByte('S'), 1, 4); packer.AddField("entrust_price", Convert.ToSByte('F'), 11, 4); packer.AddField("entrust_amount", Convert.ToSByte('F'), 16, 2); packer.AddField("covered_flag", Convert.ToSByte('S'), 1, 2); packer.AddStr(this.token); packer.AddStr(this.currcombino); packer.AddStr(param.marketno); packer.AddStr(param.stockcode); packer.AddStr(param.entrustdirection); packer.AddStr(param.futuredirection); //futrue direction '1'-开仓; '2'-平仓。 packer.AddStr("0"); //0=限价 packer.AddDouble(param.price); packer.AddDouble(param.volume); packer.AddStr("0"); //covered_flag,备兑标志,0=非备兑 packer.EndPack(); this.sendpacker(OptionFunctionCode.Entrust, packer); }
public override void OptionBasketEntrust(List <EntrustPara> paramlist) { try { if (!islogon()) { return; } if (paramlist == null || paramlist.Count == 0) { return; } string codelist = "|"; #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("market_no", Convert.ToSByte('S'), 3, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddField("entrust_direction", Convert.ToSByte('S'), 3, 4); packer.AddField("futures_direction", Convert.ToSByte('S'), 1, 4); packer.AddField("price_type", Convert.ToSByte('S'), 1, 4); packer.AddField("entrust_price", Convert.ToSByte('F'), 11, 4); packer.AddField("entrust_amount", Convert.ToSByte('F'), 16, 2); packer.AddField("covered_flag", Convert.ToSByte('S'), 1, 2); foreach (EntrustPara param in paramlist) { packer.AddStr(this.token); packer.AddStr(param.portfolio); packer.AddStr(this.getMarketNo(param.exchange)); packer.AddStr(param.securitycode); packer.AddStr(((int)param.entrustdirection).ToString()); packer.AddStr(((int)param.futuredirection).ToString()); packer.AddStr("0"); //0=限价 packer.AddDouble(param.price); packer.AddDouble(param.volume); packer.AddStr("0"); //covered_flag,备兑标志,0=非备兑 codelist += param.securitycode + "|"; } packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.BasketEntrust, packer); MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("篮子委托:共{0}笔,{1}", paramlist.Count, codelist)); } catch (Exception ex) { throw ex; } }
private void button1_Click(object sender, EventArgs e) { //初始化t2连接 if (!InitT2()) { return; } //打包请求报文 CT2Packer packer = new CT2Packer(2); sbyte strType = Convert.ToSByte('S'); sbyte intType = Convert.ToSByte('I'); packer.BeginPack(); //插件编号 packer.AddField("plugin_id", strType, 255, 4); //管理功能号 packer.AddField("function_id", intType, 255, 4); packer.AddStr("com.hundsun.fbase.f2core"); packer.AddInt(100); packer.EndPack(); //功能号,业务包 int iRet = conn.SendBiz(8, packer, 0, 0, 1); if (iRet < 0) { DisplayText(conn.GetErrorMsg(iRet)); } else { string error = null; CT2UnPacker unpacker = null; iRet = conn.RecvBiz(iRet, out error, out unpacker, 4000, 0); if (iRet == 0 || iRet == 1) { while (unpacker.IsEOF() != 1) { for (int i = 0; i < unpacker.GetColCount(); i++) { textBox1.Text += unpacker.GetStrByIndex(i) + " "; } textBox1.Text += "\r\n"; unpacker.Next(); } } else if (iRet < 0) { DisplayText(conn.GetErrorMsg(iRet)); } else if (iRet == 2) { DisplayText("解包失败"); } } packer.Dispose(); }
public ConnectionCode Subscribe(LoginUser user, IUFXMessageHandlerFactory handlerFactory) { callback = new T2SubCallback(handlerFactory); subcribe = _conn.NewSubscriber(callback, SubscribeName, (int)_timeOut, 2000, 100); if (subcribe == null) { string msg = string.Format("主推业务订阅创建失败: {0}", _conn.GetMCLastError()); logger.Error(msg); return(ConnectionCode.ErrorFailSubscribe); } CT2SubscribeParamInterface args = new CT2SubscribeParamInterface(); args.SetTopicName("ufx_topic"); args.SetReplace(false); args.SetFilter("operator_no", user.Operator); CT2Packer req = new CT2Packer(2); req.BeginPack(); req.AddField("login_operator_no", Convert.ToSByte('S'), 16, 4); req.AddField("password", Convert.ToSByte('S'), 16, 4); req.AddStr(user.Operator); req.AddStr(user.Password); req.EndPack(); CT2UnPacker unpacker = null; int ret = subcribe.SubscribeTopicEx(args, 50000, out unpacker, req); req.Dispose(); //根据文档说明,返回值大于0表示有效的订阅标识,否则其他表示错误。 if (ret > 0) { string msg = string.Format("主推业务订阅创建成功, 返回码: {0}, 消息: {1}", ret, _conn.GetErrorMsg(ret)); logger.Info(msg); return(ConnectionCode.SuccessSubscribe); } else { string outMsg = string.Empty; if (unpacker != null) { //Show(back); DataParser parser = new DataParser(); parser.Parse(unpacker); unpacker.Dispose(); var errResponse = T2ErrorHandler.Handle(parser); outMsg = errResponse.MessageDetail; } string msg = string.Format("主推业务订阅创建失败,返回码: {0}, 消息: {1}, 返回数据包消息: {2}", ret, _conn.GetErrorMsg(ret), outMsg); logger.Error(msg); return(ConnectionCode.ErrorFailSubscribe); } }
public void Logon(string user, string pwd, string accno, string combino) { this.curraccno = accno; this.currcombino = combino; CT2Packer packer = new CT2Packer(2); packer.BeginPack(); //字段名 packer.AddField("operator_no", Convert.ToSByte('S'), 16, 4); packer.AddField("password", Convert.ToSByte('S'), 16, 4); packer.AddField("mac_address", Convert.ToSByte('S'), 32, 4); packer.AddField("ip_address", Convert.ToSByte('S'), 32, 4); packer.AddField("hd_volserial", Convert.ToSByte('S'), 10, 4); packer.AddField("op_station", Convert.ToSByte('S'), 255, 4); packer.AddField("authorization_id", Convert.ToSByte('S'), 64, 4); packer.AddField("login_time", Convert.ToSByte('S'), 6, 4); packer.AddField("verification_code", Convert.ToSByte('S'), 32, 4); //参数值 packer.AddStr(user); packer.AddStr(pwd); packer.AddStr("mac"); packer.AddStr("ip"); packer.AddStr("vol"); packer.AddStr("op_station"); packer.AddStr(""); packer.AddStr(""); packer.AddStr(""); packer.EndPack(); this.sendpacker(OptionFunctionCode.Logon, packer); }
public override void Logon(string user, string pwd) { //无需重复登陆 if (islogon()) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); //字段名 packer.AddField("operator_no", Convert.ToSByte('S'), 16, 4); packer.AddField("password", Convert.ToSByte('S'), 16, 4); packer.AddField("mac_address", Convert.ToSByte('S'), 32, 4); packer.AddField("ip_address", Convert.ToSByte('S'), 32, 4); packer.AddField("hd_volserial", Convert.ToSByte('S'), 10, 4); packer.AddField("op_station", Convert.ToSByte('S'), 255, 4); packer.AddField("authorization_id", Convert.ToSByte('S'), 64, 4); packer.AddField("login_time", Convert.ToSByte('S'), 6, 4); packer.AddField("verification_code", Convert.ToSByte('S'), 32, 4); //参数值 packer.AddStr(user); packer.AddStr(pwd); packer.AddStr("mac"); //TODO: 使用真实数据替代 packer.AddStr("ip"); packer.AddStr("vol"); packer.AddStr("op"); packer.AddStr(""); packer.AddStr(""); packer.AddStr(""); packer.EndPack(); #endregion MessageManager.GetInstance().Add(MessageType.Warning, string.Format("Logon:mac,ip等信息为虚拟的")); int retcode = this.sendpacker(OptionFunction.Logon, packer, false); #region unpacker CT2UnPacker unpacker = getCallbackData(retcode); if (unpacker != null) { this.token = unpacker.GetStr("user_token"); MessageManager.GetInstance().Add(MessageType.Information, string.Format("恒生系统登陆成功:{0}", this.token)); } else { this.token = null; MessageManager.GetInstance().Add(MessageType.Error, string.Format("恒生系统登陆失败")); } #endregion }
public void Withdraw(int enrtustno) { Debug.Print(string.Format("正在撤单:no={0}", enrtustno)); CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("entrust_no", Convert.ToSByte('I'), 8, 4); packer.AddStr(token); packer.AddInt(enrtustno); packer.EndPack(); this.sendpacker(OptionFunctionCode.Withdraw, packer); }
public ConnectionCode HeartBeat() { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.HeartBeat); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.HeartBeat); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(LoginManager.Instance.LoginUser.Token); break; default: break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendSync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("心跳检测失败"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
public void Subcribe(string user, string pwd) { subcallback = new UFXSubCallback(this); subcribe = this.connMain.NewSubscriber(subcallback, "ufx_demo", 50000, 2000, 100); if (subcribe == null) { Debug.Print(string.Format("订阅创建失败 {0}", connMain.GetMCLastError())); return; } CT2SubscribeParamInterface args = new CT2SubscribeParamInterface(); args.SetTopicName("ufx_topic"); args.SetReplace(false); args.SetFilter("operator_no", user); CT2Packer req = new CT2Packer(2); req.BeginPack(); req.AddField("login_operator_no", Convert.ToSByte('S'), 16, 4); req.AddField("password", Convert.ToSByte('S'), 16, 4); req.AddStr(user); req.AddStr(pwd); req.EndPack(); CT2UnPacker unpacker = null; int ret = subcribe.SubscribeTopicEx(args, 50000, out unpacker, req); req.Dispose(); if (ret > 0) { Debug.Print("订阅成功"); subcribeid = ret; } else { if (unpacker != null) { Debug.Print("订阅失败"); this.ShowUnPacker(unpacker); } } }
public int QueryPosition(QueryPara param) { CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("account_code", Convert.ToSByte('S'), 32, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddStr(this.token); packer.AddStr(this.curraccno); packer.AddStr(this.currcombino); packer.AddStr(param.stock_code); packer.EndPack(); return(this.sendpacker(OptionFunctionCode.QueryPosition, packer, false)); }
private void button2_Click(object sender, EventArgs e) { //打包请求报文 CT2Packer packer = new CT2Packer(2); sbyte strType = Convert.ToSByte('S'); sbyte intType = Convert.ToSByte('I'); packer.BeginPack(); //插件编号 packer.AddField("plugin_id", strType, 255, 4); //管理功能号 packer.AddField("function_id", intType, 255, 4); packer.AddStr("com.hundsun.fbase.f2core"); packer.AddInt(100); packer.EndPack(); int iRet = conn.SendBiz(8, packer, 1, 0, 1); packer.Dispose(); }
public override void OptionWithdraw(List <int> entrustnolist) { try { if (!islogon()) { return; } if (entrustnolist == null || entrustnolist.Count == 0) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("entrust_no", Convert.ToSByte('I'), 8, 4); string entrustlist = ""; foreach (int entrustno in entrustnolist) { packer.AddStr(this.token); packer.AddInt(entrustno); entrustlist += entrustno + "|"; } packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.Withdraw, packer); MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("委托撤单:共{0}笔,|{1}", entrustnolist.Count, entrustlist)); } catch (Exception ex) { throw ex; } }
public override void SendHeartbeat() { //无需重复登陆 if (!islogon()) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("operator_no", Convert.ToSByte('S'), 16, 4); packer.AddStr(this.token); packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.Logon, packer, false); }
public ConnectionCode EntrustBasket() { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.EntrustBasket); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.EntrustBasket); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": { packer.AddStr(userToken); } break; case "account_code": { packer.AddStr(""); } break; case "asset_no": { packer.AddStr(""); } break; case "combi_no": { packer.AddStr(""); } break; case "instance_no": { packer.AddStr(""); } break; case "stockholder_id": { packer.AddStr(""); } break; case "report_seat": { packer.AddStr(""); } break; case "market_no": { packer.AddStr(""); } break; case "stock_code": { packer.AddStr(""); } break; case "entrust_direction": { packer.AddStr(""); } break; case "futures_direction": { packer.AddStr(""); } break; case "price_type": { packer.AddDouble(0.0f); } break; case "entrust_price": { packer.AddDouble(0.0f); } break; case "entrust_amount": { packer.AddInt(0); } break; case "limit_entrust_ratio": { packer.AddDouble(0.0f); } break; case "max_cancel_ratio": { packer.AddDouble(0.0f); } break; case "invest_type": { packer.AddStr(""); } break; case "extsystem_id": { packer.AddStr(""); } break; case "third_reff": { packer.AddStr(""); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("证券篮子委托失败!"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
public DataParser SubmitSync <T>(UFXFunctionCode functionCode, List <T> requests) { DataParser parser = new DataParser(); FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode); logger.Error(msg); parser.ErrorCode = ConnectionCode.ErrorNoFunctionCode; return(parser); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode); logger.Error(msg); parser.ErrorCode = ConnectionCode.ErrorLogin; return(parser); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } var dataFieldMap = UFXDataBindingHelper.GetProperty <T>(); foreach (var request in requests) { foreach (FieldItem item in functionItem.RequestFields) { if (dataFieldMap.ContainsKey(item.Name)) { SetRequestField <T>(ref packer, request, item, dataFieldMap); } else { SetRequestDefaultField(ref packer, item, userToken); } } } packer.EndPack(); #if DEBUG OutputParam <T>(functionCode, requests); #endif unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } parser = _t2SDKWrap.SendSync2(bizMessage); return(parser); }
public ConnectionCode Login(LoginUser user) { UFXFunctionCode functionCode = UFXFunctionCode.Login; FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } LoginManager.Instance.LoginUser = user; CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "operator_no": packer.AddStr(user.Operator); break; case "password": packer.AddStr(user.Password); break; case "mac_address": { packer.AddStr(ConfigManager.Instance.GetTerminalConfig().MacAddress); } break; case "op_station": { packer.AddStr("www.htsec.com"); } break; case "ip_address": { packer.AddStr(ConfigManager.Instance.GetTerminalConfig().IPAddress); } break; case "hd_volserial": { packer.AddStr(""); } break; case "authorization_id": { //TODO: packer.AddStr("authorization_id"); } break; default: if (item.Type == UFXPackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == UFXPackFieldType.StringType || item.Type == UFXPackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } var parser = _t2SDKWrap.SendSync2(bizMessage); packer.Dispose(); bizMessage.Dispose(); var ret = parser.ErrorCode; if (ret == ConnectionCode.Success) { string token = string.Empty; string version = string.Empty; var response = T2ErrorHandler.Handle(parser); if (T2ErrorHandler.Success(response.ErrorCode)) { if (parser.DataSets[1].Rows[0].Columns.ContainsKey("user_token")) { token = parser.DataSets[1].Rows[0].Columns["user_token"].GetStr(); } if (parser.DataSets[1].Rows[0].Columns.ContainsKey("version_no")) { version = parser.DataSets[1].Rows[0].Columns["version_no"].GetStr(); } string msg = string.Format("Login success - token: [{0}], version: [{1}]", token, version); UFXLogger.Info(logger, functionCode, msg); } else { UFXLogger.Error(logger, functionCode, response); } if (!string.IsNullOrEmpty(token)) { LoginManager.Instance.LoginUser.Token = token; ret = ConnectionCode.Success; } else { ret = ConnectionCode.ErrorLogin; } } return(ret); }
public ConnectionCode Logout() { UFXFunctionCode functionCode = UFXFunctionCode.Logout; FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(LoginManager.Instance.LoginUser.Token); break; default: break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } var parser = _t2SDKWrap.SendSync2(bizMessage); packer.Dispose(); bizMessage.Dispose(); var ret = parser.ErrorCode; if (ret == ConnectionCode.Success) { var response = T2ErrorHandler.Handle(parser); if (!T2ErrorHandler.Success(response.ErrorCode)) { UFXLogger.Error(logger, functionCode, response); return(ConnectionCode.ErrorFailContent); } } else { UFXLogger.Error(logger, functionCode, "退出登录失败!"); } return(ret); }
public ConnectionCode Login(User user) { if (!IsInit) { var retCon = Init(); if (retCon != ConnectionCode.Success) { return(retCon); } } FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.Login); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.Login); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "operator_no": packer.AddStr(user.Operator); break; case "password": packer.AddStr(user.Password); break; case "mac_address": { packer.AddStr(ConfigManager.Instance.GetTerminalConfig().MacAddress); } break; case "op_station": { packer.AddStr("www.htsec.com"); } break; case "ip_address": { packer.AddStr(ConfigManager.Instance.GetTerminalConfig().IPAddress); } break; case "hd_volserial": { packer.AddStr(""); } break; case "authorization_id": { //TODO: packer.AddStr("authorization_id"); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = SendSync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("登录失败:" + _conn.GetErrorMsg(retCode)); return(ConnectionCode.ErrorConn); } return(ReceivedBizMsg(retCode, FunctionCode.Login)); }
public ConnectionCode Logout() { if (!IsInit) { var retCon = Init(); if (retCon != ConnectionCode.Success) { return(retCon); } } FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.Logout); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.Logout); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(LoginManager.Instance.LoginUser.Token); break; default: break; } } unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = SendSync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("退出登录失败:" + _conn.GetErrorMsg(retCode)); return(ConnectionCode.ErrorConn); } var retConnCode = ReceivedBizMsg(retCode, FunctionCode.Logout); return(retConnCode); }
public void SendFunctionAction(int functionId, string functionIdGenerationStr, Action <ShowList> callback) { CT2Esbmsg t2Message = new CT2Esbmsg(); //构造消息 t2Message.GetItem(CT2tag_def.TAG_FUNCTION_ID).SetInt(functionId, 0); //设置功能号 t2Message.GetItem(CT2tag_def.TAG_PACKET_TYPE).SetInt(0, 0);; //设置消息类型为请求 //打包请求报文 CT2Packer packer = new CT2Packer(3); sbyte strType = Convert.ToSByte('S'); sbyte intType = Convert.ToSByte('I'); sbyte charType = Convert.ToSByte('C'); packer.BeginPack(); //插件编号 //管理功能号 foreach (var item in _sendFunctionDtoList) { if (item.Type == "int") { packer.AddField(item.Name, intType, 255, 4); } else if (item.Type == "string") { packer.AddField(item.Name, strType, 255, 4); } } foreach (var item in _sendFunctionDtoList) { if (item.Type == "int") { packer.AddInt(Convert.ToInt32(item.Value)); } else if (item.Type == "string") { packer.AddStr(item.Value); } } packer.EndPack(); unsafe { t2Message.GetItem(CT2tag_def.TAG_MESSAGE_BODY).SetRawData(packer.GetPackBuf(), packer.GetPackLen()); int iMsgLen = 0; void *lpData = t2Message.GetBuffer(&iMsgLen); int iRet = Conn.Send(lpData, iMsgLen, 0); if (iRet < 0) { MessageBox.Show(Conn.GetErrorMsg(iRet)); } else { void *lpRecvData = null; int iRecvLen = 0; iRet = Conn.Receive(iRet, &lpRecvData, &iRecvLen, 5000, 0); if (iRet == 0) { CT2Esbmsg ansMessage = new CT2Esbmsg(); //构造消息 int iParseError = ansMessage.SetBuffer(lpRecvData, iRecvLen); //解析消息 if (iParseError != 0) { MessageBox.Show("同步接收业务错误:解析消息失败\n"); } else { int iRetCode = ansMessage.GetItem(CT2tag_def.TAG_RETURN_CODE).GetInt(0); //获取返回码 int iErrorCode = ansMessage.GetItem(CT2tag_def.TAG_ERROR_NO).GetInt(0); //获取错误码 if (iErrorCode != 0) { MessageBox.Show("同步接收出错:" + ansMessage.GetItem(CT2tag_def.TAG_ERROR_NO).GetString(0) + ansMessage.GetItem(CT2tag_def.TAG_ERROR_INFO).GetString(0)); } else { CT2UnPacker unpacker = null; unsafe { int iLen = 0; void *lpdata = ansMessage.GetItem(CT2tag_def.TAG_MESSAGE_BODY).GetRawData(&iLen, 0); unpacker = new CT2UnPacker(lpdata, (uint)iLen); } //返回业务错误 if (iRetCode != 0) { MessageBox.Show("同步接收业务出错:\n"); UnPack(unpacker); } //正常业务返回 else { UnPack(unpacker); callback?.Invoke(_showlist); } unpacker.Dispose(); } } ansMessage.Dispose(); } else { Conn.GetErrorMsg(iRet); } } } t2Message.Dispose(); packer.Dispose(); }
public ConnectionCode QueryHolder() { UFXFunctionCode functionCode = UFXFunctionCode.QueryHolder; FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(LoginManager.Instance.LoginUser.Token); break; case "account_code": packer.AddStr(""); break; case "asset_no": packer.AddStr(""); break; case "combi_no": packer.AddStr(""); break; case "market_no": packer.AddStr(""); break; default: break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } var parser = _t2SDKWrap.SendSync2(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (parser.ErrorCode != ConnectionCode.Success) { UFXLogger.Error(logger, functionCode, "交易股东查询失败"); return(parser.ErrorCode); } var response = T2ErrorHandler.Handle(parser); if (T2ErrorHandler.Success(response.ErrorCode)) { if (parser.DataSets.Count > 1) { var dataSet = parser.DataSets[1]; foreach (var dataRow in dataSet.Rows) { HolderItem p = new HolderItem(); p.AccountCode = dataRow.Columns["account_code"].GetStr(); p.AssetNo = dataRow.Columns["asset_no"].GetStr(); p.CombiNo = dataRow.Columns["combi_no"].GetStr(); p.StockHolderId = dataRow.Columns["stockholder_id"].GetStr(); p.MarketNo = dataRow.Columns["market_no"].GetStr(); LoginManager.Instance.AddHolder(p); } } return(ConnectionCode.Success); } else { UFXLogger.Error(logger, functionCode, response); return(ConnectionCode.ErrorFailContent); } }
public ConnectionCode QueryAccount() { UFXFunctionCode functionCode = UFXFunctionCode.QueryAccount; FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(LoginManager.Instance.LoginUser.Token); break; case "account_code": packer.AddStr(""); break; default: break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } var parser = _t2SDKWrap.SendSync2(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (parser.ErrorCode != ConnectionCode.Success) { UFXLogger.Error(logger, functionCode, "账户查询失败"); return(ConnectionCode.ErrorConn); } var response = T2ErrorHandler.Handle(parser); if (T2ErrorHandler.Success(response.ErrorCode)) { if (parser.DataSets.Count > 1) { var dataSet = parser.DataSets[1]; foreach (var dataRow in dataSet.Rows) { AccountItem acc = new AccountItem(); acc.AccountCode = dataRow.Columns["account_code"].GetStr(); acc.AccountName = dataRow.Columns["account_name"].GetStr(); string accType = dataRow.Columns["account_type"].GetStr(); int temp; if (int.TryParse(accType, out temp)) { acc.AccountType = (FundAccountType)temp; } LoginManager.Instance.AddAccount(acc); } } return(ConnectionCode.Success); } else { UFXLogger.Error(logger, functionCode, response); return(ConnectionCode.ErrorFailContent); } }
public ConnectionCode QueryTrading() { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } //string[] account_code = new string[3] { "850010", "S54638", "SF0007" }; //foreach (string s in account_code) //{ foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": { packer.AddStr(userToken); } break; case "account_group_code": { packer.AddStr(""); } break; case "instance_no": { packer.AddStr(""); } break; case "instance_type": { packer.AddStr(""); } break; case "ext_invest_plan_no_list": { packer.AddStr(""); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } //} packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("查询交易实例失败!"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
/// <summary> /// 异步调用UFX接口,完成调用之后,如果不出错,则注册回调信息 /// </summary> /// <typeparam name="T">A generic type defines the UFX request parameters.</typeparam> /// <param name="functionCode">An enum type defines the UFX interface number.</param> /// <param name="requests">A generic request list. NOTE: the caller MUST control the request count if the /// interface does not support many requests at a time. /// </param> /// <param name="callbacker">It is used to store the callback information.</param> /// <returns>It is used to define the call result.</returns> public ConnectionCode SubmitAsync <T>(UFXFunctionCode functionCode, List <T> requests, Callbacker callbacker) { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode); logger.Error(msg); return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode); logger.Error(msg); return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)functionCode); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } var dataFieldMap = UFXDataBindingHelper.GetProperty <T>(); foreach (var request in requests) { foreach (FieldItem item in functionItem.RequestFields) { if (dataFieldMap.ContainsKey(item.Name)) { SetRequestField <T>(ref packer, request, item, dataFieldMap); } else { SetRequestDefaultField(ref packer, item, userToken); } } } packer.EndPack(); #if DEBUG OutputParam <T>(functionCode, requests); #endif unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } ConnectionCode retCode = ConnectionCode.Success; int hSend = _t2SDKWrap.SendAsync(bizMessage); if (hSend < 0) { string msg = string.Format("提交UFX请求[{0}]失败, 返回值:[{1}]!", functionCode, hSend); logger.Error(msg); retCode = ConnectionCode.ErrorConn; } else { //注册UFX返回数据后,需要调用的回调 //此处存在假设,异步提交返回之前,不会触发回调 AddDataHandler(functionCode, hSend, callbacker); retCode = ConnectionCode.Success; } packer.Dispose(); bizMessage.Dispose(); return(retCode); }
public override void OptionEntrustQuery(QueryPara param, List <EntrustBook> entrustbook) { try { if (!islogon()) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("account_code", Convert.ToSByte('S'), 32, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddStr(this.token); packer.AddStr(param.fundcode); packer.AddStr(param.portfolio); packer.AddStr(param.securitycode); packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.EntrustQuery, packer, false); #region unpacker CT2UnPacker unpacker = getCallbackData(retcode); if (unpacker != null) { //更新委托列表 entrustbook.Clear(); while (unpacker.IsEOF() == 0) { EntrustBook enbook = new EntrustBook(); enbook.code = unpacker.GetStr("stock_code"); enbook.batchno = unpacker.GetInt("batch_no"); enbook.entrustno = unpacker.GetInt("entrust_no"); enbook.price = unpacker.GetDouble("entrust_price"); enbook.message = unpacker.GetStr("withdraw_cause"); //委托 int entrustdirction = unpacker.GetInt("entrust_direction"); if (entrustdirction == 1) { enbook.tradedirection = TradeDirection.BUY; } else { enbook.tradedirection = TradeDirection.SELL; } //开平 int futuredirection = unpacker.GetInt("futures_direction"); if (futuredirection == 1) { enbook.futuredirection = FutureDirection.OPEN; } else { enbook.futuredirection = FutureDirection.COVER; } //剩余数量 int entrustvol = unpacker.GetInt("entrust_amount"); int dealvol = unpacker.GetInt("deal_amount"); enbook.volume = entrustvol - dealvol; //委托状态 string entruststate = unpacker.GetStr("entrust_state"); //委托状态 switch (entruststate) { case "1": //未报 case "4": //已报 case "6": //部成 if (enbook.price > 0 && enbook.volume > 0) { entrustbook.Add(enbook); } break; case "5": //废单 case "7": //已成 case "8": //部撤 case "9": //已撤 case "a": //待撤 case "A": //未撤 case "B": //待撤 case "C": //正撤 case "D": //撤认 case "E": //撤废 case "F": //已撤 break; default: break; } unpacker.Next(); } } else { MessageManager.GetInstance().Add(MessageType.Error, string.Format("委托查询失败:{0}", param.securitycode)); } #endregion } catch (Exception ex) { throw ex; } }
public override void OptionPositionQuery(QueryPara param, List <PositionBook> positionbook) { try { if (!islogon()) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("account_code", Convert.ToSByte('S'), 32, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddStr(this.token); packer.AddStr(param.fundcode); packer.AddStr(param.portfolio); packer.AddStr(param.securitycode); packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.PositionQuery, packer, false); #region unpacker CT2UnPacker unpacker = getCallbackData(retcode); if (unpacker != null) { //更新持仓 positionbook.Clear(); while (unpacker.IsEOF() == 0) { PositionBook pbook = new PositionBook(); pbook.code = unpacker.GetStr("stock_code"); int pflag = unpacker.GetInt("position_flag"); if (pflag == 1) { pbook.positiondirection = PostionDerection.LONG; } else { pbook.positiondirection = PostionDerection.SHORT; } pbook.volume = unpacker.GetInt("enable_amount"); //可能存在volume<=0的bug,所以筛选出为正的 if (pbook.volume > 0) { positionbook.Add(pbook); } unpacker.Next(); } } else { MessageManager.GetInstance().Add(MessageType.Error, string.Format("持仓查询失败:{0}", param.securitycode)); } #endregion } catch (Exception ex) { throw ex; } }
public ConnectionCode WithdrawBasket() { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.WithdrawBasket); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.WithdrawBasket); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": { packer.AddStr(userToken); } break; case "batch_no": { packer.AddInt(-1); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("撤销委托实例失败!"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
public ConnectionCode QueryEntrust() { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QuerySecurityEntrust); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.QuerySecurityEntrust); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": { packer.AddStr(userToken); } break; case "batch_no": { packer.AddInt(2317379); } break; case "entrust_no": { packer.AddInt(-1); } break; case "account_code": { packer.AddStr(""); } break; case "asset_no": { packer.AddStr(""); } break; case "combi_no": { packer.AddStr(""); } break; case "stockholder_id": { packer.AddStr(""); } break; case "market_no": { packer.AddStr(""); } break; case "stock_code": { packer.AddStr(""); } break; case "entrust_direction": { packer.AddStr(""); } break; case "entrust_state_list": { packer.AddStr(""); } break; case "extsystem_id": { packer.AddInt(-1); } break; case "third_reff": { packer.AddStr(""); } break; case "position_str": { packer.AddStr(""); } break; case "request_num": { packer.AddInt(1000); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("撤销委托实例失败!"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
public ConnectionCode QueryTradingInstance(string userToken) { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": packer.AddStr(userToken); break; case "account_group_code": packer.AddStr(""); break; case "instance_no": packer.AddInt(0); break; case "instance_type": packer.AddStr(""); break; case "ext_invest_plan_no_list": packer.AddStr(""); break; default: break; } } unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("查询交易实例失败:" + _conn.GetErrorMsg(retCode)); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }
public ConnectionCode QueryInstance(AccountItem account) { FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance1); if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0) { return(ConnectionCode.ErrorNoFunctionCode); } string userToken = LoginManager.Instance.LoginUser.Token; if (string.IsNullOrEmpty(userToken)) { return(ConnectionCode.ErrorLogin); } CT2BizMessage bizMessage = new CT2BizMessage(); //初始化 bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance1); bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET); //业务包 CT2Packer packer = new CT2Packer(2); packer.BeginPack(); foreach (FieldItem item in functionItem.RequestFields) { packer.AddField(item.Name, item.Type, item.Width, item.Scale); } //var accounts = LoginManager.Instance.Accounts; //foreach (var account in accounts) //{ Console.WriteLine("Account: " + account.AccountCode + " " + account.AccountName); foreach (FieldItem item in functionItem.RequestFields) { switch (item.Name) { case "user_token": { packer.AddStr(userToken); } break; case "account_code": { packer.AddStr(account.AccountCode); } break; case "combi_no": { packer.AddStr(""); } break; case "instance_no": { packer.AddStr(""); } break; case "instance_type": { packer.AddStr(""); } break; case "template_no": { packer.AddInt(0); } break; case "long_market_no": { packer.AddStr(""); } break; case "long_report_code": { packer.AddStr(""); } break; case "short_market_no": { packer.AddStr(""); } break; case "short_report_code": { packer.AddStr(""); } break; case "invest_plan_no": { packer.AddStr(""); } break; default: if (item.Type == PackFieldType.IntType) { packer.AddInt(-1); } else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType) { packer.AddStr(item.Name); } else { packer.AddStr(item.Name); } break; } } //} packer.EndPack(); unsafe { bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen()); } int retCode = _t2SDKWrap.SendAsync(bizMessage); packer.Dispose(); bizMessage.Dispose(); if (retCode < 0) { logger.Error("查询交易实例失败!"); return(ConnectionCode.ErrorConn); } return(ConnectionCode.Success); }