Exemplo n.º 1
0
        private static void checkAggregateOrders(IList<IOrder> orderList, bool netting)
        {
            int childCount = 0;
            int wrongStatusCount = 0;
            string err = "";

            if (orderList != null)
            {
                foreach (Order order in orderList)
                {
                    if (order.IsAggregateOrder)
                    {
                        // Only add to Aggregated orders that are not yet approved and not aggregated themselves
                        if (order.Status == OrderStati.New && order.parentOrder == null)
                        {
                            OrderSearchKey SearchKey = new OrderSearchKey(order, netting);
                            if (!aggregatedOrders.ContainsKey(SearchKey))
                            {
                                aggregatedOrders.Add(SearchKey, order);
                                aggregatedOrderKeys.Add(SearchKey);
                                // how many children?
                                if (netting)
                                {
                                    SearchKey.Count = order.ChildOrders.Count;
                                }
                            }
                            else
                            {
                                //TODO -> Delete aggregate order and orphan the children
                            }
                        }
                        else
                            wrongStatusCount++;
                    }
                    else
                    {
                        childCount++;
                    }
                }

                if (childCount > 0)
                {
                    err = string.Format("{0} child orders were found.", childCount.ToString());
                }

                if (wrongStatusCount > 0)
                {
                    err = err + (err != "" ? "\n" : "") + string.Format("{0} child orders were found.", childCount.ToString());

                }
                if (err != "")
                {
                    throw new ApplicationException("Can not do aggregation:/n" + err);
                }
            }
        }
Exemplo n.º 2
0
 private static bool getKeyFromAggregatedOrders(ref OrderSearchKey searchKey)
 {
     bool success = false;
     foreach (var item in aggregatedOrders)
     {
         if (item.Key.Equals(searchKey))
         {
             searchKey = item.Key;
             success = true;
             break;
         }
     }
     return success;
 }
Exemplo n.º 3
0
 private static OrderSearchKey addToList(Order newOrder, IOrderRouteMapper routeMapper, bool aggrOnStg, bool netting)
 {
     int index;
     OrderSearchKey SearchKey = new OrderSearchKey(newOrder, netting);
     if (!getKeyFromAggregatedOrders(ref SearchKey))
     {
         if (!(newOrder.parentOrder == null))
         {
             aggregatedOrders.Add(SearchKey, newOrder.parentOrder);
         }
         else
         {
             switch (newOrder.OrderType)
             {
                 case OrderTypes.Monetary:
                     if (aggrOnStg)
                     {
                         if (netting)
                             aggregatedOrders.Add(SearchKey, new StgMonetaryOrder((IStgMonetaryOrder)newOrder));
                         else
                             aggregatedOrders.Add(SearchKey, new StgMonetaryOrder(getClearingAccount(newOrder), (IAggregateMonetaryOrder)newOrder, routeMapper));
                     }
                     else
                         aggregatedOrders.Add(SearchKey, new AggregateMonetaryOrder(getClearingAccount(newOrder), (IMonetaryOrder)newOrder));
                     break;
                 case OrderTypes.SizeBased:
                     if (aggrOnStg)
                     {
                         if (netting)
                             aggregatedOrders.Add(SearchKey, new StgSizeOrder((IStgSizeOrder)newOrder));
                         else
                             aggregatedOrders.Add(SearchKey, new StgSizeOrder(getClearingAccount(newOrder), (IAggregateSizeOrder)newOrder, routeMapper));
                     }
                     else
                         aggregatedOrders.Add(SearchKey, new AggregateSizeOrder(getClearingAccount(newOrder), (IOrderSizeBased)newOrder));
                     break;
                 default:
                     //OrderTypes.AmountBased:
                     if (aggrOnStg)
                     {
                         if (netting)
                             aggregatedOrders.Add(SearchKey, new StgAmtOrder((IStgAmtOrder)newOrder));
                         else
                             aggregatedOrders.Add(SearchKey, new StgAmtOrder(getClearingAccount(newOrder), (IAggregateAmtOrder)newOrder, routeMapper));
                     }
                     else
                         aggregatedOrders.Add(SearchKey, new AggregateAmtOrder(getClearingAccount(newOrder), (IOrderAmountBased)newOrder));
                     break;
             }
         }
         aggregatedOrderKeys.Add(SearchKey);
     }
     else
     {
         // return same Key -> stored in collection
         int i = aggregatedOrderKeys.IndexOf(SearchKey);
         aggregatedOrderKeys[i] = SearchKey;
     }
     return SearchKey;
 }