标的交易&风控
This commit is contained in:
@@ -20,51 +20,28 @@ namespace YLErp.Modules.ExchangeTradeModule
|
||||
public void ResetExchangeTradePosition()
|
||||
{
|
||||
var valueDate = SystemValueDate;
|
||||
var lastDate = EodOperationBase.GetLastSettlementDate(valueDate, false);
|
||||
List<string> tradetypes = new List<string> { "股票", "商品期货", "商品现货", "场内期权", "利率债", "信用债", "其它债券" };
|
||||
var eodQuery = from et in DbContext.eod_trade_position.AsNoTracking()
|
||||
where et.ValueDate == lastDate && tradetypes.Contains(et.TradeType)
|
||||
select new TradePositionEx
|
||||
{
|
||||
UnderlyingId = et.UnderlyingId,
|
||||
TradeType = et.TradeType,
|
||||
BookId = et.BookId,
|
||||
InstrumentCode = et.ExchangeOptionCode,
|
||||
UnderlyingCode = et.UnderlyingCode,
|
||||
Position = et.Amount,
|
||||
PositionCost = et.Cost,
|
||||
BuySell = et.PositionType
|
||||
};
|
||||
|
||||
var positionList = eodQuery.ToList();
|
||||
|
||||
//如果当天未收盘
|
||||
if (valueDate != lastDate)
|
||||
{
|
||||
var tdQuery = from trad in DbContext.ExchangeTrade.AsNoTracking()
|
||||
where trad.TradeDate > lastDate && trad.TradeDate <= valueDate && trad.IsValid
|
||||
select new TdTradePositionEx
|
||||
{
|
||||
TradeType = trad.TradeType,
|
||||
BookId = trad.AssetBookId,
|
||||
InstrumentCode = trad.OptionCode,
|
||||
Position = trad.Notional,
|
||||
BuySell = trad.TradeSide,
|
||||
UnderlyingCode = trad.UnderlyingCode,
|
||||
TradeSinglePrice = trad.TradeSinglePrice
|
||||
};
|
||||
|
||||
var tdDatas = tdQuery.ToArray();
|
||||
positionList.AddRange(tdDatas);
|
||||
}
|
||||
var tdQuery = from trad in DbContext.ExchangeTrade.AsNoTracking()
|
||||
where trad.IsValid
|
||||
select new TdTradePositionEx
|
||||
{
|
||||
TradeType = trad.TradeType,
|
||||
BookId = trad.AssetBookId,
|
||||
InstrumentCode = trad.OptionCode,
|
||||
Position = trad.Notional,
|
||||
BuySell = trad.TradeSide,
|
||||
UnderlyingCode = trad.UnderlyingCode,
|
||||
TradeSinglePrice = trad.TradeSinglePrice
|
||||
};
|
||||
|
||||
var positionList = tdQuery.ToList();
|
||||
var dic = new Dictionary<string, TradePosition>(positionList.Count);
|
||||
|
||||
foreach (var n in positionList)
|
||||
{
|
||||
var tradeType1 = TradeHelper.GetTradeType1(n.TradeType);
|
||||
var positionType = TradeHelper.GetPositionType(n.BuySell);
|
||||
var key = $"{n.BookId}^{(int)tradeType1}^{(int)positionType}^{n.UnderlyingCode}^{n.InstrumentCode}";
|
||||
var key = $"{n.BookId}^{(int)tradeType1}^{n.UnderlyingCode}^{n.InstrumentCode}";
|
||||
var position = n.IsEod ? n.Position : TradeHelper.GetPositionNotional(n.BuySell, n.Position);
|
||||
var positionCost = n.IsEod ? n.PositionCost : position * n.TradeSinglePrice;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user