126 lines
4.8 KiB
C#
126 lines
4.8 KiB
C#
using BaseOUDAL;
|
|
using YLErp.BLL;
|
|
using YLErp.Model;
|
|
|
|
namespace YLErp.Modules.EodModule
|
|
{
|
|
public class EodSwapPositionMannualService : YLBaseService
|
|
{
|
|
public EodSwapPositionMannualService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
public SearchListResult<eod_trade_position_swap_mannual> SearchPositionList(TradeSpanReq req)
|
|
{
|
|
var query = SearchPositionQuery(req);
|
|
var result = query.ToSearchList(req);
|
|
|
|
var clientDataSource = DataCacheProvider.GetClientDataSource();
|
|
var underlyDataSource = DataCacheProvider.GetUnderlyingDataSource();
|
|
var varietyDataSource = DataCacheProvider.GetVarietyDataSource();
|
|
var eodCurrencyRate = new EodCurrencyRateService(UserInfo);
|
|
|
|
foreach (var item in result.rows)
|
|
{
|
|
var client = clientDataSource.GetData(item.ClientId);
|
|
var underlying = underlyDataSource.GetData(item.UnderlyingCode);
|
|
var variety = varietyDataSource.GetData(underlying.UnderlyingTypeId);
|
|
|
|
item.ClientName = client.Name;
|
|
item.UnderlyingName = underlying.UnderlyingName;
|
|
var currencyRate = eodCurrencyRate.GetCurrencyRate(variety.QuoteCurrency, client.SettlementCurrency, item.ValueDate, seekPreday: item.ValueDate == valuedateBLL.ValueDate);
|
|
item.CurrencyRate = currencyRate;
|
|
|
|
item.Notional *= -1;
|
|
item.TotalFee *= -1;
|
|
item.AnnualFee *= -1;
|
|
item.FloatingWinLoss *= -1;
|
|
item.PositionPnl *= -1;
|
|
|
|
item.QuotePositionPnl = item.PositionPnl * currencyRate;
|
|
item.TradeAmount = item.Notional / underlying.CountRatio;
|
|
}
|
|
|
|
var gsum = new EodPositionSwapMannualSum();
|
|
|
|
if (query.Any())
|
|
{
|
|
gsum.TotalFeeSum = result.rows.Sum(x => x.TotalFee);
|
|
gsum.MarginSum = result.rows.Sum(x => x.Margin);
|
|
gsum.PositionPnlSum = result.rows.Sum(x => x.PositionPnl);
|
|
gsum.QuotePositionPnlSum = result.rows.Sum(x => x.QuotePositionPnl);
|
|
}
|
|
result.Sum = gsum;
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<eod_trade_position_swap_mannual> SearchPositionListAll(TradeSpanReq req)
|
|
{
|
|
var query = SearchPositionQuery(req);
|
|
var list = query.ToList();
|
|
|
|
var clientDataSource = DataCacheProvider.GetClientDataSource();
|
|
var underlyDataSource = DataCacheProvider.GetUnderlyingDataSource();
|
|
var varietyDataSource = DataCacheProvider.GetVarietyDataSource();
|
|
var eodCurrencyRate = new EodCurrencyRateService(UserInfo);
|
|
|
|
foreach (var item in list)
|
|
{
|
|
var client = clientDataSource.GetData(item.ClientId);
|
|
var underlying = underlyDataSource.GetData(item.UnderlyingCode);
|
|
var variety = varietyDataSource.GetData(underlying.UnderlyingTypeId);
|
|
item.ClientName = client.Name;
|
|
item.UnderlyingName = underlying.UnderlyingName;
|
|
var currencyRate = eodCurrencyRate.GetCurrencyRate(variety.QuoteCurrency, client.SettlementCurrency, item.ValueDate, seekPreday: item.ValueDate == valuedateBLL.ValueDate);
|
|
|
|
item.Notional *= -1;
|
|
item.TotalFee *= -1;
|
|
item.AnnualFee *= -1;
|
|
item.FloatingWinLoss *= -1;
|
|
item.PositionPnl *= -1;
|
|
|
|
item.CurrencyRate = currencyRate;
|
|
item.QuotePositionPnl = item.PositionPnl * currencyRate;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private IQueryable<eod_trade_position_swap_mannual> SearchPositionQuery(TradeSpanReq req)
|
|
{
|
|
var query = from trm in DbContext.eod_trade_position_swap_mannual
|
|
select trm;
|
|
|
|
if (req.ClientId > 0)
|
|
{
|
|
query = query.Where(x => x.ClientId == req.ClientId);
|
|
}
|
|
if (req.ValueDate != null)
|
|
{
|
|
query = query.Where(x => x.ValueDate == req.ValueDate);
|
|
}
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "ValueDate,id";
|
|
req.sord = "desc";
|
|
}
|
|
return query;
|
|
}
|
|
|
|
public int SearchPositionCount(int clientId, DateTime valueDate)
|
|
{
|
|
var query = from trm in DbContext.eod_trade_position_swap_mannual
|
|
select trm;
|
|
|
|
if (clientId > 0)
|
|
{
|
|
query = query.Where(x => x.ClientId == clientId);
|
|
}
|
|
query = query.Where(x => x.ValueDate == valueDate);
|
|
var result = query.Count();
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|