There was an error while loading. Please reload this page.
TwelveDataSharp was built with DI in mind. You can inject the client into ASP.NET Core controllers by first creating a singleton in Startup.cs:
services.AddSingleton<TwelveDataSharp.TwelveDataClient>(new TwelveDataClient("API_KEY", new HttpClient()));
The client can now be injected into a controller:
private readonly TwelveDataClient_client; public MyController(TwelveDataClient client) { _client = client; }
And finally used in an endpoint:
[HttpGet] [Route("GetPrice/{symbol}")] public async Task<ActionResult> GetPrice(string symbol) { var response = await _client.GetRealTimePriceAsync(symbol); return Ok(response?.Price); }