Ejemplo n.º 1
0
        public BLLResponse Submit(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callerCallback)
        {
            var cmdEntrustItems = entrustItems.Where(p => p.CommandId == cmdItem.CommandId && p.SubmitId == cmdItem.SubmitId).ToList();

            if (cmdEntrustItems == null || cmdEntrustItems.Count == 0)
            {
                return(new BLLResponse(ConnectionCode.EmptyEntrustItem, "Empty EntrustCommandItem or EntrustSecurityItem."));
            }

            UpdateUFXSetting();
            var tradeCommandItem = _tradeCommandBLL.GetTradeCommand(cmdItem.CommandId);
            var portfolio        = LoginManager.Instance.GetPortfolio(tradeCommandItem.PortfolioCode);
            //var stockholder = LoginManager.Instance.GetHolder(tradeCommandItem.

            var ufxRequests = new List <UFXBasketEntrustRequest>();
            var futuItem    = cmdEntrustItems.Find(p => p.SecuType == Model.SecurityInfo.SecurityType.Futures);

            foreach (var secuItem in cmdEntrustItems)
            {
                UFXBasketEntrustRequest request = new UFXBasketEntrustRequest
                {
                    StockCode             = secuItem.SecuCode,
                    EntrustPrice          = secuItem.EntrustPrice,
                    EntrustAmount         = secuItem.EntrustAmount,
                    PriceType             = EntrustRequestHelper.GetEntrustPriceType(secuItem.EntrustPriceType),
                    ExtSystemId           = secuItem.RequestId,
                    ThirdReff             = EntrustRequestHelper.GenerateThirdReff(secuItem.CommandId, secuItem.SubmitId, secuItem.RequestId),
                    LimitEntrustRatio     = _limitEntrustRatio,
                    FutuLimitEntrustRatio = _futuLimitEntrustRatio,
                    OptLimitEntrustRatio  = _optLimitEntrustRatio,
                };

                if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = string.Empty;
                }
                else if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = EntrustRequestHelper.GetFuturesDirection(secuItem.EntrustDirection);
                }

                var secuInfo = SecurityInfoManager.Instance.Get(secuItem.SecuCode, secuItem.SecuType);
                if (secuInfo != null)
                {
                    request.MarketNo = EntrustRequestHelper.GetMarketNo(secuInfo.ExchangeCode);
                }

                if (tradeCommandItem != null)
                {
                    request.AccountCode = tradeCommandItem.AccountCode;
                    request.CombiNo     = tradeCommandItem.PortfolioCode;
                }

                ufxRequests.Add(request);
            }

            Callbacker callbacker = new Callbacker
            {
                Token = new CallerToken
                {
                    SubmitId  = cmdItem.SubmitId,
                    CommandId = cmdItem.CommandId,
                    Caller    = callerCallback,
                    WaitEvent = new AutoResetEvent(false),
                },

                DataHandler = EntrustDataHandler,
            };

            var result = _securityBLL.EntrustBasket(ufxRequests, callbacker);

            BLLResponse bllResponse = new BLLResponse();

            if (result == Model.ConnectionCode.Success)
            {
                if (callbacker.Token.WaitEvent.WaitOne(_timeOut))
                {
                    var errorResponse = callbacker.Token.ErrorResponse as UFXErrorResponse;
                    if (errorResponse != null && T2ErrorHandler.Success(errorResponse.ErrorCode))
                    {
                        bllResponse.Code    = ConnectionCode.Success;
                        bllResponse.Message = "Success Entrust";
                    }
                    else
                    {
                        bllResponse.Code    = ConnectionCode.FailEntrust;
                        bllResponse.Message = "Fail Entrust: " + errorResponse.ErrorCode + " " + errorResponse.ErrorMessage + " " + errorResponse.MessageDetail;
                    }
                }
                else
                {
                    bllResponse.Code    = ConnectionCode.FailTimeoutEntrust;
                    bllResponse.Message = "Timeout to entrust.";
                }
            }
            else
            {
                bllResponse.Code    = result;
                bllResponse.Message = "Fail to submit in ufx.";
            }

            return(bllResponse);
        }
Ejemplo n.º 2
0
        public int Submit(EntrustCommandItem cmdItem, List <EntrustSecurityItem> entrustItems)
        {
            int ret = -1;

            var cmdEntrustItems = entrustItems.Where(p => p.CommandId == cmdItem.CommandId && p.SubmitId == cmdItem.SubmitId).ToList();

            if (cmdEntrustItems == null || cmdEntrustItems.Count == 0)
            {
                return(ret);
            }
            var tradeCommandItem = _tradeCommandBLL.GetTradeCommandItem(cmdItem.CommandId);
            var portfolio        = LoginManager.Instance.GetPortfolio(tradeCommandItem.PortfolioCode);
            //var stockholder = LoginManager.Instance.GetHolder(tradeCommandItem.

            var ufxRequests = new List <UFXBasketEntrustRequest>();
            var futuItem    = cmdEntrustItems.Find(p => p.SecuType == Model.SecurityInfo.SecurityType.Futures);

            foreach (var secuItem in cmdEntrustItems)
            {
                UFXBasketEntrustRequest request = new UFXBasketEntrustRequest
                {
                    StockCode             = secuItem.SecuCode,
                    EntrustPrice          = secuItem.EntrustPrice,
                    EntrustAmount         = secuItem.EntrustAmount,
                    PriceType             = EntrustRequestHelper.GetEntrustPriceType(secuItem.EntrustPriceType),
                    ExtSystemId           = secuItem.RequestId,
                    ThirdReff             = EntrustRequestHelper.GenerateThirdReff(secuItem.CommandId, secuItem.SubmitId, secuItem.RequestId),
                    LimitEntrustRatio     = 100,
                    FutuLimitEntrustRatio = 100,
                    OptLimitEntrustRatio  = 100,
                };

                if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = string.Empty;
                }
                else if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = EntrustRequestHelper.GetFuturesDirection(secuItem.EntrustDirection);
                }

                var secuInfo = SecurityInfoManager.Instance.Get(secuItem.SecuCode, secuItem.SecuType);
                if (secuInfo != null)
                {
                    request.MarketNo = EntrustRequestHelper.GetMarketNo(secuInfo.ExchangeCode);
                }

                if (tradeCommandItem != null)
                {
                    request.AccountCode = tradeCommandItem.FundCode;
                    request.CombiNo     = tradeCommandItem.PortfolioCode;
                }

                ufxRequests.Add(request);
            }

            Callbacker callbacker = new Callbacker
            {
                Token = new CallerToken
                {
                    SubmitId  = cmdItem.SubmitId,
                    CommandId = cmdItem.CommandId,
                    InArgs    = cmdItem,
                    WaitEvent = new AutoResetEvent(false),
                },

                DataHandler = EntrustBasketCallback,
            };

            var result = _securityBLL.EntrustBasket(ufxRequests, callbacker);

            if (result == Model.ConnectionCode.Success)
            {
                callbacker.Token.WaitEvent.WaitOne();
                var errorResponse = callbacker.Token.OutArgs as UFXErrorResponse;
                if (errorResponse != null && T2ErrorHandler.Success(errorResponse.ErrorCode))
                {
                    ret = 1;
                }
            }

            return(ret);
        }