private static void InitializeFilledAndMarginArgs(this AccountClass.Instrument instrument, bool isBuy, MarginAndQuantityResult unfilledArgs, MarginAndQuantityResult filledArgs, MarginAndQuantityResult marginArgs) { var physicalInstrument = instrument as Physical.PhysicalInstrument; BuySellPair margin, quantity, partialMargin, partialQuantity; margin = new BuySellPair(instrument.TotalBuyMargin, instrument.TotalSellMargin); quantity = new BuySellPair(instrument.TotalBuyQuantity, instrument.TotalSellQuantity); if (physicalInstrument != null) { partialMargin = new BuySellPair(physicalInstrument.TotalBuyMarginForPartialPaymentPhysicalOrder, physicalInstrument.TotalSellMarginForPartialPaymentPhysicalOrder); partialQuantity = new BuySellPair(physicalInstrument.TotalBuyLotBalanceForPartialPaymentPhysicalOrder, physicalInstrument.TotalSellLotBalanceForPartialPaymentPhysicalOrder); } else { partialMargin = BuySellPair.Empty; partialQuantity = BuySellPair.Empty; } filledArgs.Add(isBuy, margin, quantity, partialMargin, partialQuantity); marginArgs.Add(isBuy, unfilledArgs); marginArgs.Add(isBuy, margin, quantity, partialMargin, partialQuantity); }
private static decimal CalculateNecessary(AccountClass.Instrument instrument, bool isBuy, MarginAndQuantityResult marginArgs, MarginAndQuantityResult filledArgs) { MarginAndQuantityResult necessaryParams = new MarginAndQuantityResult(); necessaryParams.Add(isBuy, marginArgs, filledArgs); decimal netNecessary = 0m; decimal hedgeNecessary = 0m; decimal partialPaymentPhysicalNecessary = 0m; if (necessaryParams.PartialQuantity.Sell > 0) { partialPaymentPhysicalNecessary = necessaryParams.PartialMargin.Sell; } else if (necessaryParams.PartialQuantity.Buy > 0) { partialPaymentPhysicalNecessary = necessaryParams.PartialMargin.Buy; } instrument.CalculateNetAndHedgeNecessary(necessaryParams.Margin.Buy, necessaryParams.Margin.Sell, necessaryParams.Quantity.Buy, necessaryParams.Quantity.Sell, partialPaymentPhysicalNecessary, out netNecessary, out hedgeNecessary); return(netNecessary + hedgeNecessary); }