예제 #1
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_GetMissingQuote()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = expDate
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate.AddSeconds(1)
            };

              var quoteStore = new QuoteStore();

              quoteStore.Add(expQuote);
              quoteStore.Add(expQuote2);

              var actQuote = quoteStore.Get(expDate.AddHours(1));

              Assert.AreEqual(null, actQuote);
        }
예제 #2
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_GetExistsQuote()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc)
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate.AddSeconds(1)
            };

              var quoteStore = new QuoteStore();

              quoteStore.Add(expQuote);
              quoteStore.Add(expQuote2);

              var actQuote = quoteStore.Get(expDate);

              Assert.AreEqual(expQuote.Ask, actQuote.Ask);
              Assert.AreEqual(expQuote.Bid, actQuote.Bid);
              Assert.AreEqual(expQuote.Symbol, actQuote.Symbol);
        }
예제 #3
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_GetQuoteWithNullTime()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = expDate
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
            };

              var quoteStore = new QuoteStore();

              quoteStore.Add(expQuote);
              quoteStore.Add(expQuote2);

              var actQuote = quoteStore.Get(Convert.ToDateTime(null));

              Assert.AreEqual(expQuote2.Ask, actQuote.Ask);
              Assert.AreEqual(expQuote2.Bid, actQuote.Bid);
              Assert.AreEqual(expQuote2.Symbol, actQuote.Symbol);
        }
예제 #4
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_SaveQuotesToFileAndLoadQuotesFromSavedFile()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = expDate
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate.AddSeconds(1)
            };

              var quoteStore = new QuoteStore();

              quoteStore.Add(expQuote);
              quoteStore.Add(expQuote2);

              quoteStore.SaveToFile(AppDomain.CurrentDomain.BaseDirectory + @"\QuoteStore.xml");

              var quoteStoreFromFile = new QuoteStore();

              quoteStoreFromFile.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory + @"\QuoteStore.xml");

              var actQuote = quoteStoreFromFile.Get(expDate);

              Assert.AreEqual(expQuote.Ask, actQuote.Ask);
              Assert.AreEqual(expQuote.Bid, actQuote.Bid);
              Assert.AreEqual(expQuote.Symbol, actQuote.Symbol);
        }
예제 #5
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_RemoveQuote()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);
              var expDate2 = expDate.AddMinutes(2);
              var expDate3 = expDate.AddMinutes(3);
              var expDate4 = expDate.AddMinutes(5);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = expDate
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate2
            };

              var expQuote3 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33929,
              Bid = 1.33912,
              Time = expDate3
            };

              var expQuote4 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33927,
              Bid = 1.33910,
              Time = expDate4
            };

              var quoteStore4Elements = new QuoteStore();

              quoteStore4Elements.Add(expQuote);
              quoteStore4Elements.Add(expQuote2);
              quoteStore4Elements.Add(expQuote3);
              quoteStore4Elements.Add(expQuote4);

              quoteStore4Elements.Remove(expDate.AddMinutes(2), expDate.AddMinutes(3));

              Assert.AreEqual(expQuote, quoteStore4Elements.Get(expDate));
              Assert.AreEqual(null, quoteStore4Elements.Get(expDate2));
              Assert.AreEqual(null, quoteStore4Elements.Get(expDate3));
              Assert.AreEqual(expQuote4, quoteStore4Elements.Get(expDate4));
        }
예제 #6
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_MT_RemoveQuotesWhenManyWritesInQuotes()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var quoteStore = new QuoteStore();

              var tasks = new Task[100];

              for (int i = 0; i < 100; i++)
              {
            int i1 = i;
            tasks[i] = Task.Factory.StartNew(() =>
            {
              for (int j = 0; j < 10; j++)
              {
            quoteStore.Add(new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate.AddSeconds(i1*10 + j)
            });
            Thread.Sleep(10);  //hack
              }
              quoteStore.Remove(expDate.AddSeconds(10), expDate.AddSeconds(13));
            });
              }

              Task.WaitAll(tasks);

              Assert.AreEqual(expDate.AddSeconds(9), quoteStore.Get(expDate.AddSeconds(9)).Time);
              Assert.AreEqual(null, quoteStore.Get(expDate.AddSeconds(10)));
              Assert.AreEqual(null, quoteStore.Get(expDate.AddSeconds(11)));
              Assert.AreEqual(null, quoteStore.Get(expDate.AddSeconds(12)));
              Assert.AreEqual(null, quoteStore.Get(expDate.AddSeconds(13)));
              Assert.AreEqual(expDate.AddSeconds(14), quoteStore.Get(expDate.AddSeconds(14)).Time);
        }
예제 #7
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_MT_ReadRangeOfQuotesWhenManyWritesInQuotes()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var quoteStore = new QuoteStore();

              for (int i = 0; i < 1000; i+=10)
              {
            int i1 = i;
            new Thread(() =>
              {
            for (int j = 0; j < 10; j++)
            {
              quoteStore.Add(new Quote
                {
                  Symbol = "EURUSD",
                  Ask = 1.33925,
                  Bid = 1.33908,
                  Time = expDate.AddSeconds(i1 + j)
                });
              Thread.Sleep(1);
            }
              }).Start();
              }

              var actQuote = quoteStore.GetRange(expDate.AddSeconds(10), expDate.AddSeconds(50));

              int k = 0;
              foreach (var quote in actQuote)
              {
            Debug.Print("Step " + k + " " + quote.Time.ToString(CultureInfo.InvariantCulture));
            k += 1;
              }
        }
예제 #8
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_MT_ReadQuotesWhenManyWritesInQuotes()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);

              var quoteStore = new QuoteStore();

              for (int i = 0; i < 1000; i+=10)
              {
            int i1 = i;
            new Thread(() =>
              {
            for (int j = 0; j < 10; j++)
            {
              quoteStore.Add(new Quote
                {
                  Symbol = "EURUSD",
                  Ask = 1.33925,
                  Bid = 1.33908,
                  Time = expDate.AddSeconds(i1 + j)
                });
              Thread.Sleep(5);
            }
              }).Start();
              }

              for (int i = 0; i < 1000; i++)
              {
            var actQuote = quoteStore.Get(expDate.AddSeconds(i));

            if (actQuote != null)
              Debug.Print("Step " + i + " " + actQuote.Time.ToString(CultureInfo.InvariantCulture));
              }
        }
예제 #9
0
파일: QuoteTest.cs 프로젝트: Gelian/Trader
        public void QuoteStore_GetRangeOfQoutes()
        {
            var expDate = new DateTime(2013, 08, 07, 22, 35, 00, DateTimeKind.Utc);
              var expDate2 = expDate.AddMinutes(2);
              var expDate3 = expDate.AddMinutes(3);
              var expDate4 = expDate.AddMinutes(5);

              var expQuote = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33924,
              Bid = 1.33907,
              Time = expDate
            };

              var expQuote2 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33925,
              Bid = 1.33908,
              Time = expDate2
            };

              var expQuote3 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33929,
              Bid = 1.33912,
              Time = expDate3
            };

              var expQuote4 = new Quote
            {
              Symbol = "EURUSD",
              Ask = 1.33927,
              Bid = 1.33910,
              Time = expDate4
            };

              var quoteStore = new QuoteStore();

              quoteStore.Add(expQuote);
              quoteStore.Add(expQuote2);
              quoteStore.Add(expQuote3);
              quoteStore.Add(expQuote4);

              var actQuotes = quoteStore.GetRange(expDate2, expDate3).ToList();

              Assert.AreEqual(false, actQuotes.Exists(p => p.Time == expDate));
              Assert.AreEqual(true, actQuotes.Exists(p => p.Time == expDate2));
              Assert.AreEqual(true, actQuotes.Exists(p => p.Time == expDate3));
              Assert.AreEqual(false, actQuotes.Exists(p => p.Time == expDate4));
        }