public EntityResponse SetAutomaticOptionExercisingParameters(CustomerAutomaticOptionExercisingInformation information)
        {
            if (string.IsNullOrWhiteSpace(information.CustomerAccountCode))
            {
                return(EntityResponse <List <CustomerAutomaticOptionExercisingInformation> > .Error(
                           ErrorCode.SZKingdomLibraryError,
                           ErrorMessages.SZKingdom_CustomerCodeEmpty));
            }

            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerCode(information.CustomerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(information.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.StockBoard(information.TradeSector));
            arguments.Add(SZKingdomArgument.TradeAccount(information.TradingAccount));

            arguments.Add(SZKingdomArgument.ExercisingQuantity(information.ExercisingQuantity));
            arguments.Add(SZKingdomArgument.AutomaticExerciseControl(information.AutomaticExcerciseControl));
            arguments.Add(SZKingdomArgument.ExercisingStrategyType(information.ExercisingStrategyType));
            arguments.Add(SZKingdomArgument.ExercisingStrategyValue(information.ExercisingStrategyValue));
            arguments.Add(SZKingdomArgument.OptionNumber(information.ContractNumber));
            arguments.Add(SZKingdomArgument.Remark(information.Remark));

            EntityResponse result =
                _marketDataLibrary.ExecuteCommand(SZKingdomRequest.SetAutomaticOptionExercisingParameters, arguments);

            return(result);
        }
Beispiel #2
0
        public EntityResponse <AuthenticationModel> SignIn(SignInModel signInModel)
        {
            if (!ModelState.IsValid)
            {
                List <string> errorMessages = GetValidationErrorMessages();
                EntityResponse <AuthenticationModel> error =
                    EntityResponse <AuthenticationModel> .Error(ErrorCode.AccountVerificationInvalidModel, string.Join(".", errorMessages));

                return(error);
            }

            Role role = _authenticationService.Authenticate(signInModel.Login, signInModel.Password, signInModel.LoginAccountType, signInModel.RememberMe);

            if (role == null)
            {
                EntityResponse <AuthenticationModel> error = EntityResponse <AuthenticationModel> .Error(
                    ErrorCode.AccountVerificationInvalidLoginOrPassword,
                    ClientErrorMessages.AccountController_AccountVerificationInvalidLoginOrPassword);

                return(error);
            }

            AuthenticationModel authenticationModel = GetSecurityModel();

            return(authenticationModel);
        }
Beispiel #3
0
        public EntityResponse <T> ExecuteCommandSingleEntity <T>(SZKingdomRequest request, List <SZKingdomArgument> arguments) where T : new()
        {
            EntityResponse <DataTable> response = ExecuteCommand(request, arguments);

            if (!response.IsSuccess)
            {
                return(EntityResponse <T> .Error(response));
            }

            List <T> results = SZKingdomMappingHelper.ReadEntitiesFromTable <T>(response);

            if (results.Count == 0)
            {
                return(EntityResponse <T> .Error(ErrorCode.SZKingdomLibraryNoRecords,
                                                 string.Format(ErrorMessages.SZKingdom_NoResults, request, string.Join("; ", arguments.Select(p =>
                                                                                                                                              string.Format("{0} = {1}", p.Name, p.Value))))));
            }
            if (results.Count > 1)
            {
                return(EntityResponse <T> .Error(ErrorCode.SZKingdomLibraryError,
                                                 string.Format(ErrorMessages.SZKingdom_SingleResultExpected, request, string.Join("; ", arguments.Select(p =>
                                                                                                                                                         string.Format("{0} = {1}", p.Name, p.Value))))));
            }
            return(results.Single());
        }
Beispiel #4
0
        public EntityResponse <SecurityQuotation> GetSecurityQuotation(string securityCode)
        {
            EntityResponse <List <SecurityInformation> > securityInfoList = _marketDataProvider.GetSecuritiesInformation(null, securityCode);

            if (!securityInfoList.IsSuccess)
            {
                return(EntityResponse <SecurityQuotation> .Error(securityInfoList));
            }

            SecurityInformation securityInfo = securityInfoList.Entity.Single();

            EntityResponse <StockQuoteInfo> stockQuotes = GetStockQuote(securityInfo.SecurityCode);

            if (!stockQuotes.IsSuccess)
            {
                return(EntityResponse <SecurityQuotation> .Error(stockQuotes));
            }

            SecurityQuotation model = Mapper.Map <SecurityQuotation>(securityInfo);

            model = Mapper.Map(stockQuotes.Entity, model);
            //model.HasOptions = _marketDataProvider.GetAllOptionBasicInformation().Any(cache => cache.OptionUnderlyingCode == securityCode && cache.OptionStatus != " ");
            model.HasOptions = isSecurityHasOptions(securityCode);
            return(model);
        }
        public EntityResponse <List <HistoricalFundTransfer> > GetHistoricalTransferFund(string customerAccountCode, string BeginDate, string EndDate, int qryPos, int qryNum)
        {
            var arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));
            arguments.Add(SZKingdomArgument.BeginDate(BeginDate));
            arguments.Add(SZKingdomArgument.EndDate(EndDate));
            arguments.Add(SZKingdomArgument.QueryNumer(qryNum));
            arguments.Add(SZKingdomArgument.QueryPosition(qryPos));


            EntityResponse <List <HistoricalFundTransfer> > results = _marketDataLibrary.ExecuteCommandList <HistoricalFundTransfer>(SZKingdomRequest.HistoricalFundTransfer, arguments);

            if (results.IsSuccess)
            {
                if (results.Entity.Count >= 1)
                {
                    List <HistoricalFundTransfer> resultList = (List <HistoricalFundTransfer>)results.Entity.OrderBy(u => u.OccurTime); // order by OccurTime to show

                    return(resultList);
                }
                return(EntityResponse <List <HistoricalFundTransfer> > .Error(ErrorCode.AuthenticationIncorrectIdentity, string.Format(ErrorMessages.InvalidDateRange, BeginDate, EndDate)));
            }
            return(EntityResponse <List <HistoricalFundTransfer> > .Error(results));
        }
        public EntityResponse <UserLoginInformation> UserLogin(LoginAccountType accountType, string accountId, string password, PasswordUseScope useScope)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.LoginAccountType(accountType));
            arguments.Add(SZKingdomArgument.LoginAccountId(accountId));
            arguments.Add(SZKingdomArgument.PasswordUseScpose(useScope));
            arguments.Add(SZKingdomArgument.AuthenticationData(_marketDataLibrary.EncryptPassword(accountId, password)));
            arguments.Add(SZKingdomArgument.EncryptionKey(accountId));
            arguments.Add(SZKingdomArgument.EncryptionType(EncryptionType.WinEncryption));
            arguments.Add(SZKingdomArgument.AuthenticationType(AuthenticationType.Password));             // password(0) is the only AUTH_TYPE

            EntityResponse <List <UserLoginInformation> > results =
                _marketDataLibrary.ExecuteCommandList <UserLoginInformation>(SZKingdomRequest.UserLogin, arguments);

            if (results.IsSuccess)
            {
                if (results.Entity.Count >= 1)
                {
                    UserLoginInformation result = results.Entity.First();                     //.Single(u => u.StockBoard == StockBoard.SHStockOptions);
                    return(result);
                }
                return(EntityResponse <UserLoginInformation> .Error(ErrorCode.AuthenticationIncorrectIdentity, string.Format(ErrorMessages.SZKingdom_Invalid_Account, accountId)));
            }
            return(EntityResponse <UserLoginInformation> .Error(results));
        }
        public EntityResponse <List <OptionPositionInformation> > GetOptionPositions(OptionPositionsArguments optionPositionsArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (optionPositionsArguments.CustomerCode == null && optionPositionsArguments.CustomerAccountCode == null)
            {
                return(EntityResponse <List <OptionPositionInformation> > .Error(
                           ErrorCode.SZKingdomLibraryError,
                           ErrorMessages.SZKingdom_CustAndAccCodeNull));
            }

            arguments.Add(SZKingdomArgument.CustomerCode(optionPositionsArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(optionPositionsArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.TradeAccount(optionPositionsArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.OptionNumber(optionPositionsArguments.OptionNumber));
            arguments.Add(SZKingdomArgument.TradeUnit(optionPositionsArguments.TradeUnit));
            arguments.Add(SZKingdomArgument.OptionSide(optionPositionsArguments.OptionSide));
            arguments.Add(SZKingdomArgument.OptionCoveredFlag(optionPositionsArguments.OptionCoveredFlag));
            arguments.Add(SZKingdomArgument.QueryPosition(optionPositionsArguments.QueryPosition));

            EntityResponse <List <OptionPositionInformation> > result =
                _marketDataLibrary.ExecuteCommandList <OptionPositionInformation>(SZKingdomRequest.OptionPositions, arguments);

            return(result);
        }
        public EntityResponse <List <CustomerAutomaticOptionExercisingInformation> > GetAutomaticOptionExercisingParameters(string customerCode, string customerAccountCode, string tradeSector, string tradeAccount, List <string> optionNumbers)
        {
            if (string.IsNullOrWhiteSpace(customerAccountCode))
            {
                return(EntityResponse <List <CustomerAutomaticOptionExercisingInformation> > .Error(
                           ErrorCode.SZKingdomLibraryError,
                           ErrorMessages.SZKingdom_CustomerCodeEmpty));
            }
            List <CustomerAutomaticOptionExercisingInformation> result = new List <CustomerAutomaticOptionExercisingInformation>();

            foreach (string optionNumber in optionNumbers)
            {
                var arguments = new List <SZKingdomArgument>();
                arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));

                arguments.Add(SZKingdomArgument.OptionNumber(optionNumber));

                EntityResponse <CustomerAutomaticOptionExercisingInformation> item =
                    _marketDataLibrary.ExecuteCommandSingleEntity <CustomerAutomaticOptionExercisingInformation>(SZKingdomRequest.AutomaticOptionExercisingParameters, arguments);
                if (item.Entity == null)
                {
                    item = EntityResponse <CustomerAutomaticOptionExercisingInformation> .Success(
                        new CustomerAutomaticOptionExercisingInformation()
                    {
                        ContractNumber     = optionNumber,
                        ExercisingQuantity = 0
                    });
                }

                result.Add(item);
            }

            return(result);
        }
Beispiel #9
0
        public EntityResponse <OptionQuoteInfo> GetOption5LevelQuotation(string optionNumber)
        {
            EntityResponse <OptionQuoteInfo> r = GetOptionQuote(optionNumber);

            if (!r.IsSuccess)
            {
                return(EntityResponse <OptionQuoteInfo> .Error(r));
            }
            return(r);
        }
Beispiel #10
0
        public EntityResponse <DateTime> GetUtcMarketCloseTimeForDate(DateTime date)
        {
            EntityResponse <Tuple <DateTime, DateTime> > utcMarketOpenCloseTime = GetUtcMarketOpenCloseTimeForDate(date);

            if (!utcMarketOpenCloseTime.IsSuccess)
            {
                return(EntityResponse <DateTime> .Error(utcMarketOpenCloseTime));
            }
            return(utcMarketOpenCloseTime.Entity.Item2);
        }
Beispiel #11
0
        public EntityResponse <List <T> > ExecuteCommandList <T>(SZKingdomRequest request, List <SZKingdomArgument> arguments) where T : new()
        {
            EntityResponse <DataTable> response = ExecuteCommand(request, arguments);

            if (!response.IsSuccess)
            {
                return(EntityResponse <List <T> > .Error(response));
            }

            List <T> results = SZKingdomMappingHelper.ReadEntitiesFromTable <T>(response);

            return(results);
        }
Beispiel #12
0
        public EntityResponse <List <OptionBasicInformation> > GetOptions(string filter)
        {
            EntityResponse <List <OptionBasicInformation> > response = _marketDataProvider.GetOptionBasicInformation();

            if (!response.IsSuccess)
            {
                return(EntityResponse <List <OptionBasicInformation> > .Error(response));
            }

            EntityResponse <List <OptionBasicInformation> > result = response.Entity.Where(x => x.OptionNumber.Contains(filter)).ToList();

            return(result);
        }
Beispiel #13
0
        public EntityResponse <OptionQuotation> GetOptionQuotation(string optionNo)
        {
            EntityResponse <OptionQuoteInfo> r = GetOptionQuote(optionNo);

            if (!r.IsSuccess)
            {
                return(EntityResponse <OptionQuotation> .Error(r));
            }

            OptionQuotation optionQuotation = ConvertToOptionQuotation(r);

            return(optionQuotation);
        }
Beispiel #14
0
        public EntityResponse <OptionBasicInformation> GetOptionInformation(string optionNo)
        {
            EntityResponse <List <OptionBasicInformation> > r = _marketDataProvider.GetOptionBasicInformation(null, optionNo);

            if (!r.IsSuccess)
            {
                return(EntityResponse <OptionBasicInformation> .Error(r));
            }

            OptionBasicInformation optionInformation = r.Entity.Single();

            return(optionInformation);
        }
Beispiel #15
0
        public EntityResponse <T> GetValueOnly <T>(string[] configDirectories, string valueName)
        {
            EntityResponse <ConfigValue> valueResponse = GetConfigValue(configDirectories, valueName);

            if (!valueResponse.IsSuccess)
            {
                return(EntityResponse <T> .Error(valueResponse));
            }

            T value = valueResponse.Entity.GetValue <T>();

            return(value);
        }
        public static IMappingExpression <TSrc, TDest> IncludeEntityResponse <TSrc, TDest>(this IMappingExpression <TSrc, TDest> expression)
        {
            Mapper.CreateMap <IEntityResponse <TSrc>, EntityResponse <TDest> >().ConvertUsing(response =>
            {
                if (!response.IsSuccess)
                {
                    return(EntityResponse <TDest> .Error(response));
                }

                return(Mapper.Map <TDest>(response.Entity));
            });

            return(expression);
        }
Beispiel #17
0
        private EntityResponse <List <OptionQuotation> > GetOptionQuotesByOptionNumbers(IEnumerable <string> optionNumbers)
        {
            EntityResponse <List <OptionQuoteInfo> > optionQuotes = GetOptionQuotes();

            if (!optionQuotes.IsSuccess)
            {
                return(EntityResponse <List <OptionQuotation> > .Error(optionQuotes));
            }
            IEnumerable <OptionQuoteInfo> entities =
                optionQuotes.Entity.Where(item => optionNumbers.Contains(item.OptionNumber));

            List <OptionQuotation> quotations = entities.Select(ConvertToOptionQuotation).ToList();

            return(quotations);
        }
        public EntityResponse <AccountInformation> GetAccountInformation(string customerCode, string customerAccountCode)
        {
            if (string.IsNullOrWhiteSpace(customerCode) && string.IsNullOrWhiteSpace(customerAccountCode))
            {
                return(EntityResponse <AccountInformation> .Error(
                           ErrorCode.SZKingdomLibraryError,
                           "Customer code and account code cannot be empty at the same time."));
            }

            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerCode(customerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));

            return(_marketDataLibrary.ExecuteCommandSingleEntity <AccountInformation>(SZKingdomRequest.GetAccountInformation, arguments));
        }
        public EntityResponse <OptionOrderMaxQuantityInformation> GetOptionOrderMaxQuantity(OptionOrderMaxQuantityArguments maxQuantityArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerCode(maxQuantityArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(maxQuantityArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.TradeAccount(maxQuantityArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.StockBoard(maxQuantityArguments.StockBoard));
            arguments.Add(SZKingdomArgument.StockBusiness(maxQuantityArguments.StockBusiness));
            arguments.Add(SZKingdomArgument.StockBusinessAction(maxQuantityArguments.StockBusinessAction));

            if (maxQuantityArguments.StockBusiness.In(OptionOrderBusinesses) && string.IsNullOrWhiteSpace(maxQuantityArguments.OptionNumber))
            {
                EntityResponse <OptionOrderMaxQuantityInformation> entityResponse = EntityResponse <OptionOrderMaxQuantityInformation> .Error(
                    ErrorCode.SZKingdomLibraryError,
                    ErrorMessages.SZKingdom_OptionNumberCanNotBeEmpty);

                return(entityResponse);
            }
            if (maxQuantityArguments.StockBusiness.In(StockOrderBusinesses) && string.IsNullOrWhiteSpace(maxQuantityArguments.SecurityCode))
            {
                EntityResponse <OptionOrderMaxQuantityInformation> entityResponse = EntityResponse <OptionOrderMaxQuantityInformation> .Error(
                    ErrorCode.SZKingdomLibraryError,
                    ErrorMessages.SZKingdom_StockCanNotBeEmpty);

                return(entityResponse);
            }
            arguments.Add(SZKingdomArgument.OptionNumber(maxQuantityArguments.OptionNumber));
            arguments.Add(SZKingdomArgument.SecurityCode(maxQuantityArguments.SecurityCode));


            if (maxQuantityArguments.StockBusiness.In(PriceNecessaryBusinesses) && maxQuantityArguments.OrderPrice == null)
            {
                EntityResponse <OptionOrderMaxQuantityInformation> entityResponse = EntityResponse <OptionOrderMaxQuantityInformation>
                                                                                    .Error(ErrorCode.SZKingdomLibraryError, ErrorMessages.SZKingdom_OrderPriceCanNotBeEmpty);

                return(entityResponse);
            }
            arguments.Add(SZKingdomArgument.OrderPrice(maxQuantityArguments.OrderPrice));


            EntityResponse <OptionOrderMaxQuantityInformation> result =
                _marketDataLibrary.ExecuteCommandSingleEntity <OptionOrderMaxQuantityInformation>(SZKingdomRequest.OptionOrderMaxQuantity, arguments);

            return(result);
        }
        public EntityResponse <OptionOrderInformation> SubmitOptionOrder(OptionOrderArguments orderArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerAccountCode(orderArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.StockBoard(orderArguments.StockBoard));
            arguments.Add(SZKingdomArgument.TradeAccount(orderArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.OptionNumber(orderArguments.OptionNumber));
            arguments.Add(SZKingdomArgument.SecurityCode(orderArguments.SecurityCode));
            arguments.Add(SZKingdomArgument.OrderQuantity(orderArguments.OrderQuantity));
            arguments.Add(SZKingdomArgument.StockBusiness(orderArguments.StockBusiness));
            arguments.Add(SZKingdomArgument.StockBusinessAction(orderArguments.StockBusinessAction));
            arguments.Add(SZKingdomArgument.SecurityLevel(orderArguments.SecurityLevel));
            arguments.Add(SZKingdomArgument.OrderPrice(orderArguments.OrderPrice));
            arguments.Add(SZKingdomArgument.CustomerCode(orderArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.TradeUnit(orderArguments.TradeUnit));
            arguments.Add(SZKingdomArgument.OrderBatchSerialNo(orderArguments.OrderBatchSerialNo));
            arguments.Add(SZKingdomArgument.ClientInfo(orderArguments.ClientInfo));
            arguments.Add(SZKingdomArgument.InternalOrganization(orderArguments.InternalOrganization));

            if (orderArguments.SecurityLevel != SecurityLevel.NoSecurity)
            {
                if (!string.IsNullOrWhiteSpace(orderArguments.SecurityInfo))
                {
                    arguments.Add(SZKingdomArgument.SecurityInfo(orderArguments.SecurityInfo));
                }
                else if (!string.IsNullOrWhiteSpace(orderArguments.Password))
                {
                    orderArguments.SecurityInfo = _marketDataLibrary.EncryptPassword(orderArguments.CustomerAccountCode, orderArguments.Password);
                }
                else
                {
                    EntityResponse <OptionOrderInformation> entityResponse = EntityResponse <OptionOrderInformation>
                                                                             .Error(ErrorCode.SZKingdomLibraryError, "No security info");

                    return(entityResponse);
                }
            }

            EntityResponse <OptionOrderInformation> result =
                _marketDataLibrary.ExecuteCommandSingleEntity <OptionOrderInformation>(SZKingdomRequest.OptionOrder, arguments);

            return(result);
        }
        public EntityResponse <RiskLevelInformation> GetAccountRiskLevelInformation(string customerAccountCode, Currency currency)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (string.IsNullOrWhiteSpace(customerAccountCode))
            {
                return(EntityResponse <RiskLevelInformation> .Error(
                           ErrorCode.SZKingdomLibraryError,
                           ErrorMessages.SZKingdom_CustomerCodeEmpty));
            }

            arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));
            arguments.Add(SZKingdomArgument.Currency(currency));

            EntityResponse <RiskLevelInformation> result =
                _marketDataLibrary.ExecuteCommandSingleEntity <RiskLevelInformation>(SZKingdomRequest.AccountRiskLevel, arguments);

            return(result);
        }
        public EntityResponse <List <FundInformation> > GetFundInformation(string customertCode = null, string customerAccountCode = null, Currency currency = null)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (string.IsNullOrWhiteSpace(customertCode) && string.IsNullOrWhiteSpace(customerAccountCode))
            {
                return(EntityResponse <List <FundInformation> > .Error(ErrorCode.SZKingdomLibraryError,
                                                                       string.Format(ErrorMessages.SZKingdom_EmptyAccountIds)));
            }

            arguments.Add(SZKingdomArgument.CustomerCode(customertCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));
            arguments.Add(SZKingdomArgument.Currency(currency));
            arguments.Add(SZKingdomArgument.ValueFlag("15"));

            EntityResponse <List <FundInformation> > result =
                _marketDataLibrary.ExecuteCommandList <FundInformation>(SZKingdomRequest.FundInformation, arguments);

            return(result);
        }
        public BaseResponse CancelOptionOrder(OptionOrderCancellationArguments cancellationArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerAccountCode(cancellationArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.StockBoard(cancellationArguments.StockBoard.ToString()));
            arguments.Add(SZKingdomArgument.InternalOrganization(cancellationArguments.InternalOrganization));
            arguments.Add(SZKingdomArgument.OrderId(cancellationArguments.OrderId));
            arguments.Add(SZKingdomArgument.OrderBatchSerialNo(cancellationArguments.OrderBatchSerialNo));

            if (string.IsNullOrWhiteSpace(cancellationArguments.OrderId) && cancellationArguments.OrderBatchSerialNo == null)
            {
                EntityResponse <OptionOrderCancellationInformation> entityResponse = EntityResponse <OptionOrderCancellationInformation>
                                                                                     .Error(ErrorCode.SZKingdomLibraryError, "Order Id and Order BSN cannot be empty at the same time");

                return(entityResponse);
            }

            BaseResponse result = _marketDataLibrary.ExecuteCommand(SZKingdomRequest.CancelOptionOrder, arguments);

            return(result);
        }
        public EntityResponse <List <OptionableStockPositionInformation> > GetOptionalStockPositions(string customerCode, string customerAccountCode,
                                                                                                     string tradeAccount, string tradeUnit = null,
                                                                                                     string queryPosition = null)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (string.IsNullOrWhiteSpace(customerCode) && string.IsNullOrWhiteSpace(customerAccountCode))
            {
                return(EntityResponse <List <OptionableStockPositionInformation> > .Error(ErrorCode.SZKingdomLibraryError, "Customer code and Account code cannot be empty at the same time."));
            }

            arguments.Add(SZKingdomArgument.CustomerCode(customerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(customerAccountCode));
            arguments.Add(SZKingdomArgument.TradeAccount(tradeAccount));
            arguments.Add(SZKingdomArgument.TradeUnit(tradeUnit));
            arguments.Add(SZKingdomArgument.QueryPosition(queryPosition));

            EntityResponse <List <OptionableStockPositionInformation> > result =
                _marketDataLibrary.ExecuteCommandList <OptionableStockPositionInformation>(SZKingdomRequest.OptionableStockPositions, arguments);

            return(result);
        }
        public EntityResponse <List <HistoricalOptionTradeInformation> > GetHistoricalOptionTrades(HistoricalOptionOrdersArguments historicalOrderArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (historicalOrderArguments.CustomerCode == null && historicalOrderArguments.CustomerAccountCode == null)
            {
                EntityResponse <List <HistoricalOptionTradeInformation> > entityResponse = EntityResponse <List <HistoricalOptionTradeInformation> >
                                                                                           .Error(ErrorCode.SZKingdomLibraryError, SameCodesErrorMessage);

                return(entityResponse);
            }

            arguments.Add(SZKingdomArgument.CustomerCode(historicalOrderArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(historicalOrderArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.StockBoard(historicalOrderArguments.StockBoard));
            arguments.Add(SZKingdomArgument.TradeAccount(historicalOrderArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.OptionNumber(historicalOrderArguments.OptionNumber));
            arguments.Add(SZKingdomArgument.OptionUnderlyingCode(historicalOrderArguments.OptionUnderlyingCode));
            arguments.Add(SZKingdomArgument.OrderId(historicalOrderArguments.OrderId));
            arguments.Add(SZKingdomArgument.OrderBatchSerialNo(historicalOrderArguments.OrderBatchSerialNo));
            arguments.Add(SZKingdomArgument.BeginDate(historicalOrderArguments.BeginDate.ToString(SZKingdomMappingHelper.SZKingdomDateFormat)));
            arguments.Add(SZKingdomArgument.EndDate(historicalOrderArguments.EndDate.ToString(SZKingdomMappingHelper.SZKingdomDateFormat)));
            arguments.Add(SZKingdomArgument.PageNumber(historicalOrderArguments.PageNumber));
            arguments.Add(SZKingdomArgument.PageRecordCount(historicalOrderArguments.PageRecordCount));

            EntityResponse <List <HistoricalOptionTradeInformation> > result = _marketDataLibrary
                                                                               .ExecuteCommandList <HistoricalOptionTradeInformation>(SZKingdomRequest.HistoricalOptionTrades, arguments);

            return(result);
        }
        public EntityResponse <List <LockableUnderlyingInformation> > GetLockableUnderlyings(StockBoard stockBoard, string tradeAccount,
                                                                                             string customerCode = null, string accountCode = null)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (customerCode == null && accountCode == null)
            {
                EntityResponse <List <LockableUnderlyingInformation> > entityReponse = EntityResponse <List <LockableUnderlyingInformation> >
                                                                                       .Error(ErrorCode.SZKingdomLibraryError, SameCodesErrorMessage);

                return(entityReponse);
            }

            arguments.Add(SZKingdomArgument.CustomerCode(customerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(accountCode));
            arguments.Add(SZKingdomArgument.StockBoard(stockBoard));
            arguments.Add(SZKingdomArgument.TradeAccount(tradeAccount));

            EntityResponse <List <LockableUnderlyingInformation> > result = _marketDataLibrary
                                                                            .ExecuteCommandList <LockableUnderlyingInformation>(SZKingdomRequest.LockableUnderlyings, arguments);

            return(result);
        }
        public EntityResponse <List <IntradayOptionOrderBasicInformation> > GetCancellableOrders(IntradayOptionOrderArguments intradayOrderArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            if (intradayOrderArguments.CustomerCode == null && intradayOrderArguments.CustomerAccountCode == null)
            {
                EntityResponse <List <IntradayOptionOrderBasicInformation> > entityRespose = EntityResponse <List <IntradayOptionOrderBasicInformation> >
                                                                                             .Error(ErrorCode.SZKingdomLibraryError, SameCodesErrorMessage);

                return(entityRespose);
            }

            arguments.Add(SZKingdomArgument.CustomerCode(intradayOrderArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.CustomerAccountCode(intradayOrderArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.StockBoard(intradayOrderArguments.StockBoard));
            arguments.Add(SZKingdomArgument.TradeAccount(intradayOrderArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.OptionNumber(intradayOrderArguments.OptionNumber));
            arguments.Add(SZKingdomArgument.OptionUnderlyingCode(intradayOrderArguments.OptionUnderlyingCode));
            arguments.Add(SZKingdomArgument.OrderId(intradayOrderArguments.OrderId));
            arguments.Add(SZKingdomArgument.QueryPosition(intradayOrderArguments.QueryPosition));

            EntityResponse <List <IntradayOptionOrderBasicInformation> > result = _marketDataLibrary
                                                                                  .ExecuteCommandList <IntradayOptionOrderBasicInformation>(SZKingdomRequest.CancelableOptionOrders, arguments);

            return(result);
        }
        public EntityResponse <UnderlyingSecurityLockUnlockInformation> LockUnlockUnderlyingSecurity(
            UnderlyingSecurityLockUnlockArguments lockUnlockArguments)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.CustomerAccountCode(lockUnlockArguments.CustomerAccountCode));
            arguments.Add(SZKingdomArgument.TradeAccount(lockUnlockArguments.TradeAccount));
            arguments.Add(SZKingdomArgument.StockBoard(lockUnlockArguments.StockBoard));
            arguments.Add(SZKingdomArgument.SecurityCode(lockUnlockArguments.SecurityCode));
            arguments.Add(SZKingdomArgument.OrderQuantity(lockUnlockArguments.OrderQuantity));
            arguments.Add(SZKingdomArgument.StockBusiness(lockUnlockArguments.StockBusiness));
            arguments.Add(SZKingdomArgument.StockBusinessAction(StockBusinessAction.OrderDeclaration));
            arguments.Add(SZKingdomArgument.SecurityLevel(lockUnlockArguments.SecurityLevel));
            arguments.Add(SZKingdomArgument.InternalOrganization(lockUnlockArguments.InternalOrganization));

            if (lockUnlockArguments.SecurityLevel != SecurityLevel.NoSecurity)
            {
                lockUnlockArguments.SecurityInfo = _marketDataLibrary.EncryptPassword(lockUnlockArguments.CustomerAccountCode, lockUnlockArguments.Password);

                if (!string.IsNullOrWhiteSpace(lockUnlockArguments.SecurityInfo))
                {
                    arguments.Add(SZKingdomArgument.SecurityInfo(lockUnlockArguments.SecurityInfo));
                }
                else
                {
                    EntityResponse <UnderlyingSecurityLockUnlockInformation> entityResponse = EntityResponse <UnderlyingSecurityLockUnlockInformation>
                                                                                              .Error(ErrorCode.SZKingdomLibraryError, "No security info");

                    return(entityResponse);
                }
            }

            arguments.Add(SZKingdomArgument.CustomerCode(lockUnlockArguments.CustomerCode));
            arguments.Add(SZKingdomArgument.TradeUnit(lockUnlockArguments.TradeUnit));
            arguments.Add(SZKingdomArgument.OrderBatchSerialNo(lockUnlockArguments.OrderBatchSerialNo));
            arguments.Add(SZKingdomArgument.ClientInfo(lockUnlockArguments.ClientInfo));

            EntityResponse <UnderlyingSecurityLockUnlockInformation> result = _marketDataLibrary
                                                                              .ExecuteCommandSingleEntity <UnderlyingSecurityLockUnlockInformation>(SZKingdomRequest.UnderlyingSecurityLockUnlock, arguments);

            return(result);
        }
Beispiel #29
0
        public EntityResponse <OptionChain> GetOptionChain(string underlying)
        {
            EntityResponse <StockQuoteInfo> stockQuote = GetStockQuote(underlying);

            if (!stockQuote.IsSuccess)
            {
                return(EntityResponse <OptionChain> .Error(stockQuote));
            }

            EntityResponse <List <OptionBasicInformation> > optionBasicInformationResponse = _marketDataProvider.GetOptionBasicInformation(underlying);

            if (!optionBasicInformationResponse.IsSuccess)
            {
                return(EntityResponse <OptionChain> .Error(optionBasicInformationResponse));
            }

            double interestRate = _riskFreeRateProvider.GetRiskFreeRate();

            decimal spotPrice = stockQuote.Entity.LastPrice == 0
                ? (stockQuote.Entity.PreviousClose ?? 0)
                : (stockQuote.Entity.LastPrice ?? 0);

            //filtering OptionBasicInformation and get all not expired
            DateTime nowInmarketTimeZone = _marketWorkTimeService.NowInMarketTimeZone.Date;
            List <OptionBasicInformation> optionsBasicInformation = optionBasicInformationResponse.Entity
                                                                    .Where(item => item.ExpireDate.Date >= nowInmarketTimeZone.Date)
                                                                    .ToList();

            List <string> optionNumbers = optionsBasicInformation.Select(item => item.OptionNumber).Distinct().ToList();

            EntityResponse <List <OptionQuotation> > optionQuotesResponse = GetOptionQuotesByOptionNumbers(optionNumbers);

            if (!optionQuotesResponse.IsSuccess)
            {
                return(EntityResponse <OptionChain> .Error(optionQuotesResponse));
            }

            // To filter the optionBasicInformation
            Dictionary <string, OptionQuotation> optionQuotesDict = new Dictionary <string, OptionQuotation>();

            foreach (OptionQuotation itemOptionQuotation in optionQuotesResponse.Entity)
            {
                optionQuotesDict.Add(itemOptionQuotation.OptionNumber, itemOptionQuotation);
            }

            if (!MemoryCache.IsOptionChainCacheExpired(underlying))
            {
                // memory cache working.
                MemoryCache.OptionChainCache[underlying].OptionChains.UpdateQuotation((double)spotPrice, interestRate, optionQuotesResponse.Entity);
                return(MemoryCache.OptionChainCache[underlying].OptionChains);
            }

            // todo: 4 requests here. Big problem with performance

            SecurityInformationCache securityInfo = _marketDataProvider
                                                    .GetAllSecuritiesInformation().FirstOrDefault(s => s.SecurityCode == underlying);

            if (securityInfo == null)
            {
                return(ErrorCode.SZKingdomLibraryNoRecords);
            }

            HashSet <OptionPair> chains = new HashSet <OptionPair>();

            foreach (OptionBasicInformation optionBasicInformation in optionsBasicInformation)
            {
                // Filter the option if the quotation of the specified options cannot be found
                if (!optionQuotesDict.ContainsKey(optionBasicInformation.OptionNumber))
                {
                    continue;
                }

                DateAndNumberOfDaysUntil expiry = _marketWorkTimeService
                                                  .GetNumberOfDaysLeftUntilExpiry(optionBasicInformation.ExpireDate);

                OptionPair pair = new OptionPair
                {
                    Expiry            = expiry,
                    StrikePrice       = (double)optionBasicInformation.StrikePrice,
                    PremiumMultiplier = optionBasicInformation.OptionUnit,
                    SecurityCode      = optionBasicInformation.OptionUnderlyingCode,
                    SecurityName      = optionBasicInformation.OptionUnderlyingName
                };

                if (!chains.Contains(pair))
                {
                    chains.Add(pair);
                }
                else
                {
                    pair = chains.Single(c => c.Equals(pair));
                }

                Option op = new Option(pair, optionBasicInformation.OptionNumber, optionBasicInformation.OptionCode)
                {
                    Name          = optionBasicInformation.OptionName,
                    OptionName    = optionBasicInformation.OptionName,
                    OpenInterest  = optionBasicInformation.UncoveredPositionQuantity,
                    SecurityCode  = optionBasicInformation.OptionUnderlyingCode,
                    PreviousClose = (double)optionBasicInformation.PreviousClosingPrice,
                    Greeks        = new Greeks()
                };
                if (optionBasicInformation.OptionType == OptionType.Call)
                {
                    op.LegType      = LegType.Call;
                    pair.CallOption = op;
                }
                else
                {
                    op.LegType     = LegType.Put;
                    pair.PutOption = op;
                }
            }

            OptionChain chain = new OptionChain(chains, (double)spotPrice, interestRate, optionQuotesResponse.Entity);

            MemoryCache.AddOrUpdateOptionChainCache(underlying, chain);
            return(chain);
        }
Beispiel #30
0
        private EntityResponse <DataTable> ExecuteInternal(SZKingdomRequest function, List <SZKingdomArgument> inputParamenters)
        {
            SetFixedParameters(function, inputParamenters);
            EnsureConnected();
            _wrapper.BeginWrite();
            foreach (SZKingdomArgument input in inputParamenters)
            {
                if (!string.IsNullOrWhiteSpace(input.Value))
                {
                    _wrapper.SetValue(input.Name, input.Value);
                }
            }

            _wrapper.CallProgramAndCommit(function.InternalValue);

            // Get the first ResultSet, refer to 2.1.3 Response package
            _wrapper.RsOpen();

            // There is only one row in the first response status ResultSet
            _wrapper.RsFetchRow();             //skip first row with responseStatus

            int    messageCode = int.Parse(_wrapper.RsGetCol("MSG_CODE"));
            string messageText = _wrapper.RsGetCol("MSG_TEXT");

            // MSG_CODE: 0 means successful, others are error code.
            if (messageCode != 0)
            {
                _wrapper.RsClose();
                if (messageCode == 100)
                {
                    return(EntityResponse <DataTable> .Success(new DataTable()));
                }
                return(EntityResponse <DataTable> .Error(ErrorCode.SZKingdomLibraryError,
                                                         string.Format(messageText)));

                //string.Format("KCBP error code: {0}. Message: {1}.", messageCode, messageText));
            }

            DataTable tableResult = new DataTable();

            // Get the second ResultSet, which is the output of the request.
            if (_wrapper.RsMore())
            {
                // Get number of rows.
                int numberOfrows    = _wrapper.RsGetRowNum() - 1;
                int numberOfColumns = _wrapper.RsGetColNum();

                for (int i = 1; i <= numberOfColumns; i++)
                {
                    // Get column name by column index, column index starts from 1.
                    string columnName = _wrapper.RsGetColName(i);
                    tableResult.Columns.Add(columnName.Trim());
                }

                // Get results row by row
                for (int i = 0; i < numberOfrows; i++)
                {
                    if (!_wrapper.RsFetchRow())
                    {
                        continue;
                    }

                    object[] items = new object[numberOfColumns];
                    for (int j = 1; j <= numberOfColumns; j++)
                    {
                        items[j - 1] = _wrapper.RsGetCol(j);
                    }
                    tableResult.Rows.Add(items);
                }
            }
            _wrapper.RsClose();
            return(tableResult);
        }