private (ISpotInstrument, ISpotInstrument) GetInstumentPair( string brokerId, string fromAsset, string toAsset) { (ISpotInstrument, ISpotInstrument)result = (null, null); var instruments = _spotInstrumentDictionaryClient.GetSpotInstrumentByBroker(new JetBrandIdentity { BrokerId = brokerId }); foreach (var asset in _liquidityConverterSettingsAccessor.GetLiquidityConverterSettings(brokerId) .CrossAssetSymbols) { var instrument1 = instruments.FirstOrDefault(e => e.BaseAsset == fromAsset && e.QuoteAsset == asset || e.BaseAsset == asset && e.QuoteAsset == fromAsset); if (instrument1 != null) { var instrument2 = instruments.FirstOrDefault(e => e.BaseAsset == asset && e.QuoteAsset == toAsset || e.BaseAsset == toAsset && e.QuoteAsset == asset); if (instrument2 != null) { result = (instrument1, instrument2); break; } } } return(result); }
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)); }