docker files fixes from liaqat
This commit is contained in:
73
src/Managing.Api/Controllers/DataController.cs
Normal file
73
src/Managing.Api/Controllers/DataController.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Hubs;
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using Managing.Domain.Candles;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("[controller]")]
|
||||
public class DataController : ControllerBase
|
||||
{
|
||||
private readonly IExchangeService _exchangeService;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IStatisticService _statisticService;
|
||||
private readonly IHubContext<CandleHub> _hubContext;
|
||||
|
||||
public DataController(
|
||||
IExchangeService exchangeService,
|
||||
IAccountService accountService,
|
||||
ICacheService cacheService,
|
||||
IStatisticService statisticService,
|
||||
IHubContext<CandleHub> hubContext)
|
||||
{
|
||||
_exchangeService = exchangeService;
|
||||
_accountService = accountService;
|
||||
_cacheService = cacheService;
|
||||
_statisticService = statisticService;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
[HttpPost("GetTickers")]
|
||||
public async Task<ActionResult<Ticker[]>> GetTickers(string accountName, Timeframe timeframe)
|
||||
{
|
||||
var account = await _accountService.GetAccount(accountName, true, false);
|
||||
var cacheKey = string.Concat(accountName, timeframe.ToString());
|
||||
var tickers = _cacheService.GetOrSave(cacheKey, () =>
|
||||
{
|
||||
return _exchangeService.GetTickers(account, timeframe).Result;
|
||||
}, TimeSpan.FromHours(2));
|
||||
|
||||
return Ok(tickers);
|
||||
}
|
||||
|
||||
[HttpGet("Spotlight")]
|
||||
public ActionResult<SpotlightOverview> GetSpotlight()
|
||||
{
|
||||
var overview = _cacheService.GetOrSave(nameof(SpotlightOverview), () =>
|
||||
{
|
||||
return _statisticService.GetLastSpotlight(DateTime.Now.AddHours(-3));
|
||||
}, TimeSpan.FromMinutes(2));
|
||||
|
||||
if (overview?.Spotlights.Count < overview?.ScenarioCount)
|
||||
{
|
||||
overview = _statisticService.GetLastSpotlight(DateTime.Now.AddHours(-3));
|
||||
}
|
||||
|
||||
return Ok(overview);
|
||||
}
|
||||
|
||||
[HttpGet("GetCandles")]
|
||||
public async Task<ActionResult<List<Candle>>> GetCandles(TradingExchanges exchange, Ticker ticker, DateTime startDate, Timeframe timeframe)
|
||||
{
|
||||
return Ok(await _exchangeService.GetCandlesInflux(exchange, ticker, startDate, timeframe));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user