{"repo": "arithmax-research/feenqr", "files": {"Services/DataRequirementAdvisor.cs": {"022ddb72e6486a5a8812c65889823fadf0d0f0f4": {"t": 1785745797.6121912, "n": 4131, "h": "041dd27ba4d64f88", "c": "using Microsoft.Extensions.Logging;\nusing System.Net.Http;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Configuration;\n\nnamespace QuantResearchAgent.Services;\n\npublic class DataRequirementAdvisor\n{\n private readonly ILogger _logger;\n private readonly HttpClient _httpClient;\n private readonly string _apiKey;\n private readonly string _model;\n\n public DataRequirementAdvisor(ILogger logger, IHttpClientFactory httpClientFactory, IConfiguration configuration)\n {\n _logger = logger;\n _httpClient = httpClientFactory.CreateClient();\n _apiKey = configuration[\"DeepSeek:ApiKey\"] ?? Environment.GetEnvironmentVariable(\"DEEPSEEK_API_KEY\") ?? throw new InvalidOperationException(\"DEEPSEEK_API_KEY not set\");\n _model = configuration[\"DeepSeek:ModelId\"] ?? \"deepseek-chat\";\n }\n\n public async Task> AnalyzeDataRequirementsAsync(string strategyText)\n {\n try\n {\n var prompt = $@\"\nAnalyze this trading strategy description and determine what data types are ABSOLUTELY REQUIRED for QuantConnect LEAN backtesting.\n\nStrategy: {strategyText}\n\nIMPORTANT: Only include data types that are explicitly mentioned in the strategy or clearly required for the core trading logic. Do not include data for performance metrics, benchmarks, or general analysis unless the strategy specifically requires it.\n\nCommon types include:\n- 'equity' for US stock/ETF data (required for most equity strategies)\n- 'crypto' for cryptocurrency data\n- 'forex' for foreign exchange data\n- 'commodity' for commodity/futures data\n- 'interest-rate' for risk-free rate data (only if strategy uses it for calculations)\n- 'alternative' for alternative data sources\n\nFor simple technical indicator strategies on equities, typically only 'equity' is needed.\n\nReturn a JSON array of data types required. Only return the JSON array, no other text.\nExample: [\"\"equity\"\"]\n\";\n\n var requestBody = new\n {\n model = _model,\n messages = new[]\n {\n new { role = \"user\", content = prompt }\n },\n temperature = 0.1,\n max_tokens = 200\n };\n\n var request = new HttpRequestMessage(HttpMethod.Post, \"https://api.deepseek.com/v1/chat/completions\")\n {\n Headers = { { \"Authorization\", $\"Bearer {_apiKey}\" } },\n Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, \"application/json\")\n };\n\n var response = await _httpClient.SendAsync(request);\n response.EnsureSuccessStatusCode();\n\n var responseContent = await response.Content.ReadAsStringAsync();\n var jsonResponse = JsonDocument.Parse(responseContent);\n var content = jsonResponse.RootElement.GetProperty(\"choices\")[0].GetProperty(\"message\").GetProperty(\"content\").GetString();\n\n if (string.IsNullOrWhiteSpace(content))\n {\n _logger.LogWarning(\"Empty response from DeepSeek for data requirements\");\n return new List { \"equity\" }; // fallback\n }\n\n // Try to parse as JSON array\n try\n {\n var dataTypes = JsonSerializer.Deserialize>(content.Trim());\n _logger.LogInformation(\"DeepSeek identified data requirements: {Types}\", string.Join(\", \", dataTypes ?? new List()));\n return dataTypes ?? new List { \"equity\" };\n }\n catch (JsonException ex)\n {\n _logger.LogWarning(ex, \"Failed to parse DeepSeek response as JSON: {Content}\", content);\n return new List { \"equity\" }; // fallback\n }\n }\n catch (Exception ex)\n {\n _logger.LogError(ex, \"Error analyzing data requirements with DeepSeek\");\n return new List { \"equity\" }; // fallback to basic equity data\n }\n }\n}"}, "4cef60ae96bb841b739bc3f6493b726f8545c05a": {"t": 1785756596.5815623, "n": 4131, "h": "041dd27ba4d64f88", "c": "using Microsoft.Extensions.Logging;\nusing System.Net.Http;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Configuration;\n\nnamespace QuantResearchAgent.Services;\n\npublic class DataRequirementAdvisor\n{\n private readonly ILogger _logger;\n private readonly HttpClient _httpClient;\n private readonly string _apiKey;\n private readonly string _model;\n\n public DataRequirementAdvisor(ILogger logger, IHttpClientFactory httpClientFactory, IConfiguration configuration)\n {\n _logger = logger;\n _httpClient = httpClientFactory.CreateClient();\n _apiKey = configuration[\"DeepSeek:ApiKey\"] ?? Environment.GetEnvironmentVariable(\"DEEPSEEK_API_KEY\") ?? throw new InvalidOperationException(\"DEEPSEEK_API_KEY not set\");\n _model = configuration[\"DeepSeek:ModelId\"] ?? \"deepseek-chat\";\n }\n\n public async Task> AnalyzeDataRequirementsAsync(string strategyText)\n {\n try\n {\n var prompt = $@\"\nAnalyze this trading strategy description and determine what data types are ABSOLUTELY REQUIRED for QuantConnect LEAN backtesting.\n\nStrategy: {strategyText}\n\nIMPORTANT: Only include data types that are explicitly mentioned in the strategy or clearly required for the core trading logic. Do not include data for performance metrics, benchmarks, or general analysis unless the strategy specifically requires it.\n\nCommon types include:\n- 'equity' for US stock/ETF data (required for most equity strategies)\n- 'crypto' for cryptocurrency data\n- 'forex' for foreign exchange data\n- 'commodity' for commodity/futures data\n- 'interest-rate' for risk-free rate data (only if strategy uses it for calculations)\n- 'alternative' for alternative data sources\n\nFor simple technical indicator strategies on equities, typically only 'equity' is needed.\n\nReturn a JSON array of data types required. Only return the JSON array, no other text.\nExample: [\"\"equity\"\"]\n\";\n\n var requestBody = new\n {\n model = _model,\n messages = new[]\n {\n new { role = \"user\", content = prompt }\n },\n temperature = 0.1,\n max_tokens = 200\n };\n\n var request = new HttpRequestMessage(HttpMethod.Post, \"https://api.deepseek.com/v1/chat/completions\")\n {\n Headers = { { \"Authorization\", $\"Bearer {_apiKey}\" } },\n Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, \"application/json\")\n };\n\n var response = await _httpClient.SendAsync(request);\n response.EnsureSuccessStatusCode();\n\n var responseContent = await response.Content.ReadAsStringAsync();\n var jsonResponse = JsonDocument.Parse(responseContent);\n var content = jsonResponse.RootElement.GetProperty(\"choices\")[0].GetProperty(\"message\").GetProperty(\"content\").GetString();\n\n if (string.IsNullOrWhiteSpace(content))\n {\n _logger.LogWarning(\"Empty response from DeepSeek for data requirements\");\n return new List { \"equity\" }; // fallback\n }\n\n // Try to parse as JSON array\n try\n {\n var dataTypes = JsonSerializer.Deserialize>(content.Trim());\n _logger.LogInformation(\"DeepSeek identified data requirements: {Types}\", string.Join(\", \", dataTypes ?? new List()));\n return dataTypes ?? new List { \"equity\" };\n }\n catch (JsonException ex)\n {\n _logger.LogWarning(ex, \"Failed to parse DeepSeek response as JSON: {Content}\", content);\n return new List { \"equity\" }; // fallback\n }\n }\n catch (Exception ex)\n {\n _logger.LogError(ex, \"Error analyzing data requirements with DeepSeek\");\n return new List { \"equity\" }; // fallback to basic equity data\n }\n }\n}"}}, "Services/DeepSeekService.cs": {"022ddb72e6486a5a8812c65889823fadf0d0f0f4": {"t": 1785746211.4591572, "n": 3096, "h": "552dc44c6a7f15cb", "c": "using System;\nusing System.Net.Http;\nusing System.Net.Http.Headers;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.Logging;\n\nnamespace QuantResearchAgent.Services\n{\n public class DeepSeekService\n {\n private readonly string _apiKey;\n private readonly string _modelId;\n private readonly string _baseUrl;\n private readonly HttpClient _httpClient;\n private readonly ILogger _logger;\n\n public DeepSeekService(IConfiguration configuration, HttpClient httpClient, ILogger logger)\n {\n _apiKey = configuration[\"DeepSeek:ApiKey\"] ?? throw new ArgumentException(\"DeepSeek API key not configured\");\n _modelId = configuration[\"DeepSeek:ModelId\"] ?? \"deepseek-chat\";\n _baseUrl = configuration[\"DeepSeek:BaseUrl\"] ?? \"https://api.deepseek.com/v1/chat/completions\";\n _httpClient = httpClient;\n _logger = logger;\n }\n\n public async Task GetChatCompletionAsync(string prompt)\n {\n try\n {\n var requestBody = new\n {\n model = _modelId,\n messages = new[]\n {\n new { role = \"user\", content = prompt }\n }\n };\n\n var requestJson = JsonSerializer.Serialize(requestBody);\n var request = new HttpRequestMessage(HttpMethod.Post, _baseUrl);\n request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", _apiKey);\n request.Content = new StringContent(requestJson, Encoding.UTF8, \"application/json\");\n\n var response = await _httpClient.SendAsync(request);\n var responseJson = await response.Content.ReadAsStringAsync();\n\n if (!response.IsSuccessStatusCode)\n {\n _logger?.LogError($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n throw new Exception($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n }\n\n try\n {\n using var doc = JsonDocument.Parse(responseJson);\n var content = doc.RootElement\n .GetProperty(\"choices\")[0]\n .GetProperty(\"message\")\n .GetProperty(\"content\")\n .GetString();\n return content ?? string.Empty;\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, $\"Failed to parse DeepSeek response: {responseJson}\");\n throw new Exception($\"Failed to parse DeepSeek response: {responseJson}\", ex);\n }\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, \"DeepSeekService.GetChatCompletionAsync failed\");\n throw;\n }\n }\n }\n}\n"}, "38b82f14f11d7d38fb1238f605dd4651334d939f": {"t": 1785756598.2853212, "n": 3096, "h": "552dc44c6a7f15cb", "c": "using System;\nusing System.Net.Http;\nusing System.Net.Http.Headers;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.Logging;\n\nnamespace QuantResearchAgent.Services\n{\n public class DeepSeekService\n {\n private readonly string _apiKey;\n private readonly string _modelId;\n private readonly string _baseUrl;\n private readonly HttpClient _httpClient;\n private readonly ILogger _logger;\n\n public DeepSeekService(IConfiguration configuration, HttpClient httpClient, ILogger logger)\n {\n _apiKey = configuration[\"DeepSeek:ApiKey\"] ?? throw new ArgumentException(\"DeepSeek API key not configured\");\n _modelId = configuration[\"DeepSeek:ModelId\"] ?? \"deepseek-chat\";\n _baseUrl = configuration[\"DeepSeek:BaseUrl\"] ?? \"https://api.deepseek.com/v1/chat/completions\";\n _httpClient = httpClient;\n _logger = logger;\n }\n\n public async Task GetChatCompletionAsync(string prompt)\n {\n try\n {\n var requestBody = new\n {\n model = _modelId,\n messages = new[]\n {\n new { role = \"user\", content = prompt }\n }\n };\n\n var requestJson = JsonSerializer.Serialize(requestBody);\n var request = new HttpRequestMessage(HttpMethod.Post, _baseUrl);\n request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", _apiKey);\n request.Content = new StringContent(requestJson, Encoding.UTF8, \"application/json\");\n\n var response = await _httpClient.SendAsync(request);\n var responseJson = await response.Content.ReadAsStringAsync();\n\n if (!response.IsSuccessStatusCode)\n {\n _logger?.LogError($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n throw new Exception($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n }\n\n try\n {\n using var doc = JsonDocument.Parse(responseJson);\n var content = doc.RootElement\n .GetProperty(\"choices\")[0]\n .GetProperty(\"message\")\n .GetProperty(\"content\")\n .GetString();\n return content ?? string.Empty;\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, $\"Failed to parse DeepSeek response: {responseJson}\");\n throw new Exception($\"Failed to parse DeepSeek response: {responseJson}\", ex);\n }\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, \"DeepSeekService.GetChatCompletionAsync failed\");\n throw;\n }\n }\n }\n}\n"}, "8d207ee92f8c2f28a1c5176243cceb3b21949523": {"t": 1785756599.7343462, "n": 3060, "h": "5e9895ee7babb31b", "c": "using System;\nusing System.Net.Http;\nusing System.Net.Http.Headers;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Configuration;\n\nnamespace QuantResearchAgent.Services\n{\n public class DeepSeekService\n {\n private readonly string _apiKey;\n private readonly string _modelId;\n private readonly string _baseUrl;\n private readonly HttpClient _httpClient;\n private readonly ILogger _logger;\n\n public DeepSeekService(IConfiguration configuration, HttpClient httpClient, ILogger logger)\n {\n _apiKey = configuration[\"DeepSeek:ApiKey\"] ?? throw new ArgumentException(\"DeepSeek API key not configured\");\n _modelId = configuration[\"DeepSeek:ModelId\"] ?? \"deepseek-chat\";\n _baseUrl = configuration[\"DeepSeek:BaseUrl\"] ?? \"https://api.deepseek.com/v1/chat/completions\";\n _httpClient = httpClient;\n _logger = logger;\n }\n\n public async Task GetChatCompletionAsync(string prompt)\n {\n try\n {\n var requestBody = new\n {\n model = _modelId,\n messages = new[]\n {\n new { role = \"user\", content = prompt }\n }\n };\n\n var requestJson = JsonSerializer.Serialize(requestBody);\n var request = new HttpRequestMessage(HttpMethod.Post, _baseUrl);\n request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", _apiKey);\n request.Content = new StringContent(requestJson, Encoding.UTF8, \"application/json\");\n\n var response = await _httpClient.SendAsync(request);\n var responseJson = await response.Content.ReadAsStringAsync();\n\n if (!response.IsSuccessStatusCode)\n {\n _logger?.LogError($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n throw new Exception($\"DeepSeek API error: {response.StatusCode} - {responseJson}\");\n }\n\n try\n {\n using var doc = JsonDocument.Parse(responseJson);\n var content = doc.RootElement\n .GetProperty(\"choices\")[0]\n .GetProperty(\"message\")\n .GetProperty(\"content\")\n .GetString();\n return content ?? string.Empty;\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, $\"Failed to parse DeepSeek response: {responseJson}\");\n throw new Exception($\"Failed to parse DeepSeek response: {responseJson}\", ex);\n }\n }\n catch (Exception ex)\n {\n _logger?.LogError(ex, \"DeepSeekService.GetChatCompletionAsync failed\");\n throw;\n }\n }\n }\n}\n"}}}}