Example #1
0
        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);
        }
Example #2
0
        private void SetRequestField <T>(ref CT2Packer packer, T request, FieldItem fieldItem, Dictionary <string, UFXDataField> dataFieldMap)
        {
            var    dataField = dataFieldMap[fieldItem.Name];
            Type   type      = request.GetType();
            object obj       = type.GetProperty(dataField.Name).GetValue(request);

            if (fieldItem.Name.Equals("entrust_amount"))
            {
                //TODO: 委托数量字段跟文档定义不一样,文档定义是N12(整型),但测试时传入整型出错。
                //恒生确认: 该字段将会被更新为:N16.2
                if (obj != null)
                {
                    packer.AddDouble((double)(int)obj);
                    //packer.AddInt((int)obj);
                }
                else
                {
                    packer.AddDouble(0f);
                    //packer.AddInt(0);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.IntType)
            {
                if (obj != null)
                {
                    packer.AddInt((int)obj);
                }
                else
                {
                    packer.AddInt(-1);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.FloatType)
            {
                if (obj != null)
                {
                    packer.AddDouble((double)obj);
                }
                else
                {
                    packer.AddDouble(0f);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.StringType)
            {
                if (obj != null)
                {
                    packer.AddStr(obj.ToString());
                }
                else
                {
                    packer.AddStr("");
                }
            }
            else
            {
                packer.AddStr("");
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        public ConnectionCode Entrust()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.Entrust);

            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.Entrust);
            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.AddStr("");
                }
                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 "report_seat":
                {
                    packer.AddStr("");
                }
                break;

                case "market_no":
                {
                    packer.AddStr("");
                }
                break;

                case "stock_code":
                {
                    packer.AddStr("");
                }
                break;

                case "entrust_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 "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);
        }