Ejemplo n.º 1
0
        // send a cancel buy/sell request using the MarketClient project API
        public bool SendCancelBuySellRequest(int id)
        {
            string data = SendRequest <CancelBuySellRequest>(new CancelBuySellRequest(id));

            if (data == null)
            {
                return(false);
            }
            if (data.Equals("Ok"))
            {
                //In case when history table's size is 1
                if (HistoryTable.getHistoryList().Last() == HistoryTable.getHistoryList().First())
                {
                    HistoryTable.getHistoryList().First()._status = Status.cancelled;
                    Logger.InfoLog("Request " + HistoryTable.getHistoryList().Last()._id + " has cancelled");
                }
                else
                {
                    HistoryItem item = HistoryTable.getHistoryList().Where(x => x._id == id).First();
                    item._status = Status.cancelled;
                    Logger.InfoLog(item._id + " has cancelled");
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static void TestSessionHistory()
        {
            //Directory.SetCurrentDirectory(@"./GUI/bin/Debug");
            Random      rnd   = new Random();
            BuyRequest  b1    = new BuyRequest(rnd.Next(1, 10), rnd.Next(1, 100), rnd.Next(30, 200));
            HistoryItem item1 = new HistoryItem(DateTime.Now, "BuyRequest", b1, rnd.Next(10000, 99999));

            HistoryTable.Add(item1);
            bool found = false;

            foreach (HistoryItem item in HistoryTable.getHistoryList())
            {
                if (item.Equals(item1))
                {
                    found = true;
                }
            }
            Assert.AreEqual(true, found);
            Assert.AreEqual(Status.pending, item1._status);
            HistoryTable.update();
            Assert.AreEqual(Status.completed, item1._status);
            BuyRequest  b2     = new BuyRequest(rnd.Next(1, 10), rnd.Next(1, 100), rnd.Next(30, 200));
            HistoryItem item2  = new HistoryItem(DateTime.Now, "BuyRequest", b2, rnd.Next(10000, 99999));
            bool        found2 = false;

            foreach (HistoryItem item in HistoryTable.getHistoryList())
            {
                if (item.Equals(item2))
                {
                    found2 = true;
                }
            }
            Assert.AreEqual(false, found2);
            HistoryTable.Add(item2);
            foreach (HistoryItem item in HistoryTable.getHistoryList())
            {
                if (item.Equals(item2))
                {
                    found2 = true;
                }
            }
            Assert.AreEqual(true, found2);
            item2._status = Status.cancelled;
            bool found3 = false;

            foreach (HistoryItem item in HistoryTable.getHistoryList())
            {
                if (item._status == Status.cancelled)
                {
                    found3 = true;
                }
            }
            Assert.AreEqual(true, found3);
            HistoryTable.update();
            Assert.AreEqual(true, item2._status == Status.cancelled);
        }
Ejemplo n.º 3
0
        // send a buy request using the MarketClient project API
        public int SendBuyRequest(int price, int commodity, int amount)
        {
            string response = "Unknown error";

            try
            {
                BuyRequest data = new BuyRequest(commodity, amount, price);
                response = SendRequest(data);
                int id = Convert.ToInt32(response);
                if (id >= 1)
                {
                    HistoryItem newItem = new HistoryItem(DateTime.Now, data.type, data.ToString(), id);
                    HistoryTable.Add(newItem);
                }
                return(id);
            }
            catch
            {
                printError(response); // Print the error
                return(-1);
            }
        }
Ejemplo n.º 4
0
 public void allHistory()
 {
     HistoryTable.PrintHistory();
 }