public int CalculateTechnicalIndicator(IndicatorCalculationElementsWIndicatorType data) { string jsonString = Utility.JsonSerializer.ConvertObjectToJsonString <IndicatorCalculationElementsWIndicatorType>(data); int idOfCalculation = 0; try { HttpContent payload = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = _client.PostAsync("api/CalculateTechnicalIndicator", payload).Result; if (response.StatusCode == HttpStatusCode.Created) { idOfCalculation = Utility.JsonSerializer.JsonStringToObjectType <int>(response.Content.ReadAsStringAsync().Result); } else { throw new Exception(); } } catch (Exception e) { Console.WriteLine("There was an error during process of technical indicator calculation."); idOfCalculation = -1; //throw e; } return(idOfCalculation); }
public IActionResult CalculateTechnicalIndicator(IndicatorCalculationElementsWIndicatorType data) { try { List <Signal> obtainedSignals = data.TechnicalIndicator.GetSignals(data.Quotes, data.Parameters); string jsonString = JsonSerializer.ConvertCollectionOfObjectsToJsonString <Signal>(obtainedSignals); int newFileId; lock (_padlock) { int filesCount = FileHelper.CountFilesInDirectory(GeneratedSignalsURL); newFileId = (filesCount == 0 ? 0 : filesCount); string fileName = $"signals_{newFileId}.json"; FileHelper.SaveJsonFile(GeneratedSignalsURL + fileName, jsonString); } return(StatusCode(201, newFileId)); } catch (Exception e) { return(StatusCode(500, e)); } }