92 lines
3.3 KiB
C#
92 lines
3.3 KiB
C#
using BaseOUDAL;
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
using Newtonsoft.Json;
|
|
using Org.BouncyCastle.Ocsp;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using YLErp;
|
|
using YLErp.Abstract;
|
|
using YLErp.BLL;
|
|
using YLErp.BLL.Eod;
|
|
using YLErp.Cache;
|
|
using YLErp.Helpers;
|
|
using YLErp.Model;
|
|
using YLErp.Modules;
|
|
using YLErp.Modules.ClientModule;
|
|
|
|
namespace RealTimeCalcPositionService
|
|
{
|
|
public class ClientNoDMABalanceTask : IHostedService, IDisposable
|
|
{
|
|
private readonly IYcLogger _logger;
|
|
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
|
private IYLCache _yLCache;
|
|
public ClientNoDMABalanceTask(IYLCache yLCache)
|
|
{
|
|
_logger = LogFactory.GetLogger("ClientNoDMABalanceTask");
|
|
_yLCache= yLCache;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
_cts.Dispose();
|
|
}
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_logger.Info("ClientNoDMABalanceTask task is starting.");
|
|
Task.Run(() => ExecuteTask(_cts.Token), _cts.Token);
|
|
return Task.CompletedTask;
|
|
}
|
|
private void ExecuteTask(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
using var clientDb = new ClientDBContext();
|
|
var clients= clientDb.client.Where(x=>x.SwapTradeType==0).ToList();
|
|
//系统交易日
|
|
var valuedate = valuedateBLL.ValueDate;
|
|
foreach (var client in clients)
|
|
{
|
|
var cb = ClientAssetDataService.GetClientLatestBalance(null, valuedate, client.id, false, false, false);
|
|
cb.AvailableAmount = cb.AmountFund + cb.TotalCredit + cb.PayableMargin + cb.GuaranteesTotalAmount;
|
|
var obj = new ClientBalanceForTrsResponse
|
|
{
|
|
TotalAmountTotal = cb.RoundedTotalAmountTotal,
|
|
AvailableAmount = Math.Round(cb.AvailableAmount, 2),
|
|
PositionPv = cb.RoundedPositionPv,
|
|
PositionPnl = cb.RoundedPositionPnl,
|
|
DaliyPnl = Math.Round(cb.DaliyPnl, 2),
|
|
ClientId = client.id,
|
|
ClientType = cb.ClientType,
|
|
Credit = cb.TotalCredit
|
|
};
|
|
if (_yLCache != null)
|
|
{
|
|
_yLCache.StringSet<ClientBalanceForTrsResponse>("ClientBalance:" + cb.ClientId, obj);
|
|
}
|
|
}
|
|
Thread.Sleep(3000);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "普通实时客户资金服务异常:" + ex.Message);
|
|
}
|
|
|
|
}
|
|
}
|
|
public async Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_logger.Info("ClientNoDMABalanceTask task is stopping.");
|
|
_cts.Cancel();
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|