Exemple #1
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
Exemple #2
0
        public async Task <IActionResult> PlaceMarketOrderAsync([FromBody] PlaceMarkerBody placeMarkerBody, string figi, int lots, int operationType)
        {
            try
            {
                var stopLoss   = placeMarkerBody.stopLoss;
                var takeProfit = placeMarkerBody.takeProfit;

                var result = await _tinkoffService.PlaceMarketOrderAsync(figi, lots, (OperationType)operationType, stopLoss, takeProfit);

                return(this.Ok(result));
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status400BadRequest, e.Message));
            }
        }