コード例 #1
0
 public static QuoteResponse Success(ConvertQuote quote)
 {
     return(new QuoteResponse()
     {
         Data = quote,
         IsSuccess = true
     });
 }
コード例 #2
0
 public static QuoteExecutionResponse ReQuote(ConvertQuote quote)
 {
     return(new QuoteExecutionResponse()
     {
         Data = quote,
         QuoteExecutionResult = QuoteExecutionResult.ReQuote
     });
 }
コード例 #3
0
 public static QuoteExecutionResponse Success(ConvertQuote quote)
 {
     return(new QuoteExecutionResponse()
     {
         Data = quote,
         QuoteExecutionResult = QuoteExecutionResult.Success
     });
 }
コード例 #4
0
 public static bool IsQuoteEquals(ConvertQuote entity, ExecuteQuoteRequest quote)
 {
     return(entity.FromAsset.Equals(quote.FromAsset) &&
            entity.ToAsset.Equals(quote.ToAsset) &&
            entity.FromAssetVolume.Equals(quote.FromAssetVolume) &&
            entity.ToAssetVolume.Equals(quote.ToAssetVolume) &&
            entity.IsFromFixed.Equals(quote.IsFromFixed) &&
            entity.BrokerId.Equals(quote.BrokerId) &&
            entity.AccountId.Equals(quote.AccountId) &&
            entity.WalletId.Equals(quote.WalletId) &&
            entity.OperationId.Equals(quote.OperationId) &&
            entity.Price.Equals(quote.Price));
 }
コード例 #5
0
        private async Task <QuoteExecutionResponse> GenerateReQuote(ConvertQuote quote)
        {
            var requestQuote = new GetQuoteRequest()
            {
                FromAsset       = quote.FromAsset,
                FromAssetVolume = quote.FromAssetVolume,
                ToAsset         = quote.ToAsset,
                ToAssetVolume   = quote.ToAssetVolume,
                IsFromFixed     = quote.IsFromFixed,

                WalletId  = quote.WalletId,
                AccountId = quote.AccountId,
                BrokerId  = quote.BrokerId
            };

            var newQuoteResponse = await GenerateQuote(requestQuote, quote.OperationId);

            if (!newQuoteResponse.IsSuccess)
            {
                return(new QuoteExecutionResponse()
                {
                    QuoteExecutionResult = QuoteExecutionResult.Error,
                    Data = null,
                    ErrorMessage = newQuoteResponse.ErrorMessage
                });
            }

            var response = new QuoteExecutionResponse()
            {
                QuoteExecutionResult = QuoteExecutionResult.ReQuote,
                Data         = newQuoteResponse.Data,
                ErrorMessage = string.Empty
            };

            return(response);
        }
コード例 #6
0
 public Task SaveAsync(ConvertQuote quote)
 {
     _quoteStorage[quote.OperationId] = quote;
     return(Task.CompletedTask);
 }
コード例 #7
0
        public void ExecuteQuoteValidationTest()
        {
            var storageQuote = new ConvertQuote()
            {
                FromAsset       = "BTC",
                ToAsset         = "USD",
                FromAssetVolume = 0.1,
                ToAssetVolume   = 150,
                IsFromFixed     = true,
                BrokerId        = "broker",
                AccountId       = "Acc",
                WalletId        = "wallet",
                Price           = 323,
                ExpireDate      = DateTime.MaxValue,
                OperationId     = "someId",
                OpenDate        = DateTime.UtcNow,
                ClosedDate      = DateTime.MinValue,
                State           = QuoteState.Active
            };

            ConvertQuoteStorageMock.SaveAsync(storageQuote);

            var executeQuoteRequestCase1 = new ExecuteQuoteRequest()
            {
                FromAsset       = storageQuote.FromAsset,
                ToAsset         = storageQuote.ToAsset,
                FromAssetVolume = storageQuote.FromAssetVolume,
                ToAssetVolume   = storageQuote.ToAssetVolume,
                IsFromFixed     = storageQuote.IsFromFixed,
                BrokerId        = storageQuote.BrokerId,
                AccountId       = storageQuote.AccountId,
                WalletId        = "something else",
                OperationId     = storageQuote.OperationId,
                Price           = storageQuote.Price
            };

            var response = Service.ExecuteQuoteAsync(executeQuoteRequestCase1);

            Assert.IsTrue(response.Result.QuoteExecutionResult == QuoteExecutionResult.Error);

            var executeQuoteRequestCase2 = new ExecuteQuoteRequest()
            {
                FromAsset       = storageQuote.FromAsset,
                ToAsset         = storageQuote.ToAsset,
                FromAssetVolume = storageQuote.FromAssetVolume,
                ToAssetVolume   = 11,
                IsFromFixed     = storageQuote.IsFromFixed,
                BrokerId        = storageQuote.BrokerId,
                AccountId       = storageQuote.AccountId,
                WalletId        = storageQuote.WalletId,
                OperationId     = storageQuote.OperationId,
                Price           = storageQuote.Price
            };

            var response2 = Service.ExecuteQuoteAsync(executeQuoteRequestCase2);

            Assert.IsTrue(response2.Result.QuoteExecutionResult == QuoteExecutionResult.Error);


            var executeQuoteRequestCase3 = new ExecuteQuoteRequest()
            {
                FromAsset       = storageQuote.FromAsset,
                ToAsset         = "new asset",
                FromAssetVolume = storageQuote.FromAssetVolume,
                ToAssetVolume   = storageQuote.ToAssetVolume,
                IsFromFixed     = storageQuote.IsFromFixed,
                BrokerId        = storageQuote.BrokerId,
                AccountId       = storageQuote.AccountId,
                WalletId        = storageQuote.WalletId,
                OperationId     = storageQuote.OperationId,
                Price           = storageQuote.Price
            };

            var response3 = Service.ExecuteQuoteAsync(executeQuoteRequestCase3);

            Assert.IsTrue(response3.Result.QuoteExecutionResult == QuoteExecutionResult.Error);
        }
コード例 #8
0
        private async Task <QuoteResponse> GenerateQuote(GetQuoteRequest requestQuote, string previousOperationId)
        {
            var settings = _liquidityConverterSettingsAccessor.GetLiquidityConverterSettings(requestQuote.BrokerId);

            if (settings == null)
            {
                return(ErrorQuoteResponse("Liquidity Converter is not configured for broker"));
            }

            var processQuoteResult =
                _instrumentEngine.ProcessQuoteRequest(requestQuote, settings.MarkUp);

            if (!string.IsNullOrWhiteSpace(processQuoteResult.ErrorMessage))
            {
                return(ErrorQuoteResponse(processQuoteResult.ErrorMessage));
            }

            // todo: calculate fee
            //var finalPrice = (1 + settings.MarkUp + fee) * price;
            //finalPrice = Math.Round(finalPrice, Mathematics.AccuracyToNormalizeDouble);
            //finalPrice = Math.Round(finalPrice, instrument.Accuracy, MidpointRounding.ToZero);

            var operationId = Guid.NewGuid().ToString("N");

            var quote = new ConvertQuote(requestQuote.FromAsset,
                                         requestQuote.ToAsset,
                                         processQuoteResult.FromAssetVolume,
                                         processQuoteResult.ToAssetVolume,
                                         requestQuote.IsFromFixed,
                                         requestQuote.BrokerId,
                                         requestQuote.AccountId,
                                         requestQuote.WalletId,
                                         previousOperationId
                                         )
            {
                Price       = processQuoteResult.Price,
                OperationId = operationId
            };

            var now = DateTime.UtcNow;

            quote.ExpireDate = now.AddSeconds(settings.ExpirationInSeconds);
            quote.OpenDate   = DateTime.UtcNow;
            quote.ClosedDate = DateTime.MinValue;
            quote.State      = QuoteState.Active;

            // todo: добавить контекст формирования квоты - orderSide, instrumentS, fee
            await _convertQuoteStorage.SaveAsync(quote);

            processQuoteResult.Instruments.ForEach(async instrumentInTrade =>
            {
                await _convertQuoteStorage.SaveAsync(new Trade()
                {
                    TradeId          = Guid.NewGuid().ToString("N"),
                    OperationId      = operationId,
                    Fee              = 0.0, // todo: calculate fee
                    MarkUp           = settings.MarkUp,
                    InstrumentSymbol = instrumentInTrade.Symbol,
                    InstrumentPrice  = instrumentInTrade.Price,
                    State            = TradeState.New
                });
            });

            // we send to client short interval and keep on server long interval
            quote.ExpireDate = now.AddSeconds(settings.ClientExpirationInSeconds);

            return(QuoteResponse.Success(quote));
        }