实时持仓服务,资金计算
This commit is contained in:
@@ -15,10 +15,12 @@ using YLErp.Abstract;
|
||||
using YLErp.BLL;
|
||||
using YLErp.BLL.Eod;
|
||||
using YLErp.Cache;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.Helpers;
|
||||
using YLErp.Model;
|
||||
using YLErp.Modules;
|
||||
using YLErp.Modules.ClientModule;
|
||||
using YLErp.Modules.EodModule.QueryModule;
|
||||
|
||||
namespace RealTimeCalcPositionService
|
||||
{
|
||||
@@ -26,11 +28,16 @@ namespace RealTimeCalcPositionService
|
||||
{
|
||||
private readonly IYcLogger _logger;
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private IKafkaProduce kafkaProduceHelper;
|
||||
private string onRspAccountCapitalTopicTopic = string.Empty;
|
||||
private Dictionary<int, string> clientDic = new Dictionary<int, string>();
|
||||
private IYLCache _yLCache;
|
||||
public ClientNoDMABalanceTask(IYLCache yLCache)
|
||||
public ClientNoDMABalanceTask(IKafkaProduce kafkaProduce, IYLCache yLCache)
|
||||
{
|
||||
_logger = LogFactory.GetLogger("ClientNoDMABalanceTask");
|
||||
_yLCache= yLCache;
|
||||
onRspAccountCapitalTopicTopic = Environment.GetEnvironmentVariable("KafkaConfig_OnRspAccountCapitalTopic");
|
||||
kafkaProduceHelper = kafkaProduce;
|
||||
_yLCache = yLCache;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -49,27 +56,58 @@ namespace RealTimeCalcPositionService
|
||||
try
|
||||
{
|
||||
using var clientDb = new ClientDBContext();
|
||||
var clients= clientDb.client.Where(x=>x.SwapTradeType==0).ToList();
|
||||
var clients= clientDb.client.ToList();
|
||||
//系统交易日
|
||||
var valuedate = valuedateBLL.ValueDate;
|
||||
foreach (var client in clients)
|
||||
var clientSettles = new RealTimeClientBanlanceService(new OptUserInfo(0, "实时客户资金服务", OptUserFrom.Service)).GetBalances();
|
||||
foreach (var cb in clientSettles)
|
||||
{
|
||||
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
|
||||
Result result = new Result();
|
||||
try
|
||||
{
|
||||
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)
|
||||
var obj = new ClientBalanceForTrsResponse
|
||||
{
|
||||
TotalAmountTotal = cb.RoundedTotalAmount,
|
||||
AvailableAmount = Math.Round(cb.AvailableAmount, 2),
|
||||
PositionPv = cb.RoundedPositionPv,
|
||||
PositionPnl = cb.RoundedPositionPnl,
|
||||
DaliyPnl = Math.Round(cb.DaliyPnl, 2),
|
||||
ClientId = cb.ClientId,
|
||||
ClientType = cb.ClientType,
|
||||
Credit = cb.TotalCredit
|
||||
};
|
||||
result.success = true;
|
||||
result.obj = obj;
|
||||
if (_yLCache != null)
|
||||
{
|
||||
_yLCache.StringSet<ClientBalanceForTrsResponse>("ClientBalance:" + cb.ClientId, obj);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_yLCache.StringSet<ClientBalanceForTrsResponse>("ClientBalance:" + cb.ClientId, obj);
|
||||
result.msg = ex.Message;
|
||||
result.success = false;
|
||||
}
|
||||
string resultStr = JsonConvert.SerializeObject(result);
|
||||
string newEncryStr = DataProtectHelper.Encrypt(resultStr);
|
||||
bool needProduce = false;
|
||||
if (clientDic.TryGetValue(cb.ClientId, out string encryStr))
|
||||
{
|
||||
if (encryStr != newEncryStr)
|
||||
{
|
||||
needProduce = true;
|
||||
clientDic[cb.ClientId] = newEncryStr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clientDic.Add(cb.ClientId, newEncryStr);
|
||||
needProduce = true;
|
||||
}
|
||||
if (needProduce)
|
||||
{
|
||||
kafkaProduceHelper.Produce(onRspAccountCapitalTopicTopic, resultStr);
|
||||
}
|
||||
}
|
||||
Thread.Sleep(3000);
|
||||
|
||||
Reference in New Issue
Block a user