Пример #1
0
        public async Task <OpenOrderBackendResponse> PlaceOrder([FromBody] OpenOrderBackendRequest request)
        {
            var code = await _identityGenerator.GenerateIdAsync(nameof(Order));

            var order = new Order
            {
                Id                = Guid.NewGuid().ToString("N"),
                Code              = code,
                CreateDate        = DateTime.UtcNow,
                ClientId          = request.ClientId,
                AccountId         = request.Order.AccountId,
                Instrument        = request.Order.Instrument,
                Volume            = request.Order.Volume,
                ExpectedOpenPrice = request.Order.ExpectedOpenPrice,
                TakeProfit        = request.Order.TakeProfit,
                StopLoss          = request.Order.StopLoss
            };

            var placedOrder = await _tradingEngine.PlaceOrderAsync(order);

            var result = BackendContractFactory.CreateOpenOrderBackendResponse(placedOrder);

            _consoleWriter.WriteLine($"action order.place for clientId = {request.ClientId}");
            _operationsLogService.AddLog("action order.place", request.ClientId, request.Order.AccountId, request.ToJson(), result.ToJson());

            return(result);
        }
Пример #2
0
        private async Task <OrderInitialParameters> GetOrderInitialParameters(string assetPairId, string legalEntity,
                                                                              ReportingEquivalentPricesSettings equivalentSettings, string accountAssetId)
        {
            var fxAssetPairIdAndDirection = _cfdCalculatorService.GetFxAssetPairIdAndDirection(accountAssetId,
                                                                                               assetPairId, legalEntity);

            return(new OrderInitialParameters
            {
                Id = _identityGenerator.GenerateAlphanumericId(),
                Code = await _identityGenerator.GenerateIdAsync(nameof(Order)),
                Now = _dateService.Now(),
                EquivalentPrice = _cfdCalculatorService.GetQuoteRateForQuoteAsset(equivalentSettings.EquivalentAsset,
                                                                                  assetPairId, legalEntity),
                FxPrice = _cfdCalculatorService.GetQuoteRateForQuoteAsset(accountAssetId,
                                                                          assetPairId, legalEntity),
                FxAssetPairId = fxAssetPairIdAndDirection.id,
                FxToAssetPairDirection = fxAssetPairIdAndDirection.direction,
            });
        }