docker files fixes from liaqat
This commit is contained in:
75
src/Managing.Api.Workers/Workers/BaseWorker.cs
Normal file
75
src/Managing.Api.Workers/Workers/BaseWorker.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers;
|
||||
|
||||
public abstract class BaseWorker<T> : BackgroundService where T : class
|
||||
{
|
||||
private readonly WorkerType _workerType;
|
||||
protected readonly ILogger<T> _logger;
|
||||
protected readonly TimeSpan _delay;
|
||||
private readonly IWorkerService _workerService;
|
||||
private int _executionCount;
|
||||
|
||||
protected BaseWorker(
|
||||
WorkerType workerType,
|
||||
ILogger<T> logger,
|
||||
TimeSpan timeSpan,
|
||||
IWorkerService workerService)
|
||||
{
|
||||
_workerType = workerType;
|
||||
_logger = logger;
|
||||
_delay = timeSpan == TimeSpan.Zero ? TimeSpan.FromMinutes(1) : timeSpan;
|
||||
_workerService = workerService;
|
||||
_executionCount = 0;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation($"[{_workerType}] Starting");
|
||||
var worker = await _workerService.GetWorker(_workerType);
|
||||
|
||||
if (worker == null)
|
||||
{
|
||||
await _workerService.InsertWorker(_workerType, _delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"[{_workerType}] Last run : {worker.LastRunTime} - Execution Count : {worker.ExecutionCount}");
|
||||
_executionCount = worker.ExecutionCount;
|
||||
}
|
||||
|
||||
cancellationToken.Register(() => _logger.LogInformation($"[{_workerType}] Stopping"));
|
||||
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
worker = await _workerService.GetWorker(_workerType);
|
||||
|
||||
//if (true)
|
||||
if (worker.IsActive)
|
||||
{
|
||||
await Run(cancellationToken);
|
||||
_executionCount++;
|
||||
await _workerService.UpdateWorker(_workerType, _executionCount);
|
||||
_logger.LogInformation($"[{_workerType}] Run ok. Next run at : {DateTime.UtcNow.Add(_delay)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"[{_workerType}] Worker not active. Next run at : {DateTime.UtcNow.Add(_delay)}");
|
||||
}
|
||||
|
||||
await Task.Delay(_delay);
|
||||
}
|
||||
_logger.LogInformation($"[{_workerType}] Stopped");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Error : {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task Run(CancellationToken cancellationToken);
|
||||
}
|
||||
29
src/Managing.Api.Workers/Workers/FeeWorker.cs
Normal file
29
src/Managing.Api.Workers/Workers/FeeWorker.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class FeeWorker : BaseWorker<FeeWorker>
|
||||
{
|
||||
private readonly ITradingService _tradingService;
|
||||
private static readonly WorkerType _workerType = WorkerType.Fee;
|
||||
|
||||
public FeeWorker(
|
||||
ILogger<FeeWorker> logger,
|
||||
ITradingService tradingService,
|
||||
IWorkerService workerService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromHours(12),
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_tradingService = tradingService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
_tradingService.UpdateFee(TradingExchanges.Evm);
|
||||
}
|
||||
}
|
||||
28
src/Managing.Api.Workers/Workers/LeaderboardWorker.cs
Normal file
28
src/Managing.Api.Workers/Workers/LeaderboardWorker.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class LeaderboardWorker : BaseWorker<FeeWorker>
|
||||
{
|
||||
private readonly IStatisticService _statisticService;
|
||||
private static readonly WorkerType _workerType = WorkerType.LeaderboardWorker;
|
||||
|
||||
public LeaderboardWorker(
|
||||
ILogger<FeeWorker> logger,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromHours(24),
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_statisticService = statisticService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await _statisticService.UpdateLeaderboard();
|
||||
}
|
||||
}
|
||||
28
src/Managing.Api.Workers/Workers/NoobiesboardWorker.cs
Normal file
28
src/Managing.Api.Workers/Workers/NoobiesboardWorker.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class NoobiesboardWorker : BaseWorker<FeeWorker>
|
||||
{
|
||||
private readonly IStatisticService _statisticService;
|
||||
private static readonly WorkerType _workerType = WorkerType.Noobiesboard;
|
||||
|
||||
public NoobiesboardWorker(
|
||||
ILogger<FeeWorker> logger,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromHours(24),
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_statisticService = statisticService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await _statisticService.UpdateNoobiesboard();
|
||||
}
|
||||
}
|
||||
37
src/Managing.Api.Workers/Workers/PositionFetcher.cs
Normal file
37
src/Managing.Api.Workers/Workers/PositionFetcher.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Hubs;
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PositionFetcher : BaseWorker<PositionFetcher>
|
||||
{
|
||||
private static readonly WorkerType _workerType = WorkerType.PositionFetcher;
|
||||
private readonly ITradingService _tradingService;
|
||||
private readonly IHubContext<PositionHub> _hubContext;
|
||||
private readonly ILogger<PositionFetcher> _logger;
|
||||
|
||||
public PositionFetcher(
|
||||
ILogger<PositionFetcher> logger,
|
||||
IWorkerService workerService,
|
||||
ITradingService tradingService,
|
||||
|
||||
IHubContext<PositionHub> hubContext) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromSeconds(10),
|
||||
workerService)
|
||||
{
|
||||
_logger = logger;
|
||||
_tradingService = tradingService;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
var positions = _tradingService.GetPositions().Where(p => p.Initiator != PositionInitiator.PaperTrading);
|
||||
await _hubContext.Clients.All.SendAsync("Positions", positions);
|
||||
}
|
||||
}
|
||||
200
src/Managing.Api.Workers/Workers/PositionManagerWorker.cs
Normal file
200
src/Managing.Api.Workers/Workers/PositionManagerWorker.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using Managing.Domain.Trades;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PositionManagerWorker : BaseWorker<PositionManagerWorker>
|
||||
{
|
||||
private static readonly WorkerType _workerType = WorkerType.PositionManager;
|
||||
private readonly ITradingService _tradingService;
|
||||
private readonly IExchangeService _exchangeService;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly ILogger<PositionManagerWorker> _logger;
|
||||
|
||||
public PositionManagerWorker(
|
||||
ILogger<PositionManagerWorker> logger,
|
||||
IWorkerService workerService,
|
||||
ITradingService tradingService,
|
||||
IExchangeService exchangeService,
|
||||
IAccountService accountService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromMinutes(1),
|
||||
workerService)
|
||||
{
|
||||
_logger = logger;
|
||||
_tradingService = tradingService;
|
||||
_exchangeService = exchangeService;
|
||||
_accountService = accountService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await ManageNewPositions();
|
||||
await ManagePartillyFilledPositions();
|
||||
await ManageFilledPositions();
|
||||
}
|
||||
|
||||
private async Task ManagePartillyFilledPositions()
|
||||
{
|
||||
var positions = GetPositions(PositionStatus.PartiallyFilled);
|
||||
|
||||
_logger.LogInformation("Partilly filled positions count : {0} ", positions.Count());
|
||||
|
||||
foreach (var position in positions)
|
||||
{
|
||||
_logger.LogInformation("Managing Partilly filled position: {0} - Date: {1} - Direction: {2} - Ticker: {3}", position.Identifier, position.Date, position.OriginDirection, position.Ticker);
|
||||
|
||||
var account = await _accountService.GetAccount(position.AccountName, false, false);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (position.StopLoss.Status == TradeStatus.PendingOpen)
|
||||
{
|
||||
var stopLoss = _exchangeService.OpenStopLoss(account, position.Ticker, position.OriginDirection, position.StopLoss.Price, position.StopLoss.Quantity, false, DateTime.UtcNow).Result;
|
||||
|
||||
if (stopLoss != null & (stopLoss.Status == TradeStatus.Requested))
|
||||
{
|
||||
position.StopLoss = stopLoss;
|
||||
_logger.LogInformation("|_ SL is requested");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Stop loss not requested");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"|_ SL is already handle. Current status = {position.StopLoss.Status}");
|
||||
}
|
||||
|
||||
if (position.TakeProfit1.Status == TradeStatus.PendingOpen)
|
||||
{
|
||||
var takeProfit1 = _exchangeService.OpenTakeProfit(account, position.Ticker, position.OriginDirection, position.TakeProfit1.Price, position.TakeProfit1.Quantity, false, DateTime.UtcNow).Result;
|
||||
|
||||
if (takeProfit1 != null & (takeProfit1.Status == TradeStatus.Requested))
|
||||
{
|
||||
position.TakeProfit1 = takeProfit1;
|
||||
_logger.LogInformation("|_ TP is requested");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Take Profit 1 not requested");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"|_ TP is already handle. Current status = {position.TakeProfit1.Status}");
|
||||
}
|
||||
|
||||
if (position.TakeProfit2 != null &&
|
||||
position.TakeProfit2.Status == TradeStatus.PendingOpen)
|
||||
{
|
||||
var takeProfit2 = _exchangeService.OpenTakeProfit(account, position.Ticker, position.OriginDirection, position.TakeProfit2.Price, position.TakeProfit2.Quantity, false, DateTime.UtcNow).Result;
|
||||
|
||||
if (takeProfit2 != null & (takeProfit2.Status == TradeStatus.Requested))
|
||||
{
|
||||
position.TakeProfit2 = takeProfit2;
|
||||
_logger.LogInformation("|_ TP2 is requested");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Take Profit 2 not requested");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("|_ TP2 is already handle or not required");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"|_ Cannot fully filled position because : {ex.Message}");
|
||||
}
|
||||
|
||||
if (position.StopLoss.Status == TradeStatus.Requested
|
||||
&& position.TakeProfit1.Status == TradeStatus.Requested
|
||||
&& (position.TakeProfit2 == null || position.TakeProfit2.Status == TradeStatus.Requested))
|
||||
{
|
||||
position.Status = PositionStatus.Filled;
|
||||
_logger.LogInformation($"|_ Position is now open and SL/TP are correctly requested");
|
||||
}
|
||||
|
||||
_tradingService.UpdatePosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ManageFilledPositions()
|
||||
{
|
||||
var positions = GetPositions(PositionStatus.Filled);
|
||||
|
||||
_logger.LogInformation("Filled positions count : {0} ", positions.Count());
|
||||
|
||||
foreach (var position in positions)
|
||||
{
|
||||
_logger.LogInformation("Managing filled position: {0} - Date: {1} - Direction: {2} - Ticker: {3}", position.Identifier, position.Date, position.OriginDirection, position.Ticker);
|
||||
var account = await _accountService.GetAccount(position.AccountName, false, false);
|
||||
|
||||
var updatedPosition = await _tradingService.ManagePosition(account, position);
|
||||
_tradingService.UpdatePosition(updatedPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Position> GetPositions(PositionStatus positionStatus)
|
||||
{
|
||||
return _tradingService.GetPositionsByStatus(positionStatus)
|
||||
.Where(p => p.Initiator != PositionInitiator.PaperTrading);
|
||||
}
|
||||
|
||||
private async Task ManageNewPositions()
|
||||
{
|
||||
var positions = GetPositions(PositionStatus.New);
|
||||
|
||||
_logger.LogInformation("New positions count : {0} ", positions.Count());
|
||||
|
||||
foreach (var position in positions)
|
||||
{
|
||||
_logger.LogInformation("Managing position: {0} - Date: {1} - Direction: {2} - Ticker: {3}", position.Identifier, position.Date, position.OriginDirection, position.Ticker);
|
||||
position.Status = PositionStatus.Updating;
|
||||
_tradingService.UpdatePosition(position);
|
||||
|
||||
// Update status if position is open since to long
|
||||
if (position.Date < DateTime.UtcNow.AddDays(-2))
|
||||
{
|
||||
position.Status = PositionStatus.Canceled;
|
||||
_tradingService.UpdatePosition(position);
|
||||
_logger.LogInformation($"|_ Position is now Canceled");
|
||||
continue;
|
||||
}
|
||||
|
||||
var account = await _accountService.GetAccount(position.AccountName, false, false);
|
||||
if (!(await _exchangeService.GetOpenOrders(account, position.Ticker)).Any())
|
||||
{
|
||||
position.Status = PositionStatus.Canceled;
|
||||
_tradingService.UpdatePosition(position);
|
||||
_logger.LogInformation($"|_ Position is now Canceled - Position close from exchange");
|
||||
continue;
|
||||
}
|
||||
|
||||
var quantityInPosition = await _exchangeService.GetQuantityInPosition(account, position.Ticker);
|
||||
|
||||
if (quantityInPosition <= 0)
|
||||
{
|
||||
position.Status = PositionStatus.New;
|
||||
_logger.LogInformation("|_ Position is currently waiting for filling");
|
||||
}
|
||||
else
|
||||
{
|
||||
position.Open.SetStatus(TradeStatus.Filled);
|
||||
position.Status = PositionStatus.PartiallyFilled;
|
||||
_logger.LogInformation($"|_ Position is now PartiallyFilled");
|
||||
}
|
||||
|
||||
_tradingService.UpdatePosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Managing.Api.Workers/Workers/PricesBaseWorker.cs
Normal file
40
src/Managing.Api.Workers/Workers/PricesBaseWorker.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public abstract class PricesBaseWorker<T> : BaseWorker<T> where T : class
|
||||
{
|
||||
private readonly IPricesService _pricesService;
|
||||
private readonly IStatisticService _statisticService;
|
||||
private readonly Timeframe _timeframe;
|
||||
|
||||
public PricesBaseWorker(
|
||||
ILogger<T> logger,
|
||||
IPricesService pricesService,
|
||||
IWorkerService workerService,
|
||||
IStatisticService statisticService,
|
||||
TimeSpan delay,
|
||||
WorkerType workerType,
|
||||
Timeframe timeframe) : base(
|
||||
workerType,
|
||||
logger,
|
||||
delay,
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_pricesService = pricesService;
|
||||
_statisticService = statisticService;
|
||||
_timeframe = timeframe;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
var tickers = _statisticService.GetTickers();
|
||||
|
||||
foreach (var ticker in tickers)
|
||||
{
|
||||
await _pricesService.UpdatePrice(TradingExchanges.Evm, ticker, _timeframe);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PricesFifteenMinutesWorker : PricesBaseWorker<PricesFifteenMinutesWorker>
|
||||
{
|
||||
public PricesFifteenMinutesWorker(
|
||||
ILogger<PricesFifteenMinutesWorker> logger,
|
||||
IPricesService pricesService,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
logger,
|
||||
pricesService,
|
||||
workerService,
|
||||
statisticService,
|
||||
TimeSpan.FromMinutes(1),
|
||||
WorkerType.PriceFifteenMinutes,
|
||||
Timeframe.FifteenMinutes
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
23
src/Managing.Api.Workers/Workers/PricesFiveMinutesWorker.cs
Normal file
23
src/Managing.Api.Workers/Workers/PricesFiveMinutesWorker.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PricesFiveMinutesWorker : PricesBaseWorker<PricesFiveMinutesWorker>
|
||||
{
|
||||
public PricesFiveMinutesWorker(
|
||||
ILogger<PricesFiveMinutesWorker> logger,
|
||||
IPricesService pricesService,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
logger,
|
||||
pricesService,
|
||||
workerService,
|
||||
statisticService,
|
||||
TimeSpan.FromMinutes(2.5),
|
||||
WorkerType.PriceFiveMinutes,
|
||||
Timeframe.FiveMinutes
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
23
src/Managing.Api.Workers/Workers/PricesFourHoursWorker.cs
Normal file
23
src/Managing.Api.Workers/Workers/PricesFourHoursWorker.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PricesFourHoursWorker : PricesBaseWorker<PricesFourHoursWorker>
|
||||
{
|
||||
public PricesFourHoursWorker(
|
||||
ILogger<PricesFourHoursWorker> logger,
|
||||
IPricesService pricesService,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
logger,
|
||||
pricesService,
|
||||
workerService,
|
||||
statisticService,
|
||||
TimeSpan.FromHours(2),
|
||||
WorkerType.PriceFourHour,
|
||||
Timeframe.FourHour
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
23
src/Managing.Api.Workers/Workers/PricesOneDayWorker.cs
Normal file
23
src/Managing.Api.Workers/Workers/PricesOneDayWorker.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PricesOneDayWorker : PricesBaseWorker<PricesOneDayWorker>
|
||||
{
|
||||
public PricesOneDayWorker(
|
||||
ILogger<PricesOneDayWorker> logger,
|
||||
IPricesService pricesService,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
logger,
|
||||
pricesService,
|
||||
workerService,
|
||||
statisticService,
|
||||
TimeSpan.FromHours(12),
|
||||
WorkerType.PriceOneDay,
|
||||
Timeframe.OneDay
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
22
src/Managing.Api.Workers/Workers/PricesOneHourWorker.cs
Normal file
22
src/Managing.Api.Workers/Workers/PricesOneHourWorker.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class PricesOneHourWorker : PricesBaseWorker<PricesOneHourWorker>
|
||||
{
|
||||
public PricesOneHourWorker(
|
||||
ILogger<PricesOneHourWorker> logger,
|
||||
IPricesService pricesService,
|
||||
IStatisticService statisticService,
|
||||
IWorkerService workerService) : base(
|
||||
logger,
|
||||
pricesService,
|
||||
workerService,
|
||||
statisticService,
|
||||
TimeSpan.FromMinutes(30),
|
||||
WorkerType.PriceOneHour,
|
||||
Timeframe.OneHour)
|
||||
{
|
||||
}
|
||||
}
|
||||
34
src/Managing.Api.Workers/Workers/SpotlightWorker.cs
Normal file
34
src/Managing.Api.Workers/Workers/SpotlightWorker.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using Managing.Common;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class SpotlightWorker : BaseWorker<SpotlightWorker>
|
||||
{
|
||||
private readonly IStatisticService _statisticService;
|
||||
|
||||
public SpotlightWorker(
|
||||
ILogger<SpotlightWorker> logger,
|
||||
IWorkerService workerService,
|
||||
IStatisticService statisticService) : base(
|
||||
Enums.WorkerType.Spotlight,
|
||||
logger,
|
||||
TimeSpan.FromMinutes(5),
|
||||
workerService)
|
||||
{
|
||||
_statisticService = statisticService;
|
||||
}
|
||||
|
||||
protected async override Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _statisticService.UpdateSpotlight();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Enable to update spotlight", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/Managing.Api.Workers/Workers/TopVolumeTickerWorker.cs
Normal file
28
src/Managing.Api.Workers/Workers/TopVolumeTickerWorker.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class TopVolumeTickerWorker : BaseWorker<TopVolumeTickerWorker>
|
||||
{
|
||||
private readonly IStatisticService _statisticService;
|
||||
private static readonly WorkerType _workerType = WorkerType.TopVolumeTicker;
|
||||
|
||||
public TopVolumeTickerWorker(
|
||||
ILogger<TopVolumeTickerWorker> logger,
|
||||
IWorkerService workerService,
|
||||
IStatisticService statisticService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromHours(12),
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_statisticService = statisticService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await _statisticService.UpdateTopVolumeTicker(TradingExchanges.Evm, 10);
|
||||
}
|
||||
}
|
||||
29
src/Managing.Api.Workers/Workers/TraderWatcher.cs
Normal file
29
src/Managing.Api.Workers/Workers/TraderWatcher.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Workers.Abstractions;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Workers.Workers;
|
||||
|
||||
public class TraderWatcher : BaseWorker<FeeWorker>
|
||||
{
|
||||
private readonly ITradingService _tradingService;
|
||||
private static readonly WorkerType _workerType = WorkerType.TraderWatcher;
|
||||
|
||||
public TraderWatcher(
|
||||
ILogger<FeeWorker> logger,
|
||||
ITradingService tradingService,
|
||||
IWorkerService workerService) : base(
|
||||
_workerType,
|
||||
logger,
|
||||
TimeSpan.FromSeconds(120),
|
||||
workerService
|
||||
)
|
||||
{
|
||||
_tradingService = tradingService;
|
||||
}
|
||||
|
||||
protected override async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await _tradingService.WatchTrader();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user