public static TakeProfitData SetValue(this TakeProfitData takeProfitData, double close)
        {
            if (takeProfitData.Value == 0.0)
            {
                takeProfitData.Value = close * (1.0 + takeProfitData.Procent / 100.0);
            }

            return(takeProfitData);
        }
        public async Task <OperationHistory> PlaceMarketOrderAsync(string figi, int lots, OperationType operationType, StopLossData stopLoss, TakeProfitData takeProfit)
        {
            var result = await _contextApi.PlaceMarketOrderAsync(figi, lots, operationType);

            if (stopLoss == null)
            {
                stopLoss = new StopLossData();
            }
            if (takeProfit == null)
            {
                takeProfit = new TakeProfitData();
            }

            var operationHistory = new OperationHistory
            {
                orderType       = (operationType == OperationType.Buy) ? TinkoffApi.Data.Enums.OrderType.Buy : TinkoffApi.Data.Enums.OrderType.Sell,
                lots            = lots,
                figi            = figi,
                orderMode       = _contextApi.GetMode(),
                time            = ServerTime.GetDate(),
                orderId         = result.OrderId,
                operationStatus = TinkoffApi.Data.Enums.OperationStatus.Progress,
                Commission      = new TinkoffApi.Data.Models.MoneyAmount(),
                Price           = 0.0,
                StopLoss        = stopLoss,
                TakeProfit      = takeProfit
            };

            _context.OperationsHistory.Add(operationHistory);

            await SaveCurrentPortfolioBDAsync();

            await _context.SaveChangesAsync();

            _backgroundService.TaskFindOperation(_contextApi, figi, result.OrderId);

            return(operationHistory);
        }
Example #3
0
        public async Task <OperationHistory> CreatePlaceMarketOrderAsync(string figi, OperationType operationType, int lots, StopLossData stopLoss = null, TakeProfitData takeProfit = null)
        {
            var url  = $"{_host}/api/Tinkoff/placeMarketOrder?operationType={(int)operationType}&lots={lots}&figi={figi}";
            var body = new PlaceMarkerBody()
            {
                stopLoss   = stopLoss,
                takeProfit = takeProfit
            };
            var content = JsonConvert.SerializeObject(body);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(url),
                Content    = new StringContent(content, System.Text.Encoding.UTF8, "application/json")
            };
            var response = await _client.SendAsync(httpRequestMessage);

            if (!response.IsSuccessStatusCode)
            {
                return(null);
            }

            var str = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <OperationHistory>(str));
        } // stocks/rus
Example #4
0
        public OperationHistory CreatePlaceMarketOrder(string figi, OperationType operationType, int lots, StopLossData stopLoss = null, TakeProfitData takeProfit = null)
        {
            OperationHistory operation = null;

            Task.Run(async() => operation = await CreatePlaceMarketOrderAsync(figi, operationType, lots, stopLoss, takeProfit))
            .Wait();

            return(operation);
        }