Exemplo n.º 1
0
        public Order MakeOrder(Client client, ITradeable product, OrderType type, int count)
        {
            Order order = new Order();
            order.Client = client;
            order.Product = product;
            order.Type = type;
            order.Count = count;

            Order tempOrder = (Order)order.Clone();
            Order [] brokerOrders = new Order[brokers.Count];
            bool [] rtnCdes = new bool[brokers.Count];
            int modCount = order.Count;
            int idx = 0;
            int maxCount = 0;
            decimal minBrokerValue = 0;
            int brokerValueIdx = -1;

            while (modCount > 0)
            {
                tempOrder.Count = modCount;

                maxCount = 0;
                idx = 0;
                foreach (Broker broker in brokers)
                {
                    rtnCdes[idx] = broker.PrepareOrder(tempOrder, out brokerOrders[idx]);
                    if (rtnCdes[idx])
                    {
                        if (brokerOrders[idx].Count > maxCount)
                            maxCount = brokerOrders[idx].Count;
                    }

                    idx++;
                }

                if (maxCount == 0)
                    return order;

                minBrokerValue = decimal.MaxValue;
                brokerValueIdx = -1;
                for(idx = 0; idx < brokers.Count; ++idx)
                {
                    if (rtnCdes[idx])
                    {
                        if (brokerOrders[idx].Count == maxCount)
                        {
                            if (brokerOrders[idx].BrokerValue < minBrokerValue)
                            {
                                minBrokerValue = brokerOrders[idx].BrokerValue;
                                brokerValueIdx = idx;
                            }
                        }
                    }
                }

                if (brokerValueIdx == -1)
                    return order;

                brokers[brokerValueIdx].AddOrder(brokerOrders[brokerValueIdx]);
                order.TotalValue += brokerOrders[brokerValueIdx].BrokerValue;
                modCount -= brokerOrders[brokerValueIdx].Count;
            }

            client.AddOrder(order);
            return order;
        }
Exemplo n.º 2
0
        public bool PrepareOrder(Order order, out Order newOrder)
        {
            newOrder = (Order)order.Clone();
            if (order.Count < MinCount)
            {
                return false;
            }

            if (order.Count > MaxCount)
            {
                newOrder.Count = MaxCount;
            }
            else
            {
                int countMod = order.Count % Multiplicity;
                if (countMod != 0)
                {
                    newOrder.Count -= countMod;
                }
            }

            Quotation quotation = GetQuote(newOrder.Product);
            newOrder.Quote = quotation.Value;
            newOrder.Commission = GetCommission(newOrder);

            return true;
        }