コード例 #1
0
        public void limit_buy_order_filled_by_2_sell_orders()
        {
            Commodity gold = new Commodity("Gold (grams)");

            Player playerA = new Player(1, "A");
            Player playerB = new Player(2, "B");
            Player playerC = new Player(3, "C");

            IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSGOLD", "Walt's Gold Exchange");
            //order executed on match

            IOrder buyOrder = exchange.AddOrder(OrderBuilder.BuildBuyOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, gold, 10, new Money("USD", 50)));
            Thread.Sleep(250);

            Assert.AreEqual(OrderStatus.Created, buyOrder.Status);

            IOrder sellOrder1 = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 57), playerB, gold, 4, new Money("USD", 50)));
            Thread.Sleep(250);

            Assert.AreEqual(OrderStatus.Filled, sellOrder1.Status);
            Assert.AreEqual(OrderStatus.PartiallyFilled, buyOrder.Status);
            Assert.AreEqual(4, buyOrder.FilledSize);

            IOrder sellOrder2 = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 23, 05), playerC, gold, 6, new Money("USD", 50)));
            Thread.Sleep(250);

            Assert.AreEqual(OrderStatus.Filled, sellOrder2.Status);
            Assert.AreEqual(OrderStatus.Filled, buyOrder.Status);
            Assert.AreEqual(10, buyOrder.FilledSize);
        }
コード例 #2
0
        public void ensure_partition_Width_is_functioning_correctly()
        {
            ICanStore grain = new Commodity("Grain1", "Grain", UnitOfMeasurement.Kilogram, 0.001, false);

            ItemStorePartition partition = new ItemStorePartition(grain);
            Assert.AreEqual(1000, partition.Capacity);

            partition.Slots++;
            Assert.AreEqual(2000, partition.Capacity);

            partition.Slots--;
            Assert.AreEqual(1000, partition.Capacity);
        }
コード例 #3
0
ファイル: IMarket.cs プロジェクト: vitamink/InfiniteWorlds
        public ICommodity FindCommodityByCode(string commodityCode)
        {
            ICommodity commodity;
            switch (commodityCode)
            {
                case "POTAT1":
                    commodity = new Commodity("POTAT1", "Potatoes", UnitOfMeasurement.Kilogram, 0.00075, false);
                    break;
                case "GRAIN1":
                    commodity = new Commodity("GRAIN1", "Grain", UnitOfMeasurement.Kilogram, 0.001, false);
                    break;
                default:
                    commodity = null;
                    break;
            }

            return commodity;
        }
コード例 #4
0
        public void simple_sell_buy_order_sequence_with_2_limit_orders()
        {
            Commodity van = new Commodity("Camper Van");

            Player playerA = new Player(1, "A");
            Player playerB = new Player(2, "B");

            IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSRV", "Walt's RV Exchange", false);

            IOrder sellOrder = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, van, 1, new Money("USD", 5000)));

            Assert.AreEqual(OrderStatus.Created, sellOrder.Status);

            IOrder buyOrder = exchange.AddOrder(OrderBuilder.BuildBuyOrder(null, new DateTime(2013, 8, 1, 14, 22, 57), playerB, van, 1, new Money("USD", 5000)));

            Assert.AreEqual(OrderStatus.Filled, sellOrder.Status);
            Assert.AreEqual(OrderStatus.Filled, buyOrder.Status);
        }
コード例 #5
0
        public void should_transfer_all_from_crate_to_a_silo_2()
        {
            ITransferManager transfer = new TransferManager();

            Commodity grain = new Commodity("Grain1", "Grain", UnitOfMeasurement.Kilogram, 0.01, false);
            IItemStore grainContainer = new ItemStoreComposite(2);
            bool transfered = transfer.Item(101, grain).To(grainContainer);

            Assert.IsTrue(transfered);
            Assert.AreEqual(101, grainContainer["Grain"].Used);

            IItemStore toContainer = new ItemStoreComposite(1);

            transfered = transfer.Item(5, grain).From(grainContainer).To(toContainer);

            Assert.IsTrue(transfered);
            Assert.AreEqual(1, grainContainer["Grain"].Slots);

            Assert.AreEqual(5, toContainer["Grain"].Used);
        }
コード例 #6
0
        public void ensure_that_storage_with_1_slot_behaves_as_expected()
        {
            ITransferManager transfer = new TransferManager();

            IItemStore storage = new ItemStoreComposite(1);
            ICanStore grain = new Commodity("Grain1", "Grain", UnitOfMeasurement.Kilogram, 0.001, false);

            transfer.Item(5, grain).To(storage);

            Assert.AreEqual(1, storage.SlotsUsed);

            Assert.IsNotNull(storage["Grain"]);

            IItemContainer grainContainer;
            bool transfered = transfer.Item(5, grain).From(storage).ToContainer(out grainContainer);

            Assert.IsTrue(transfered);
            Assert.AreEqual(5, grainContainer.Used);
            Assert.IsNull(storage["Grain"]);
        }
コード例 #7
0
        public void simple_sell_order_cancel_on_limit_order()
        {
            Commodity van = new Commodity("Camper Van");

            Player playerA = new Player(1, "A");

            IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSRV", "Walt's RV Exchange", false);

            IOrder sellOrder = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, van, 1, new Money("USD", 5000)));

            Assert.AreEqual(OrderStatus.Created, sellOrder.Status);

            bool cancelled = exchange.CancelOrder(sellOrder);

            Assert.IsTrue(cancelled);
            Assert.AreEqual(OrderStatus.Cancelled, sellOrder.Status);
        }