public BLLResponse Withdraw(Model.Database.EntrustCommand cmdItem, CallerCallback callerCallback) { BLLResponse bllResponse = new BLLResponse(); UFXBasketWithdrawRequest request = new UFXBasketWithdrawRequest { BatchNo = cmdItem.BatchNo, }; Callbacker callbacker = new Callbacker { Token = new CallerToken { SubmitId = cmdItem.SubmitId, CommandId = cmdItem.CommandId, WaitEvent = new AutoResetEvent(false), Caller = callerCallback, }, DataHandler = WithdrawDataHandler, }; var result = _securityBLL.WithdrawBasket(request, callbacker); 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 = Model.ConnectionCode.Success; bllResponse.Message = "Success Withdraw"; } else { bllResponse.Code = Model.ConnectionCode.FailWithdraw; bllResponse.Message = errorResponse.ErrorMessage; } } else { bllResponse.Code = Model.ConnectionCode.FailTimeoutWithdraw; bllResponse.Message = "Fail to submit the basket withdraw to UFX!"; } } else { bllResponse.Code = Model.ConnectionCode.FailSubmit; bllResponse.Message = "Fail to submit the basket withdraw to UFX!"; } return(bllResponse); }
public List <EntrustFlowItem> QueryToday(CallerCallback callback) { List <EntrustFlowItem> entrustItems = new List <EntrustFlowItem>(); var portfolios = _productBLL.GetAll(); var secuEntrustItems = _querySecurityEntrustBLL.QueryToday(portfolios, _timeOut, callback); if (secuEntrustItems != null && secuEntrustItems.Count > 0) { entrustItems.AddRange(secuEntrustItems); } var futuresEntrustItems = _queryFuturesEntrustBLL.QueryToday(portfolios, _timeOut, callback); if (futuresEntrustItems != null && futuresEntrustItems.Count > 0) { entrustItems.AddRange(futuresEntrustItems); } return(entrustItems); }
//private void CancelRedo(int submitId, List<CancelRedoItem> cancelRedoItems) //{ // //var submitId = cancelRedoItems.Select(p => p.SubmitId).Single(); // //if (submitId <= 0) // //{ // // //TODO: fail to get the submitId // // return; // //} // //set the cancel status // //int ret = _entrustBLL.Cancel(cancelRedoItems); // //Call the UFX to cancel // //Update the EntrustCommand // //_entrustBLL.Submit( // //ret = _entrustBLL.CancelSuccess(cancelRedoItems); //} //TODO: validate before submit private string Submit(int commandId, List <CancelRedoItem> cancelRedoItems, CallerCallback callback) { EntrustCommand cmdItem = new EntrustCommand { CommandId = commandId, Copies = 0, }; string msg = string.Empty; var response = _entrustBLL.SubmitOne(cmdItem, cancelRedoItems, callback); if (!BLLResponse.Success(response)) { int submitId = cancelRedoItems.Select(p => p.SubmitId).Distinct().Single(); string format = ConfigManager.Instance.GetLabelConfig().GetLabelText(msgEntrustCancelResubmitFail); msg = string.Format(format, submitId, response.Message); } return(msg); }
public List <DealFlowItem> QueryToday(CallerCallback callback) { List <DealFlowItem> dealItems = new List <DealFlowItem>(); var portfolios = _productBLL.GetAll(); var dealSecuItems = _querySecurityDealBLL.QueryToday(portfolios, _timeOut, callback); if (dealSecuItems != null && dealSecuItems.Count > 0) { dealItems.AddRange(dealSecuItems); } var dealFuturesItems = _queryFuturesDealBLL.QueryToday(portfolios, _timeOut, callback); if (dealFuturesItems != null && dealFuturesItems.Count > 0) { dealItems.AddRange(dealFuturesItems); } return(dealItems); }
public List <EntrustFlowItem> QueryHistory(List <Portfolio> portfolios, DateTime startDate, DateTime endDate, int timeOut, CallerCallback callback) { List <EntrustFlowItem> entrustItems = new List <EntrustFlowItem>(); int intStart = DateUtil.GetIntDate(startDate); int intEnd = DateUtil.GetIntDate(endDate); foreach (var portfolio in portfolios) { List <UFXQueryFuturesHistEntrustRequest> requests = new List <UFXQueryFuturesHistEntrustRequest>(); UFXQueryFuturesHistEntrustRequest request = new UFXQueryFuturesHistEntrustRequest(); request.StartDate = intStart; request.EndDate = intEnd; request.CombiNo = portfolio.PortfolioNo; requests.Add(request); Callbacker callbacker = new Callbacker { Token = new CallerToken { SubmitId = -2, CommandId = -2, InArgs = portfolio, OutArgs = entrustItems, WaitEvent = new AutoResetEvent(false), Caller = callback, }, DataHandler = QueryDataHandler, }; var result = _securityBLL.QueryFuturesEntrustHistory(requests, 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.ErrorMessage; } } else { bllResponse.Code = ConnectionCode.FailEntrust; bllResponse.Message = "Fail Entrust: Timeout"; } } else { bllResponse.Code = result; bllResponse.Message = "Fail to submit in ufx."; } } return(entrustItems); }
public List <DealFlowItem> QueryToday(List <Portfolio> portfolios, int timeOut, CallerCallback callback) { List <DealFlowItem> dealItems = new List <DealFlowItem>(); foreach (var portfolio in portfolios) { List <UFXQueryDealRequest> requests = new List <UFXQueryDealRequest>(); UFXQueryDealRequest request = new UFXQueryDealRequest(); request.AccountCode = portfolio.FundCode; request.CombiNo = portfolio.PortfolioNo; requests.Add(request); Callbacker callbacker = new Callbacker { Token = new CallerToken { SubmitId = -1, CommandId = -1, InArgs = portfolio, OutArgs = dealItems, WaitEvent = new AutoResetEvent(false), Caller = callback, }, DataHandler = QueryDataHandler, }; var result = _securityBLL.QueryDeal(requests, 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 QueryDeal"; } else { bllResponse.Code = ConnectionCode.FailQueryDeal; bllResponse.Message = "Fail QueryDeal: " + errorResponse.ErrorMessage; } } else { bllResponse.Code = ConnectionCode.FailTimeoutQueryDeal; bllResponse.Message = "Fail QueryDeal: Timeout!"; } } else { bllResponse.Code = result; bllResponse.Message = "Fail to QueryDeal in ufx."; } } return(dealItems); }
public List <CancelSecurityItem> CancelSecuItem(int submitId, int commandId, List <CancelSecurityItem> cancelItems, CallerCallback callerCallback) { var cancelSecuItems = new List <CancelSecurityItem>(); var entrustedSecuItems = new List <EntrustSecurity>(); foreach (var cancelItem in cancelItems) { var entrustSecuItem = ConvertBack(cancelItem); entrustedSecuItems.Add(entrustSecuItem); } int ret = CancelSecurities(submitId, commandId, entrustedSecuItems); if (ret > 0) { cancelSecuItems.AddRange(cancelItems); } return(cancelSecuItems); }
public List <CancelRedoItem> CancelSecuItem(int submitId, int commandId, List <CancelRedoItem> cancelItems, CallerCallback callerCallback) { List <CancelRedoItem> cancelSecuItems = new List <CancelRedoItem>(); var entrustedSecuItems = ConvertToEntrustSecuItems(cancelItems); int ret = CancelSecurities(submitId, commandId, entrustedSecuItems); if (ret > 0) { cancelSecuItems.AddRange(cancelItems); } return(cancelSecuItems); }
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); }
//TODO: async to sumbit the command, it can emit the latency. public BLLResponse SubmitAsync(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callerCallback, EventWaitHandle waitHandle) { 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 = waitHandle, }, DataHandler = EntrustDataHandler, }; var result = _securityBLL.EntrustBasket(ufxRequests, callbacker); return(new BLLResponse(result, "Finish to entrust.")); }
/// <summary> /// Withdraw the entrusted securites. /// NOTE: the entrust_no is necessary. /// </summary> /// <param name="submitId">The entrustsecurity SubmitId.</param> /// <param name="commandId">The tradingcommand CommandId.</param> /// <param name="entrustItems">The entrustsecurity item.</param> /// <param name="callerCallback"></param> /// <returns></returns> public BLLResponse Withdraw(int submitId, int commandId, List <EntrustSecurity> entrustItems, CallerCallback callerCallback) { BLLResponse bllResponse = new BLLResponse(); List <UFXWithdrawRequest> requests = new List <UFXWithdrawRequest>(); foreach (var entrustItem in entrustItems) { UFXWithdrawRequest request = new UFXWithdrawRequest { EntrustNo = entrustItem.EntrustNo, }; requests.Add(request); } Callbacker callbacker = new Callbacker { Token = new CallerToken { SubmitId = submitId, CommandId = commandId, WaitEvent = new AutoResetEvent(false), Caller = callerCallback, }, DataHandler = WithdrawDataHandler, }; var result = _securityBLL.Withdraw(requests, callbacker); 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 = Model.ConnectionCode.Success; bllResponse.Message = "Success Withdraw"; } else { bllResponse.Code = Model.ConnectionCode.FailWithdraw; bllResponse.Message = errorResponse.ErrorMessage; } } else { bllResponse.Code = Model.ConnectionCode.FailTimeoutWithdraw; bllResponse.Message = "Fail to submit the basket withdraw to UFX: Timeout"; } } else { bllResponse.Code = Model.ConnectionCode.FailSubmit; bllResponse.Message = "Fail to submit the basket withdraw to UFX!"; } return(bllResponse); }
public BLLResponse SubmitAsync(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callback, EventWaitHandle waitHandle) { int ret = LocalSubmit(cmdItem, entrustItems); if (ret <= 0) { return(new BLLResponse(ConnectionCode.DBInsertFail, "Fail to submit into database")); } return(_ufxBasketEntrustBLL.SubmitAsync(cmdItem, entrustItems, callback, waitHandle)); }
public BLLResponse SubmitOne(Model.Database.EntrustCommand cmdItem, List <CancelRedoItem> cancelItems, CallerCallback callback) { //TODO: adjust the EntrustAmount List <EntrustSecurity> entrustItems = new List <EntrustSecurity>(); DateTime now = DateTime.Now; //merge the same security in with the same commandId var uniqueSecuCodes = cancelItems.Select(p => p.SecuCode).Distinct().ToList(); foreach (var secuCode in uniqueSecuCodes) { EntrustSecurity item = new EntrustSecurity { CommandId = cmdItem.CommandId, SecuCode = secuCode, EntrustDate = now, }; var originSecuItems = cancelItems.Where(p => p.SecuCode.Equals(secuCode)).ToList(); if (originSecuItems != null && originSecuItems.Count > 0) { item.SecuType = originSecuItems[0].SecuType; item.EntrustPrice = originSecuItems[0].EntrustPrice; item.EntrustDirection = originSecuItems[0].EDirection; item.EntrustPriceType = originSecuItems[0].EEntrustPriceType; item.PriceType = originSecuItems[0].EPriceSetting; item.EntrustAmount = originSecuItems.Sum(o => o.LeftAmount); entrustItems.Add(item); } } return(SubmitSync(cmdItem, entrustItems, callback)); }
public List <UFXHoldingResponse> Query(CallerCallback callback) { List <UFXHoldingResponse> holdingItems = new List <UFXHoldingResponse>(); var portfolios = _productBLL.GetAll(); foreach (var portfolio in portfolios) { var ufxRequests = new List <UFXHoldingRequest>(); var ufxRequest = new UFXHoldingRequest { CombiNo = portfolio.PortfolioNo, }; ufxRequests.Add(ufxRequest); Callbacker callbacker = new Callbacker { Token = new CallerToken { SubmitId = 90000, CommandId = 90001, InArgs = portfolio.PortfolioNo, OutArgs = holdingItems, WaitEvent = new AutoResetEvent(false), Caller = callback, }, DataHandler = DataHandlerCallback, }; var result = _securityBLL.QueryHolding(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 QueryHolding"; } else { bllResponse.Code = ConnectionCode.FailQueryHolding; bllResponse.Message = "Fail QueryHolding: " + errorResponse.ErrorMessage; } } else { bllResponse.Code = ConnectionCode.FailTimeoutQueryHolding; bllResponse.Message = "Fail QueryHolding: Timeout"; } } else { bllResponse.Code = result; bllResponse.Message = "Fail to QueryHolding in ufx."; } } return(holdingItems); }