Пример #1
0
        public void PushQuote(Quote quote)
        {
            market[quote.Symbol] = quote.Price;

            // lock for atomic get and reset
            lock (syncChanges) // ReaderWriterLock for improve perfomance may be used
            {
                changes[quote.Symbol] = quote.Price;
            }
        }
Пример #2
0
        public void QuoteSerializingTest()
        {
            var expect = "EURUSD=1.23";
            var q = new Quote
            {
                Symbol = "EURUSD",
                Price = 1.23m
            };

            var res = q.Serialize();
            Assert.AreEqual(expect, res);
        }
Пример #3
0
        public void OneQuoteTest()
        {
            var q = new Quote
            {
                Symbol = "EURUSD",
                Price = 1.0m
            };
            var store = new QuoteStore();
            store.PushQuote(q);

            var market = store.GetCurrentMarket();
            Assert.AreEqual(1, market.Count);
            Assert.AreEqual("EURUSD", market[0].Symbol);
            Assert.AreEqual(1.0, market[0].Price);
        }
Пример #4
0
        public void GetChangesTest1()
        {
            var q = new Quote
            {
                Symbol = "EURUSD",
                Price = 1.0m
            };
            var store = new QuoteStore();
            store.PushQuote(q);
            q.Price = 2.0m;
            store.PushQuote(q);

            var market = store.GetChanges();
            Assert.AreEqual(1, market.Count);
            Assert.AreEqual("EURUSD", market[0].Symbol);
            Assert.AreEqual(2.0, market[0].Price);
        }
Пример #5
0
        public void GetChangesTest3()
        {
            var q1 = new Quote
            {
                Symbol = "EURUSD",
                Price = 1.0m
            };
            var q2 = new Quote
            {
                Symbol = "EURUSD",
                Price = 2.0m
            };
            var store = new QuoteStore();
            store.PushQuote(q1);
            store.PushQuote(q2);

            var market = store.GetChanges();
            Assert.AreEqual(1, market.Count);
            Assert.IsTrue(market.Any(quote => quote.Symbol == "EURUSD" && quote.Price == 2.0m));
        }
Пример #6
0
        public void SomeQuotesTest()
        {
            var q1 = new Quote
            {
                Symbol = "EURUSD",
                Price = 1.0m
            };
            var q2 = new Quote
            {
                Symbol = "USDJPY",
                Price = 2.0m
            };
            var store = new QuoteStore();
            store.PushQuote(q1);
            store.PushQuote(q2);

            var market = store.GetCurrentMarket();
            Assert.AreEqual(2, market.Count);
            Assert.IsTrue(market.Any(quote => quote.Symbol == "EURUSD" && quote.Price == 1.0m));
            Assert.IsTrue(market.Any(quote => quote.Symbol == "USDJPY" && quote.Price == 2.0m));
        }
Пример #7
0
 private void QuoteSourceOnNewQuoteAvailable(Quote quote)
 {
     quoteStore.PushQuote(quote);
 }
Пример #8
0
 private void OnNewQuoteAvailable(Quote quote)
 {
     var handler = NewQuoteAvailable;
     if (handler != null) handler(quote);
 }
Пример #9
0
 public static string Serialize(this Quote quote)
 {
     return(string.Format("{0}={1}", quote.Symbol, quote.Price));
 }