Ejemplo n.º 1
0
        public void DataManagerTest2_RunIndependently()
        {
            IDataProvider dataProvider = new IbkrDataProvider(Port);
            PriceDatabase database     = new PriceDatabase();

            DataManager manager = new DataManager(dataProvider, database);

            Security testSec = manager.GetSecurity("TWTR");

            bool complete = false;

            manager.SecurityDataResponse += (s, e) =>
            {
                Console.WriteLine($"DataManager received data for {e.security.Ticker}");
                complete = true;
            };

            manager.UpdateSecurity(testSec, DateTime.Today);

            int timeout = 1000;

            while (!complete)
            {
                Thread.Sleep(100);
                Assert.IsTrue(--timeout > 0);
            }

            // Requires manual cancel but works

            manager.CloseDataConnection();
        }
Ejemplo n.º 2
0
        public void GetAllItemPricesTest()
        {
            foreach (AppId.AppName appId in Enum.GetValues(typeof(AppId.AppName)))
            {
                PriceDatabase.GetAllItemPrices(appId);
            }

            Assert.IsTrue(true);
        }
Ejemplo n.º 3
0
        public void SecurityCreateTest()
        {
            PriceDatabase db = new PriceDatabase();

            var sec = db.GetSecurity("TEST1");

            var tickers = db.AllTickers;

            Assert.IsTrue(tickers.Count == 1);

            Assert.AreEqual("TEST1", tickers[0]);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads a set of symbols from symbol list and attempts to populate the database with all available data
        /// </summary>
        //  [TestMethod] long Running
        public void DatamanagerTest3_RunIndependently()
        {
            IDataProvider dataProvider = new IbkrDataProvider(Port);
            PriceDatabase database     = new PriceDatabase();

            DataManager manager = new DataManager(dataProvider, database);

            Dictionary <string, string> symbols = Helpers.ReadSymbols(GetSymbolLists()[0]);

            bool complete = false;

            int limit = 5;

            int limit2 = limit;

            manager.SecurityDataResponse += (s, e) =>
            {
                Console.WriteLine($"DataManager received data for {e.security.Ticker}");
                if (--limit2 == 0)
                {
                    complete = true;
                }
            };

            foreach (var symbol in symbols)
            {
                var sec = manager.GetSecurity(symbol.Key);
                manager.UpdateSecurity(sec, DateTime.Today);
                if (--limit <= 0)
                {
                    break;
                }
            }

            while (!complete)
            {
                Thread.Sleep(100);
            }

            // Requires manual cancel but works

            manager.CloseDataConnection();
        }
Ejemplo n.º 5
0
        public void CancelAllBuyOrdersTest()
        {
            AppId.AppName app  = AppId.AppName.CounterStrikGlobalOffensive;
            int           page = 1;

            List <BuyOrder> buyOrders = MyBuyOrders.GetMyBuyOrders(app, "", MyBuyOrders.BuyOrderType.Listed, page);
            List <string>   names     = new List <string>();

            while (buyOrders.Count != 0)
            {
                foreach (BuyOrder buyOrder in buyOrders)
                {
                    names.Add(buyOrder.MarketHashName);
                }

                page++;
                buyOrders = MyBuyOrders.GetMyBuyOrders(app, "", MyBuyOrders.BuyOrderType.Listed, page);
            }

            string           name       = "";
            List <ItemPrice> itemPrices = PriceDatabase.GetAllItemPrices(app);
            int i = 0;

            while (String.IsNullOrEmpty(name))
            {
                string marketHashName = itemPrices[i].MarketHashName;
                if (!names.Contains(marketHashName))
                {
                    name = marketHashName;
                }
                i++;
            }

            CreatingBuyOrder.CreateBuyOrder(app, name, 0.01, 2);
            CancelingBuyOrders.CancelAllBuyOrders(app, name);

            Assert.IsTrue(true);
        }
Ejemplo n.º 6
0
        public void PriceDataUpdateTest()
        {
            PriceDatabase db = new PriceDatabase();

            var sec = db.GetSecurity("TEST2");

            // Assert that there are currently no price bars associated with this security
            Assert.IsTrue(db.PriceBarCount(sec.Ticker) == 0, "Fail 1");

            var date = new DateTime(2019, 11, 5);

            // Get a price bar with specific date (does not exist, will be created)
            var bar = sec.GetPriceBar(date);

            // Set price values and send to Set function to save in database
            bar.SetPriceValues(2.0m, 3.0m, 1.0m, 2.5m, 1000);
            db.SetSecurity(sec);

            // Assert that there is a single bar with associated ticker saved in the database
            Assert.IsTrue(db.PriceBarCount(sec.Ticker) == 1, "Fail 2");

            // Retrieve the security
            var checkSec = db.GetSecurity(sec.Ticker);

            // Assert that the security contains a single price bar
            Assert.IsTrue(checkSec.GetPriceBars().Count == 1, "Fail 3");

            // Check the bar values against input
            var checkBar = checkSec.PriceBarData[0];

            Assert.AreEqual(bar, checkBar, "Fail 4");

            // Add 2 more bars and update the database

            var barList = new List <PriceBar>
            {
                bar
            };

            bar = sec.GetPriceBar(date.AddDays(1));
            bar.SetPriceValues(2.1m, 3.1m, 1.1m, 2.6m, 2000);
            barList.Add(bar);

            bar = sec.GetPriceBar(date.AddDays(2));
            bar.SetPriceValues(2.2m, 3.2m, 1.2m, 2.7m, 3000);
            barList.Add(bar);

            db.SetSecurity(sec);

            // Assert that there are 3 bars with associated ticker saved in the database
            Assert.IsTrue(db.PriceBarCount(sec.Ticker) == 3, "Fail 5");

            // Retrieve the security
            checkSec = db.GetSecurity(sec.Ticker);

            // Assert that the security contains 3 price bars
            Assert.IsTrue(checkSec.GetPriceBars().Count == 3, "Fail 6");

            // Check the bar values against input
            var checkBars = checkSec.GetPriceBars();

            Assert.AreEqual(3, barList.Count, "Fail 7");

            foreach (var b in barList)
            {
                Assert.IsTrue(checkBars.Contains(b), "Fail 8");
            }
        }