public ProposedOrderLeg RemoveWorstPerforming(bool useLock = false) { double percentOfAverageForWorstLeg = double.MaxValue; ProposedOrderLeg leg = null; foreach (var legs in this.orderLegs.OrderByDescending(o => o.Key)) { double avgBuyRatio = legs.Value.Average(o => (double)o.ProposedBuyQuantity / (double)o.ProposedSellQuantity); var worstOrderLeg = legs.Value.OrderBy(o => (double)o.ProposedBuyQuantity / (double)o.ProposedSellQuantity).First(); if (worstOrderLeg.ProposedBuyQuantity > 0) { double percentOfAverage = ((double)worstOrderLeg.ProposedBuyQuantity / (double)worstOrderLeg.ProposedSellQuantity) / avgBuyRatio; if (percentOfAverage < percentOfAverageForWorstLeg) { percentOfAverageForWorstLeg = percentOfAverage; leg = worstOrderLeg; } } } if (leg != null) { if (!leg.Ask.IsBuy) { leg.SetBuyQuantity(-1 * leg.ProposedBuyQuantity, useLock: useLock); } else { leg.SetSellQuantity(-1 * leg.ProposedSellQuantity, useLock: useLock); } } return(leg); }
private long RebalanceOrderLegForSell(ProposedOrder propOrder, ProposedOrderLeg orderLeg, long buyQuantity, bool useLock = false) { long sellQuantityAdj = 0; if (!orderLeg.Ask.AllowPartialFill || orderLeg.ProposedSellQuantity < buyQuantity) { sellQuantityAdj = -1 * orderLeg.ProposedSellQuantity; } else { sellQuantityAdj = -1 * (orderLeg.ProposedSellQuantity - buyQuantity); } sellQuantityAdj = orderLeg.SetSellQuantity(sellQuantityAdj, useLock: useLock); return(sellQuantityAdj); }
public void RemoveOrderLeg(ProposedOrderLeg leg) { this.orderLegs[leg.LegLevel].Remove(leg); }