实时持仓服务,资金计算
This commit is contained in:
@@ -53,11 +53,11 @@ namespace YLErp.BLL.Eod
|
|||||||
/// 获取DMA资金
|
/// 获取DMA资金
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<ClientSettleBalance> GetDMABalances()
|
public IEnumerable<ClientSettleBalance> GetBalances()
|
||||||
{
|
{
|
||||||
|
|
||||||
using var clientDb = new ClientDBContext();
|
using var clientDb = new ClientDBContext();
|
||||||
var dmaClients = clientDb.client.Where(x => x.SwapTradeType == 1).ToList();
|
var dmaClients = clientDb.client.ToList();
|
||||||
var clientIds = dmaClients.Select(s => s.id);
|
var clientIds = dmaClients.Select(s => s.id);
|
||||||
return GetBanlances(clientIds, valuedateBLL.ValueDate, calcDate: valuedateBLL.ValueDate);
|
return GetBanlances(clientIds, valuedateBLL.ValueDate, calcDate: valuedateBLL.ValueDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ namespace YLErp.Modules.CalculationModule
|
|||||||
if (data.IsBond())
|
if (data.IsBond())
|
||||||
{
|
{
|
||||||
var bondPrice = EodPriceQueryService.GetBondPrice(valuedateBLL.ValueDate, data.UnderlyingCode);
|
var bondPrice = EodPriceQueryService.GetBondPrice(valuedateBLL.ValueDate, data.UnderlyingCode);
|
||||||
vobp = bondPrice.Vobp ?? 0;
|
vobp = bondPrice?.Vobp ?? 0;
|
||||||
var price = Convert.ToDecimal(bondPrice.ClosePrice);
|
var price = Convert.ToDecimal(bondPrice?.ClosePrice??0);
|
||||||
eodSwap.FloatingPnL = (price - item.PosiGrossPrice) * item.PosiQuantity * item.ContractSize * shortRatio * directionRatio;
|
eodSwap.FloatingPnL = (price - item.PosiGrossPrice) * item.PosiQuantity * item.ContractSize * shortRatio * directionRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ using YLErp.Abstract;
|
|||||||
using YLErp.BLL;
|
using YLErp.BLL;
|
||||||
using YLErp.BLL.Eod;
|
using YLErp.BLL.Eod;
|
||||||
using YLErp.Cache;
|
using YLErp.Cache;
|
||||||
|
using YLErp.DBModels;
|
||||||
using YLErp.Helpers;
|
using YLErp.Helpers;
|
||||||
using YLErp.Model;
|
using YLErp.Model;
|
||||||
using YLErp.Modules;
|
using YLErp.Modules;
|
||||||
using YLErp.Modules.ClientModule;
|
using YLErp.Modules.ClientModule;
|
||||||
|
using YLErp.Modules.EodModule.QueryModule;
|
||||||
|
|
||||||
namespace RealTimeCalcPositionService
|
namespace RealTimeCalcPositionService
|
||||||
{
|
{
|
||||||
@@ -26,11 +28,16 @@ namespace RealTimeCalcPositionService
|
|||||||
{
|
{
|
||||||
private readonly IYcLogger _logger;
|
private readonly IYcLogger _logger;
|
||||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
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;
|
private IYLCache _yLCache;
|
||||||
public ClientNoDMABalanceTask(IYLCache yLCache)
|
public ClientNoDMABalanceTask(IKafkaProduce kafkaProduce, IYLCache yLCache)
|
||||||
{
|
{
|
||||||
_logger = LogFactory.GetLogger("ClientNoDMABalanceTask");
|
_logger = LogFactory.GetLogger("ClientNoDMABalanceTask");
|
||||||
_yLCache= yLCache;
|
onRspAccountCapitalTopicTopic = Environment.GetEnvironmentVariable("KafkaConfig_OnRspAccountCapitalTopic");
|
||||||
|
kafkaProduceHelper = kafkaProduce;
|
||||||
|
_yLCache = yLCache;
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@@ -49,27 +56,58 @@ namespace RealTimeCalcPositionService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var clientDb = new ClientDBContext();
|
using var clientDb = new ClientDBContext();
|
||||||
var clients= clientDb.client.Where(x=>x.SwapTradeType==0).ToList();
|
var clients= clientDb.client.ToList();
|
||||||
//系统交易日
|
//系统交易日
|
||||||
var valuedate = valuedateBLL.ValueDate;
|
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;
|
cb.AvailableAmount = cb.AmountFund + cb.TotalCredit + cb.PayableMargin + cb.GuaranteesTotalAmount;
|
||||||
var obj = new ClientBalanceForTrsResponse
|
Result result = new Result();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
TotalAmountTotal = cb.RoundedTotalAmountTotal,
|
var obj = new ClientBalanceForTrsResponse
|
||||||
AvailableAmount = Math.Round(cb.AvailableAmount, 2),
|
{
|
||||||
PositionPv = cb.RoundedPositionPv,
|
TotalAmountTotal = cb.RoundedTotalAmount,
|
||||||
PositionPnl = cb.RoundedPositionPnl,
|
AvailableAmount = Math.Round(cb.AvailableAmount, 2),
|
||||||
DaliyPnl = Math.Round(cb.DaliyPnl, 2),
|
PositionPv = cb.RoundedPositionPv,
|
||||||
ClientId = client.id,
|
PositionPnl = cb.RoundedPositionPnl,
|
||||||
ClientType = cb.ClientType,
|
DaliyPnl = Math.Round(cb.DaliyPnl, 2),
|
||||||
Credit = cb.TotalCredit
|
ClientId = cb.ClientId,
|
||||||
};
|
ClientType = cb.ClientType,
|
||||||
if (_yLCache != null)
|
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);
|
Thread.Sleep(3000);
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"ylcms": "server=221.229.106.161;uid=roottest;pooling=true;port=20306;pwd=YieldChain!@#$2020;database=yltrs_ylcms;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
"ylcms": "server=139.196.109.225;uid=root;pooling=true;port=3306;pwd=Midnight001!@#$;database=yltrs_ylcms;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
||||||
"yladmin": "server=221.229.106.161;uid=roottest;pooling=true;port=20306;pwd=YieldChain!@#$2020;database=yltrs_admin;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
"yladmin": "server=139.196.109.225;uid=root;pooling=true;port=3306;pwd=Midnight001!@#$;database=yltrs_admin;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
||||||
"ylclient": "server=221.229.106.161;uid=roottest;pooling=true;port=20306;pwd=YieldChain!@#$2020;database=yltrs_client;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
"ylclient": "server=139.196.109.225;uid=root;pooling=true;port=3306;pwd=Midnight001!@#$;database=yltrs_client;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;",
|
||||||
"bondoms": "server=221.229.106.161;uid=roottest;pooling=true;port=20306;pwd=YieldChain!@#$2020;database=bond_oms;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;"
|
"bondoms": "server=139.196.109.225;uid=root;pooling=true;port=3306;pwd=Midnight001!@#$;database=bond_oms;charset=utf8;Allow User Variables=True;SslMode=none;Connection Timeout=30;IgnoreCommandTransaction=true;"
|
||||||
},
|
},
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"RunInterval": "1000",
|
"RunInterval": "1000",
|
||||||
@@ -36,19 +36,7 @@
|
|||||||
"HedgingAccountTopic": "ylHedgingAccountTopic", //对冲账户生产topic
|
"HedgingAccountTopic": "ylHedgingAccountTopic", //对冲账户生产topic
|
||||||
"ReqAccountCapitalTopic": "ReqAccountCapital", //账户资金请求topic
|
"ReqAccountCapitalTopic": "ReqAccountCapital", //账户资金请求topic
|
||||||
"OnRspAccountCapitalTopic": "OnRspAccountCapital", //账户资金请求返回topic
|
"OnRspAccountCapitalTopic": "OnRspAccountCapital", //账户资金请求返回topic
|
||||||
"ReqInterestRateSwapInsertTopic": "ReqInterestRateSwapInsert", //收益互换交易推送请求topic
|
|
||||||
"OnRspInterestRateSwapInsertTopic": "OnRspInterestRateSwapInsert", //收益互换交易推送请求响应topic
|
|
||||||
"OnRspInterestRateSwapInsertTopicGroupId": "OnRspInterestRateSwapInsertConsumer", //收益互换交易推送请求响应消费组
|
|
||||||
"AccountCapitalTopicGroupId": "YiLian_OnRspAccountCapitalConsumer", //账户资金消费组
|
"AccountCapitalTopicGroupId": "YiLian_OnRspAccountCapitalConsumer", //账户资金消费组
|
||||||
"ReqAssetSwapInsertTopic": "ReqAssetSwapInsert", //互换资产交易推送请求
|
|
||||||
"OnRspAssetSwapInsertTopic": "OnRspAssetSwapInsert", //互换资产交易推送请求响应
|
|
||||||
"OnRspAssetSwapInsertTopicGroupId": "OnRspAssetSwapInsertConsumer", //互换资产交易推送请求响应消费组
|
|
||||||
"ReqMarginInsertTopic": "ReqMarginInsert", //预付金交易推送请求
|
|
||||||
"OnRspMarginInsertTopic": "OnRspMarginInsert", //预付金交易推送请求响应
|
|
||||||
"OnRspMarginInsertTopicGroupId": "OnRspMarginInsertConsumer", //预付金交易推送请求响应消费组
|
|
||||||
"ReqAcctSwapTerminateTopic": "ReqAcctSwapTerminate", //平仓推送请求
|
|
||||||
"OnRspAcctSwapTerminateTopic": "OnRspAcctSwapTerminate", //平仓推送请求响应
|
|
||||||
"OnRspAcctSwapTerminateTopicGroupId": "OnRspAcctSwapTerminateConsumer", //平仓推送请求响应消费组
|
|
||||||
"ReqCalcBondTopic": "ReqCalcBond", //互换成交收益率计算器topic
|
"ReqCalcBondTopic": "ReqCalcBond", //互换成交收益率计算器topic
|
||||||
"OnRspCalcBondTopic": "OnRspCalcBond", //互换成交收益率计算器消费topic
|
"OnRspCalcBondTopic": "OnRspCalcBond", //互换成交收益率计算器消费topic
|
||||||
"OnRspCalcBondTopicGroupId": "OnRspCalcBondConsumer", //互换成交收益率计算器消费topic消费组
|
"OnRspCalcBondTopicGroupId": "OnRspCalcBondConsumer", //互换成交收益率计算器消费topic消费组
|
||||||
|
|||||||
Reference in New Issue
Block a user