Exemplo n.º 1
0
        public async Task <ResponseModel> Post(PinSecurityChangeModel data)
        {
            if (string.IsNullOrEmpty(data.Pin))
            {
                return(ResponseModel.CreateInvalidFieldError("pin", Phrases.FieldShouldNotBeEmpty));
            }

            if (!data.Pin.IsOnlyDigits())
            {
                return(ResponseModel.CreateInvalidFieldError("pin", Phrases.PinShouldContainsDigitsOnly));
            }

            if (data.Pin.Length < 4)
            {
                return(ResponseModel.CreateInvalidFieldError("pin", Phrases.MinLengthIs4Digits));
            }

            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel <PinSecurityCheckResultModel> .CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.NotAuthenticated));
            }
            await _puPinSecurityRepository.SaveAsync(clientId, data.Pin);

            return(ResponseModel.CreateOk());
        }
Exemplo n.º 2
0
        public async Task <ResponseModel <AuthenticateResponseModel> > Post(AuthenticateModel model)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                return(ResponseModel <AuthenticateResponseModel> .CreateInvalidFieldError("email", Phrases.FieldShouldNotBeEmpty));
            }

            if (!model.Email.IsValidEmail())
            {
                return(ResponseModel <AuthenticateResponseModel> .CreateInvalidFieldError("email", Phrases.InvalidEmailFormat));
            }

            if (string.IsNullOrEmpty(model.Password))
            {
                return(ResponseModel <AuthenticateResponseModel> .CreateInvalidFieldError("passowrd", Phrases.FieldShouldNotBeEmpty));
            }

            var client = await _clientAccountsRepository.AuthenticateAsync(model.Email, model.Password);

            if (client == null)
            {
                return(ResponseModel <AuthenticateResponseModel> .CreateInvalidFieldError("passowrd", Phrases.InvalidUsernameOrPassword));
            }

            this.AuthenticateUserViaOwin(client);

            return(ResponseModel <AuthenticateResponseModel> .CreateOk(new AuthenticateResponseModel
            {
                KycStatus = (await _kycRepository.GetKycStatusAsync(client.Id)).ToString(),
                PinIsEntered = await _pinSecurityRepository.IsPinEntered(client.Id)
            }));
        }
Exemplo n.º 3
0
        public async Task <ResponseModel> Post()
        {
            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel <KycModelStatusResponseModel> .CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.OperationCanNotBePerformed));
            }

            var status = await _kycRepository.GetKycStatusAsync(clientId);

            if (status == KycStatus.NeedToFillData)
            {
                await _kycRepository.SetStatusAsync(clientId, KycStatus.Pending);

                return(ResponseModel.CreateOk());
            }

            if (status == KycStatus.Pending)
            {
                return(ResponseModel.CreateOk());
            }

            return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InconsistentData, Phrases.OperationCanNotBePerformed));
        }
Exemplo n.º 4
0
 public ResponseModel <RestrictedCountriesResponseModel> Get()
 {
     return(ResponseModel <RestrictedCountriesResponseModel>
            .CreateOk(new RestrictedCountriesResponseModel
     {
         RestrictedCountires = Countries()
     }));
 }
Exemplo n.º 5
0
        public async Task <ResponseModel> Post(KycDocumentsModel model)
        {
            if (string.IsNullOrEmpty(model.Type))
            {
                return(ResponseModel.CreateInvalidFieldError("type", Phrases.FieldShouldNotBeEmpty));
            }


            if (!KycDocumentTypes.HasDocumentType(model.Type))
            {
                return(ResponseModel.CreateInvalidFieldError("type", Phrases.InvalidDocumentType));
            }

            if (string.IsNullOrEmpty(model.Ext))
            {
                return(ResponseModel.CreateInvalidFieldError("ext", Phrases.FieldShouldNotBeEmpty));
            }

            if (string.IsNullOrEmpty(model.Data))
            {
                return(ResponseModel.CreateInvalidFieldError("data", Phrases.FieldShouldNotBeEmpty));
            }


            byte[] data;
            try
            {
                data = Convert.FromBase64String(model.Data);
            }
            catch (Exception)
            {
                return(ResponseModel.CreateInvalidFieldError("data", "Base64 format expected"));
            }

            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.NotAuthenticated));
            }

            var status = await _kycRepository.GetKycStatusAsync(clientId);

            if (status != KycStatus.NeedToFillData)
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InconsistentData, Phrases.OperationCanNotBePerformed));
            }


            var fileName = "myFile" + model.Ext.AddFirstSymbolIfNotExists('.');
            var mimeType = MimeMapping.GetMimeMapping(fileName);

            await
            _srvKycDocumentsManager.UploadDocument(clientId, model.Type, fileName, mimeType, data);

            return(ResponseModel.CreateOk());
        }
Exemplo n.º 6
0
        public async Task <ResponseModel <IsPinSecurityEnabledResultModel> > Get()
        {
            var clientId = this.GetClientId();

            var isEnabled = await _pinSecurityRepository.IsPinEntered(clientId);

            return
                (ResponseModel <IsPinSecurityEnabledResultModel> .CreateOk(new IsPinSecurityEnabledResultModel
            {
                IsEnabled = isEnabled
            }));
        }
Exemplo n.º 7
0
        private ResponseModel <T> ConvertToApiModel <T>(MeStatusCodes status, T result)
        {
            if (status == MeStatusCodes.Ok)
            {
                return(ResponseModel <T> .CreateOk(result));
            }

            var response = ResponseModel <T> .CreateFail(ErrorCodeType.Rejected, status.ToString());

            response.Result = result;
            return(response);
        }
Exemplo n.º 8
0
        public async Task <ResponseModel <InitChartDataClientResponse> > InitChartFiltered([FromBody] InitChartDataClientRequest request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitChartDataClientResponse>());
            }

            var initGraph = await _rpcFacade.InitGraph(clientId, request?.AssetIds);

            return(ResponseModel <InitChartDataClientResponse> .CreateOk(initGraph));
        }
Exemplo n.º 9
0
        public async Task <ResponseModel <InitChartDataClientResponse> > InitChart()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitChartDataClientResponse>());
            }

            var initGraph = await _rpcFacade.InitGraph(clientId);

            return(ResponseModel <InitChartDataClientResponse> .CreateOk(initGraph));
        }
Exemplo n.º 10
0
        public async Task <ResponseModel <InitAccountInstrumentsLiveDemoClientResponse> > AccountInstruments()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitAccountInstrumentsLiveDemoClientResponse>());
            }

            var initAccountInstruments = await _rpcFacade.AccountInstruments(clientId);

            return(ResponseModel <InitAccountInstrumentsLiveDemoClientResponse> .CreateOk(initAccountInstruments));
        }
Exemplo n.º 11
0
        public async Task <ResponseModel <InitDataLiveDemoClientResponse> > InitData()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitDataLiveDemoClientResponse>());
            }

            var initData = await _rpcFacade.InitData(clientId);

            return(ResponseModel <InitDataLiveDemoClientResponse> .CreateOk(initData));
        }
Exemplo n.º 12
0
        public async Task <ResponseModel <Dictionary <string, BidAskClientContract> > > InitPricesWithFilter([FromBody] InitPricesFilteredRequest request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <Dictionary <string, BidAskClientContract> >());
            }

            var initPrices = await _rpcFacade.InitPrices(clientId, request?.AssetIds);

            return(ResponseModel <Dictionary <string, BidAskClientContract> > .CreateOk(initPrices));
        }
Exemplo n.º 13
0
        public async Task <ResponseModel <string> > GetNotificationId()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <string>());
            }

            var notificationId = await _clientNotificationService.GetNotificationId(clientId);

            return(ResponseModel <string> .CreateOk(notificationId));
        }
Exemplo n.º 14
0
        public async Task <ResponseModel <OrderClientContract[]> > GetAccountOpenPositions(string accountId)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <OrderClientContract[]>());
            }

            var result = await _rpcFacade.GetAccountOpenPositions(clientId, accountId);

            return(ResponseModel <OrderClientContract[]> .CreateOk(result));
        }
Exemplo n.º 15
0
        public async Task <ResponseModel <AccountHistoryItemClient[]> > GetAccountHistoryTimeline([FromQuery] AccountHistoryFiltersClientRequest request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <AccountHistoryItemClient[]>());
            }

            var history = await _rpcFacade.GetAccountHistoryTimeline(clientId, request);

            return(ResponseModel <AccountHistoryItemClient[]> .CreateOk(history));
        }
Exemplo n.º 16
0
        public async Task <ResponseModel <ClientOrdersLiveDemoClientResponse> > GetOpenPositions()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <ClientOrdersLiveDemoClientResponse>());
            }

            var result = await _rpcFacade.GetOpenPositions(clientId);

            return(ResponseModel <ClientOrdersLiveDemoClientResponse> .CreateOk(result));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Try to execute the refit api client task and return the possible error on failure.
 /// </summary>
 /// <param name="task">The refit task to execute.</param>
 /// <returns>The http status code and possible error</returns>
 public static async Task <RestClientResult> TryExecute(this Task task)
 {
     try
     {
         await task;
         return(new RestClientResult(HttpStatusCode.OK, ResponseModel.CreateOk()));
     }
     catch (ApiException apiException)
     {
         var response = HandleApiException(apiException, ResponseModel.CreateFail);
         return(new RestClientResult(apiException.StatusCode, response));
     }
 }
Exemplo n.º 18
0
        public async Task <ResponseModel <Dictionary <string, BidAskClientContract> > > InitPrices()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <Dictionary <string, BidAskClientContract> >());
            }


            var initPrices = await _rpcFacade.InitPrices(clientId);

            return(ResponseModel <Dictionary <string, BidAskClientContract> > .CreateOk(initPrices));
        }
Exemplo n.º 19
0
        public async Task <ResponseModel> Post(AccountRegistrationModel model)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.FieldShouldNotBeEmpty));
            }

            if (!model.Email.IsValidEmail())
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.InvalidEmailFormat));
            }

            if (string.IsNullOrEmpty(model.FirstName))
            {
                return(ResponseModel.CreateInvalidFieldError("firstname", Phrases.FieldShouldNotBeEmpty));
            }

            if (string.IsNullOrEmpty(model.LastName))
            {
                return(ResponseModel.CreateInvalidFieldError("lastname", Phrases.FieldShouldNotBeEmpty));
            }

            if (string.IsNullOrEmpty(model.ContactPhone))
            {
                return(ResponseModel.CreateInvalidFieldError("contactphone", Phrases.FieldShouldNotBeEmpty));
            }

            if (await _clientAccountsRepository.IsTraderWithEmailExistsAsync(model.Email))
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.ClientWithEmailIsRegistered));
            }

            if (string.IsNullOrEmpty(model.Password))
            {
                return(ResponseModel.CreateInvalidFieldError("passowrd", Phrases.FieldShouldNotBeEmpty));
            }

            try
            {
                var user = await _srvClientManager.RegisterClientAsync(model.Email, model.FirstName, model.LastName, model.ContactPhone, model.Password);

                this.AuthenticateUserViaOwin(user);
                return(ResponseModel.CreateOk());
            }
            catch (Exception ex)
            {
                return(ResponseModel.CreateInvalidFieldError("email", ex.StackTrace));
            }
        }
Exemplo n.º 20
0
        public async Task <ResponseModel <AccountExistResultModel> > Get(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(ResponseModel <AccountExistResultModel> .CreateInvalidFieldError("email", Phrases.FieldShouldNotBeEmpty));
            }

            if (!email.IsValidEmail())
            {
                return(ResponseModel <AccountExistResultModel> .CreateInvalidFieldError("email", Phrases.InvalidEmailFormat));
            }

            return(ResponseModel <AccountExistResultModel> .CreateOk(
                       new AccountExistResultModel { IsEmailRegistered = await _clientAccountsRepository.IsTraderWithEmailExistsAsync(email) }));
        }
Exemplo n.º 21
0
        public async Task <ResponseModel <PinSecurityCheckResultModel> > Get(string pin)
        {
            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel <PinSecurityCheckResultModel> .CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.NotAuthenticated));
            }

            var passed = await _puPinSecurityRepository.CheckAsync(clientId, pin);

            return(ResponseModel <PinSecurityCheckResultModel> .CreateOk(new PinSecurityCheckResultModel
            {
                Passed = passed
            }));
        }
Exemplo n.º 22
0
        public async Task <ResponseModel <InitPricesResponse> > InitPricesWithFilterV2([FromBody] InitPricesFilteredRequest request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitPricesResponse>());
            }

            var initPrices = await _rpcFacade.InitPrices(clientId, request?.AssetIds);

            var result = new InitPricesResponse {
                Prices = initPrices.Values.ToArray(), ServerTime = _dateService.Now()
            };

            return(ResponseModel <InitPricesResponse> .CreateOk(result));
        }
Exemplo n.º 23
0
        public async Task <ResponseModel <InitPricesResponse> > InitPricesV2()
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <InitPricesResponse>());
            }

            var initPrices = await _rpcFacade.InitPrices(clientId);

            var result = new InitPricesResponse {
                Prices = initPrices.Values.ToArray(), ServerTime = _dateService.Now()
            };

            return(ResponseModel <InitPricesResponse> .CreateOk(result));
        }
Exemplo n.º 24
0
        public async Task <ResponseModel <bool> > CancelOrder([FromBody] CloseOrderClientRequest request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <bool>());
            }

            var result = await _rpcFacade.CancelOrder(clientId, request);

            if (result.IsError() || !result.Result)
            {
                return(ResponseModel <bool> .CreateFail(ResponseModel.ErrorCodeType.InconsistentData,
                                                        result.Message));
            }

            return(ResponseModel <bool> .CreateOk(result.Result));
        }
Exemplo n.º 25
0
        public async Task <ResponseModel <OrderClientContract> > PlaceOrder([FromBody] NewOrderClientContract request)
        {
            var clientId = this.GetClientId();

            if (clientId == null)
            {
                return(this.UserNotFoundError <OrderClientContract>());
            }

            var result = await _rpcFacade.PlaceOrder(clientId, request);

            if (result.IsError())
            {
                return(ResponseModel <OrderClientContract> .CreateFail(ResponseModel.ErrorCodeType.InconsistentData,
                                                                       result.Message));
            }

            return(ResponseModel <OrderClientContract> .CreateOk(result.Result));
        }
Exemplo n.º 26
0
        public async Task <ResponseModel <CheckDocumentsToUploadModel> > Get()
        {
            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel <CheckDocumentsToUploadModel> .CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.NotAuthenticated));
            }

            var documents = (await _kycDocumentsRepository.GetAsync(clientId)).ToArray();

            var result = new CheckDocumentsToUploadModel
            {
                IdCard         = documents.FirstOrDefault(itm => itm.Type == KycDocumentTypes.IdCard) == null,
                ProofOfAddress = documents.FirstOrDefault(itm => itm.Type == KycDocumentTypes.ProofOfAddress) == null,
                Selfie         = documents.FirstOrDefault(itm => itm.Type == KycDocumentTypes.Selfie) == null
            };

            return(ResponseModel <CheckDocumentsToUploadModel> .CreateOk(result));
        }
        public static ResponseModel <int> ValidateAndGetValue(this int?paramValue, string parameter, int maxValue, int defaultValue)
        {
            var value = paramValue.GetValueOrDefault(defaultValue);

            if (value > maxValue)
            {
                return(ResponseModel <int> .CreateInvalidFieldError(parameter, $"{parameter} '{value}' is too big, maximum is '{maxValue}'."));
            }

            if (value < 0)
            {
                return(ResponseModel <int> .CreateInvalidFieldError(parameter, $"{parameter} cannot be less than zero."));
            }

            if (value == 0)
            {
                value = defaultValue;
            }

            return(ResponseModel <int> .CreateOk(value));
        }
Exemplo n.º 28
0
        public async Task <ResponseModel <KycModelStatusResponseModel> > Get()
        {
            var clientId = this.GetClientId();

            if (string.IsNullOrEmpty(clientId))
            {
                return(ResponseModel <KycModelStatusResponseModel> .CreateFail(ResponseModel.ErrorCodeType.NotAuthenticated, Phrases.NotAuthenticated));
            }

            var kycStatus = await _kycRepository.GetKycStatusAsync(clientId);

            if (kycStatus == KycStatus.Rejected)
            {
                kycStatus = KycStatus.NeedToFillData;
            }

            return(ResponseModel <KycModelStatusResponseModel> .CreateOk(
                       new KycModelStatusResponseModel
            {
                KycStatus = kycStatus.ToString()
            }));
        }
Exemplo n.º 29
0
        public async Task <ResponseModel> DeleteWatchList(string id)
        {
            var clientId = User.GetClaim(ClaimTypes.NameIdentifier);

            if (clientId == null)
            {
                return(ResponseModel <List <MarginTradingWatchList> > .CreateFail(ResponseModel.ErrorCodeType.NoAccess, "Wrong token"));
            }

            var result = await _watchListService.DeleteAsync(clientId, id);

            switch (result.Status)
            {
            case WatchListStatus.NotFound:
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.NoData, "Watch list not found"));

            case WatchListStatus.ReadOnly:
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InconsistentData, "Readonly watch list can't be deleted"));
            }

            return(ResponseModel.CreateOk());
        }
Exemplo n.º 30
0
        public async Task <ResponseModel> AddLot([FromBody] AuctionLot model)
        {
            if (string.IsNullOrEmpty(model.ClientId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"{nameof(model.ClientId)} is required"));
            }

            if (string.IsNullOrEmpty(model.AssetId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"{nameof(model.AssetId)} is required"));
            }

            if (!_settings.Assets.Contains(model.AssetId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.AssetId)}"));
            }

            if (model.Price <= 0)
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.Price)}"));
            }

            if (model.Volume <= 0)
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.Volume)}"));
            }

            //TODO: validate model.ClientId
            await _auctionLotManager.AddAsync(model.ClientId, model.AssetId, model.Price, model.Volume);

            return(ResponseModel.CreateOk());
        }