예제 #1
0
        public static string Order(Order order)
        {
            string message = "";

            message += order.Client.Name + " ";

            if (order.Type == OrderType.BUY)
                message += "buys ";
            else
                message += "sels ";

            message += Convert.ToString(order.Count) + " at " + Convert.ToString(order.TotalValue);

            return message;
        }
예제 #2
0
파일: Bank.cs 프로젝트: MarekPratnicki/Citi
        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;
        }
예제 #3
0
        public void AddOrder(Order order)
        {
            orders.Add(order);

            if (order.Type == OrderType.BUY)
                ordersSum += order.Count;
            else
                ordersSum -= order.Count;

            ordersCount += order.Count;
            orderPrizesSum += order.TotalValue;
        }
예제 #4
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;
        }
예제 #5
0
        public decimal GetCommission(Order order)
        {
            int count = order.Count;

            int fromCount = 0;
            int toCount = 0;

            foreach (Commission commission in commissions)
            {
                if (commission.FromCount != null)
                    fromCount = commission.FromCount.Value;
                else
                    fromCount = 0;

                if (commission.ToCount != null)
                    toCount = commission.ToCount.Value;
                else
                    toCount = int.MaxValue;

                if (count >= fromCount && count <= toCount)
                    return commission.Percent;
            }

            return 0;
        }
예제 #6
0
        public void AddOrder(Order order)
        {
            orders.Add(order);

            transactionsSum += order.Count;
        }