public void EventsRequestType()
 {
     var builder = new EventQueryBuilder();
     builder.SetCategory("politics");
     var result = builder.GetResult().ToEventsRequest();
     Assert.Equal(result.Type, Proto.Seto.EventsRequestType.EVENTSREQUESTPOLITICS);
     builder.SetCategory("current-affairs");
     result = builder.GetResult().ToEventsRequest();
     Assert.Null(result.SportByDate);
     Assert.Equal(result.Type, Proto.Seto.EventsRequestType.EVENTSREQUESTCURRENTAFFAIRS);
     builder.SetCategory("tv-and-entertainment");
     result = builder.GetResult().ToEventsRequest();
     Assert.Null(result.SportByDate);
     Assert.Equal(result.Type, Proto.Seto.EventsRequestType.EVENTSREQUESTTVANDENTERTAINMENT);
     builder.SetCategory("sport");
     result = builder.GetResult().ToEventsRequest();
     Assert.Null(result.SportByDate);
     Assert.Equal(result.Type, Proto.Seto.EventsRequestType.EVENTSREQUESTSPORTOTHER);
     builder.SetDateTime(new DateTime(2012, 1, 1));
     Assert.Throws<InvalidEventQueryException>(() => builder.GetResult());
     builder.SetSport("football");
     result = builder.GetResult().ToEventsRequest();
     Assert.Equal(result.Type, Proto.Seto.EventsRequestType.EVENTSREQUESTSPORTBYDATE);
     Assert.NotNull(result.SportByDate);
 }
示例#2
0
 static IEventMap GetEvents(ISmarketsClient client)
 {
     var builder = new EventQueryBuilder();
     builder.SetCategory("sport");
     builder.SetSport("football");
     builder.SetDateTime(DateTime.Today);
     var events = client.GetEvents(builder.GetResult()).Data;
     Log.Debug(string.Format("Got {0} events:", events.Count));
     foreach (var output in events.Roots.SelectMany(x => GetEventStrings(x, null, true)))
         Log.Debug(output);
     return events;
 }
        public void SportByDateType()
        {
            var builder = new EventQueryBuilder();
            builder.SetCategory("sport");
            builder.SetDateTime(new DateTime(2012, 1, 1));
            builder.SetSport("football");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATEFOOTBALL);
            builder.SetSport("tennis");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATETENNIS);
            builder.SetSport("horse-racing");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATEHORSERACING);

            var builderDate = builder.GetResult().ToEventsRequest().SportByDate.Date;
            Assert.Equal(builderDate.Year, (uint)2012);
            Assert.Equal(builderDate.Month, (uint)1);
            Assert.Equal(builderDate.Day, (uint)1);
        }
 public void ContentType()
 {
     var builder = new EventQueryBuilder();
     builder.SetCategory("sport");
     Assert.Equal(builder.GetResult().ToEventsRequest().ContentType, Proto.Seto.ContentType.CONTENTTYPEPROTOBUF);
 }
        public void ThrowsOnInvalidSport()
        {
            Assert.Throws<ArgumentException>(() => new EventQueryBuilder().SetSport("foo"));
            var builder = new EventQueryBuilder();
            builder.SetSport("football");
            // Need to also specify category of sport
            Assert.Throws<InvalidEventQueryException>(() => builder.GetResult());

            // If we only specify sport/football, we still need a date
            builder.SetCategory("sport");
            Assert.Throws<InvalidEventQueryException>(() => builder.GetResult());

            builder.SetDateTime(new DateTime(2012, 1, 1));
            Assert.DoesNotThrow(() => builder.GetResult());
        }
示例#6
0
        public void HandleQuotes()
        {
            var socket = new MockSessionSocket();
            var mockMarketUid = new Uid(317002);
            var mockContractUid = new Uid(608008);
            var mockOrder = new NewOrder {
                Type = OrderCreateType.Limit,
                Market = mockMarketUid,
                Contract = mockContractUid,
                Side = Side.Buy,
                Quantity = new Quantity(QuantityType.PayoffCurrency, 60000),
                Price = new Price(PriceType.PercentOdds, 5714)
            };
            var builder = new EventQueryBuilder();
            builder.SetCategory("sport");
            builder.SetSport("football");
            builder.SetDateTime(new DateTime(2012,2,21));

            socket.Expect(Payloads.Sequenced(Payloads.Login("mockuser", "mockpassword"), 1));
            socket.Next(Payloads.Sequenced(Payloads.LoginResponse("00000000-0000-0000-0000-000000658a8", 2), 1));
            socket.Expect(Payloads.Sequenced(Payloads.EventsRequest(builder.GetResult()), 2));
            socket.Next(Payloads.Sequenced(Payloads.HttpFound("http://mock/api/events/sport/football/20120221/2.pb", 2), 2));
            socket.Expect(Payloads.Sequenced(Payloads.MarketSubscribe(new Uid(317002)), 3));
            socket.Next(Payloads.Sequenced(Payloads.MarketQuotes(new Uid(317002)), 3));
            socket.Expect(Payloads.Sequenced(Payloads.OrderCreate(mockOrder), 4));
            socket.Next(
                Payloads.Sequenced(
                    Payloads.ContractQuotes(
                        new Uid(608008),
                        new List<Seto.Quote> { new Seto.Quote { Price = 5714, Quantity = 60000 } },
                        Enumerable.Empty<Seto.Quote>()), 4));
            socket.Next(Payloads.Sequenced(Payloads.OrderAccepted(new Uid(82892989397900053), 4), 5));
            socket.Expect(Payloads.Sequenced(Payloads.Logout(), 5));
            socket.Next(Payloads.Sequenced(Payloads.LogoutConfirmation(), 6));

            var session = new SeqSession(socket, SessionSettings);
            IClientSettings mockSettings = new ClientSettings(SocketSettings, SessionSettings);

            var mockHttpHandler = new MockHttpFoundHandler<Seto.Events>();
            mockHttpHandler.AddDocument(MockUrls.Football20120221);
            using (var client = SmarketsClient.Create(mockSettings, session, mockHttpHandler))
            {
                mockHttpHandler.SetClient(client);
                client.Login();
                var mockEventUid = new Uid(247001);
                var mockMapResponse = client.GetEvents(builder.GetResult());
                Assert.True(mockMapResponse.WaitOne(DataWait));
                var mockMap = mockMapResponse.Data;
                Assert.True(mockMap.ContainsKey(mockEventUid));
                var mockMarket = client.MarketMap[mockMarketUid];
                var mockContract = client.ContractMap[mockContractUid];
                mockMarket.SubscribeQuotes(client);
                var marketUpdatedEvent = new ManualResetEvent(false);
                var contractUpdatedEvent = new ManualResetEvent(false);
                MarketQuotes mockQuotes = null;
                mockMarket.MarketQuotesUpdated += (sender, args) => {
                    mockQuotes = args.Quotes;
                    marketUpdatedEvent.Set();
                };
                mockContract.ContractQuotesUpdated += (sender, args) => contractUpdatedEvent.Set();
                var createResponse = client.CreateOrder(mockOrder);
                Assert.True(createResponse.WaitOne(DataWait));
                Assert.NotNull(createResponse.Data);
                Assert.True(marketUpdatedEvent.WaitOne(1000));
                Assert.Equal(mockQuotes.QuantityType, QuantityType.PayoffCurrency);
                Assert.Equal(mockQuotes.PriceType, PriceType.PercentOdds);
                Assert.Equal(mockQuotes.Uid, mockMarketUid);
                Assert.True(contractUpdatedEvent.WaitOne(1000));
                Assert.True(mockQuotes.ContractQuotes.ContainsKey(mockContractUid));
                var mockContractQuotes = mockQuotes.ContractQuotes[mockContractUid];
                Assert.Equal(mockContractQuotes.Bids.Count(), 1);
                var mockBid = mockContractQuotes.Bids.First();
                Assert.Equal<uint>(mockBid.Price.Raw, 5714);
                Assert.Equal<uint>(mockBid.Quantity.Raw, 60000);
                Assert.Equal(mockContractQuotes.Offers.Count(), 0);
                Assert.Equal(mockContractQuotes.Executions.Count(), 0);
                Assert.Equal(mockContractQuotes.QuantityType, QuantityType.PayoffCurrency);
                Assert.Equal(mockContractQuotes.PriceType, PriceType.PercentOdds);
                Assert.Equal(mockContractQuotes.Uid, mockContractUid);
                client.Logout();
            }
        }