Ejemplo n.º 1
0
        internal StgSizeOrder(IStgAmtOrder childOrder, InstrumentSize value, Price price, IOrderRouteMapper routeMapper)
            : base(childOrder.Account, value, false)
        {
            // Used for TypeConversion

            // Some check
            if (childOrder.ParentOrder != null)
                throw new ApplicationException("This order has a parent order and can no longer be converted.");

            this.IsTypeConverted = true;
            setInitialValues(routeMapper);
            this.price = price;
            this.ChildOrders.Add(childOrder);
            childOrder.Approve();
            //this.CommissionDetails = childOrder.CommissionDetails;
            this.exRate = childOrder.ExRate;
            Validate();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="childOrder">Child order to create for this stichting order</param>
 /// <param name="routeMapper">Route information</param>
 public StgAmtOrder(IAccountTypeInternal account, IAggregateAmtOrder childOrder, IOrderRouteMapper routeMapper)
     : base(account, (IOrderAmountBased)childOrder)
 {
     setInitialValues(routeMapper);
 }
Ejemplo n.º 3
0
 private void setInitialValues(IOrderRouteMapper routeMapper)
 {
     this.Route = routeMapper.GetRoute(this);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="value">Value of the order</param>
 /// <param name="tradedInstrument">The traded instrument</param>
 /// <param name="routeMapper">Route information</param>
 public StgAmtOrder(IAccountTypeInternal account, Money value, IInstrument tradedInstrument, IOrderRouteMapper routeMapper)
     : base(account, value, tradedInstrument)
 {
     setInitialValues(routeMapper);
     setServiceChargeForAmountBasedOrder();
 }
Ejemplo n.º 5
0
        public virtual IStgSizeOrder ConvertBondOrder(Price price, DateTime settlementDate, IOrderRouteMapper routeMapper)
        {
            if (TradedInstrument.SecCategory.Key != SecCategories.Bond)
                throw new ApplicationException("This is not a bond order.");

            IBond bond = (IBond)TradedInstrument;
            if (bond.DoesPayInterest)
            {
                // Calculate backwards the number of bonds
                InstrumentSize value = bond.CalculateSizeBackwards(Amount, price, settlementDate);
                StgSizeOrder convertedOrder = new StgSizeOrder(this, value, price, routeMapper);
                AccruedInterestDetails calc = bond.AccruedInterest(value, settlementDate, null);
                if (calc.IsRelevant)
                    convertedOrder.AccruedInterest = calc.AccruedInterest;
                return convertedOrder;
            }
            else
                return (IStgSizeOrder)this.Convert(price, routeMapper);
        }
Ejemplo n.º 6
0
 public new virtual ISecurityOrder Convert(Price price, IOrderRouteMapper routeMapper)
 {
     InstrumentSize value = Amount.CalculateSize(price);
     return new StgSizeOrder(this, value, price, routeMapper);
 }
Ejemplo n.º 7
0
 public new virtual ISecurityOrder Convert(Price price, IOrderRouteMapper routeMapper)
 {
     Money value = this.Value.CalculateAmount(price);
     return new StgAmtOrder(this, value);
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
        public static IList<IOrder> AggregateOrdersForStichting(IList<IOrder> aggregateUnApprovedStgOrders, IList<IOrder> unStgAggregatedApprovedOrders, IOrderRouteMapper routeMapper, out string message)
        {
            aggregatedOrders = new Dictionary<OrderSearchKey, IOrder>();
            aggregatedOrderKeys = new List<OrderSearchKey>();
            IList<IOrder> result = new List<IOrder>();
            OrderSearchKey SearchKey = null;
            //IList unStgAggregatedApprovedOrders = new Order.DataAccessLayer().GetUnAggregatedOrders(true);
            int count = 0;

            if (unStgAggregatedApprovedOrders == null || unStgAggregatedApprovedOrders.Count == 0)
            {
                message = "";
                return null;
            }

            checkAggregateOrders(aggregateUnApprovedStgOrders, false);

            foreach (Order newOrder in unStgAggregatedApprovedOrders)
            {
                if (newOrder.parentOrder == null)
                {
                    if (newOrder.Approved)
                    {
                        SearchKey = addToList(newOrder, routeMapper, true, false);
                        ((IOrder)aggregatedOrders[SearchKey]).ChildOrders.Add(newOrder);
                        SearchKey.Updated = true;
                    }
                    else
                        count++;
                }
            }

            message = "";
            if (count > 0)
                message = string.Format("{0} orders could not be aggregated since they were not approved.", count.ToString());
            //saveAggregatedOrders();

            IStgOrder orderToSave;
            for (int i = 0; i < aggregatedOrderKeys.Count; i++)
            {
                OrderSearchKey key = (OrderSearchKey)aggregatedOrderKeys[i];
                if (key.Updated)
                {
                    orderToSave = (IStgOrder)aggregatedOrders[key];
                    // Calculate Service Charge
                    if (((IOrder)orderToSave).OrderType == OrderTypes.AmountBased)
                    {
                        StgAmtOrder o = (StgAmtOrder)orderToSave;
                        o.setServiceChargeForAmountBasedOrder();
                    }
                    ((IOrder)orderToSave).Validate();
                    result.Add((IOrder)orderToSave);
                }
            }
            return result;
        }