public PeriodicExample(BetfairClient client, double pollIntervalInSeconds) { var betfairClient = client; var marketCatalogues = betfairClient.ListMarketCatalogue( BFHelpers.HorseRaceFilter("GB"), BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 25).Result.Response; marketCatalogues.ForEach(c => { _markets.Enqueue(c); }); _marketListener = MarketListenerPeriodic.Create(betfairClient , BFHelpers.HorseRacePriceProjection() , pollIntervalInSeconds); }
public void Go() { var marketCatalogues = _client.ListMarketCatalogue( BFHelpers.HorseRaceFilter("GB"), BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 25).Result.Response; marketCatalogues.ForEach(c => { _markets.Enqueue(c); Console.WriteLine(c.MarketName); }); Console.WriteLine(); _marketListener = MarketListenerMultiPeriod.Create(_client, BFHelpers.HorseRacePriceProjection()); MarketCatalogue marketCatalogue1; MarketCatalogue marketCatalogue2; // Assume these just work... _markets.TryDequeue(out marketCatalogue1); _markets.TryDequeue(out marketCatalogue2); // Save the market ids so we can change the poll interval later _id1 = marketCatalogue1.MarketId; _id2 = marketCatalogue2.MarketId; // Red, every 1 second _marketSubscription1 = _marketListener.SubscribeMarketBook(_id1, 1) .SubscribeOn(Scheduler.Default) .Subscribe( marketBook => { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(marketBook.MarketId); //Console.WriteLine(BFHelpers.MarketBookConsole(marketCatalogue1, marketBook, marketCatalogue1.Runners)); //Console.WriteLine(); }, () => { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Market finished"); } ); // Blue, every 2.5 second _marketSubscription2 = _marketListener.SubscribeMarketBook(_id2, 2.5) .SubscribeOn(Scheduler.Default) .Subscribe( marketBook => { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(marketBook.MarketId); //Console.WriteLine(BFHelpers.MarketBookConsole(marketCatalogue2, marketBook, marketCatalogue2.Runners)); //Console.WriteLine(); }, () => { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Market finished"); } ); // Now setup a timer so that periodically we swap over the timings of the markets... // this will keep going until the Markets close _aTimer = new Timer(TimeSpan.FromSeconds(20).TotalMilliseconds); // every 20000 milliseconds change the poll interval for the markets // Hook up the Elapsed event for the timer. _aTimer.Elapsed += OnTimedEvent; _aTimer.Enabled = true; }
public void Go() { // find all the upcoming UK horse races (EventTypeId 7) var marketFilter = new MarketFilter(); marketFilter.EventTypeIds = new HashSet <string>() { "7" }; marketFilter.MarketStartTime = new TimeRange() { From = DateTime.Now, To = DateTime.Now.AddDays(2) }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; Console.WriteLine("BetfairClient.ListEvents()"); var events = _client.ListEvents(marketFilter).Result; if (events.HasError) { throw new ApplicationException(); } var firstEvent = events.Response.First(); Console.WriteLine("First Event {0} {1}", firstEvent.Event.Id, firstEvent.Event.Name); var marketCatalogues = _client.ListMarketCatalogue( BFHelpers.HorseRaceFilter(), BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 25).Result.Response; marketCatalogues.ForEach(c => { _markets.Enqueue(c); Console.WriteLine(c.MarketName); }); Console.WriteLine(); while (_markets.Count > 0) { AutoResetEvent waitHandle = new AutoResetEvent(false); MarketCatalogue marketCatalogue; _markets.TryDequeue(out marketCatalogue); var marketSubscription = _streamingClient.SubscribeMarket(marketCatalogue.MarketId) .SubscribeOn(Scheduler.Default) .Subscribe( tick => { Console.WriteLine(BFHelpers.MarketSnapConsole(tick, marketCatalogue.Runners)); }, () => { Console.WriteLine("Market finished"); waitHandle.Set(); }); waitHandle.WaitOne(); marketSubscription.Dispose(); } }
public void Go() { // find all the upcoming UK horse races (EventTypeId 7) var marketFilter = new MarketFilter(); marketFilter.EventTypeIds = new HashSet <string>() { "7" }; marketFilter.MarketStartTime = new TimeRange() { From = DateTime.Now, To = DateTime.Now.AddDays(2) }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; Console.WriteLine("BetfairClient.ListEvents()"); var events = _client.ListEvents(marketFilter).Result; if (events.HasError) { throw new ApplicationException(); } var firstEvent = events.Response.First(); Console.WriteLine("First Event {0} {1}", firstEvent.Event.Id, firstEvent.Event.Name); Console.WriteLine("BetfairClient.ListTimeRanges()"); var timeRanges = _client.ListTimeRanges(marketFilter, TimeGranularity.HOURS).Result; if (timeRanges.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.ListCurrentOrders()"); var currentOrders = _client.ListCurrentOrders().Result; if (currentOrders.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.ListVenues()"); var venues = _client.ListVenues(marketFilter).Result; if (venues.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.GetAccountDetails()"); var accountDetails = _client.GetAccountDetails().Result; if (accountDetails.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.GetAccountStatement()"); var accountStatement = _client.GetAccountStatement().Result; if (accountStatement.HasError) { throw new ApplicationException(); } Console.Write("BetfairClient.GetAccountFunds() "); var acc = _client.GetAccountFunds(Wallet.UK).Result; if (acc.HasError) { throw new ApplicationException(); } Console.WriteLine(acc.Response.AvailableToBetBalance); Console.WriteLine("BetfairClient.ListClearedOrders()"); var clearedOrders = _client.ListClearedOrders(BetStatus.SETTLED).Result; if (clearedOrders.HasError) { throw new ApplicationException(); } var marketCatalogues = _client.ListMarketCatalogue( BFHelpers.HorseRaceFilter(), BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 25).Result.Response; marketCatalogues.ForEach(c => { _markets.Enqueue(c); Console.WriteLine(c.MarketName); }); Console.WriteLine(); Console.WriteLine("BetfairClient.ListRaceDetails()"); var firstMarket = marketCatalogues.First(); var raceDetails = _client.ListRaceDetails(new HashSet <string>() { firstMarket.Event.Id }).Result; Console.WriteLine("ListRaceDetails {0} {1}", raceDetails.Response.First().MeetingId, raceDetails.Response.First().RaceStatus.ToString()); var marketListener = MarketListener.Create(_client, BFHelpers.HorseRacePriceProjection(), 1); while (_markets.Count > 0) { AutoResetEvent waitHandle = new AutoResetEvent(false); MarketCatalogue marketCatalogue; _markets.TryDequeue(out marketCatalogue); var marketSubscription = marketListener.SubscribeMarketBook(marketCatalogue.MarketId) .SubscribeOn(Scheduler.Default) .Subscribe( tick => { Console.WriteLine(BFHelpers.MarketBookConsole(marketCatalogue, tick, marketCatalogue.Runners)); }, () => { Console.WriteLine("Market finished"); waitHandle.Set(); }); waitHandle.WaitOne(); marketSubscription.Dispose(); } }
public static void Main() { // TODO:// replace with your app details and Betfair username/password BetfairClient client = new BetfairClient(Exchange.UK, "APPKEY"); client.Login(@"client-2048.p12", "certpass", "username", "password"); // find all the upcoming UK horse races (EventTypeId 7) var marketFilter = new MarketFilter(); marketFilter.EventTypeIds = new HashSet <string>() { "7" }; marketFilter.MarketStartTime = new TimeRange() { From = DateTime.Now, To = DateTime.Now.AddDays(2) }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; Console.WriteLine("BetfairClient.ListTimeRanges()"); var timeRanges = client.ListTimeRanges(marketFilter, TimeGranularity.HOURS).Result; if (timeRanges.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.ListCurrentOrders()"); var currentOrders = client.ListCurrentOrders().Result; if (currentOrders.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.ListVenues()"); var venues = client.ListVenues(marketFilter).Result; if (venues.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.GetAccountDetails()"); var accountDetails = client.GetAccountDetails().Result; if (accountDetails.HasError) { throw new ApplicationException(); } Console.WriteLine("BetfairClient.GetAccountStatement()"); var accountStatement = client.GetAccountStatement().Result; if (accountStatement.HasError) { throw new ApplicationException(); } Console.Write("BetfairClient.GetAccountFunds() "); var acc = client.GetAccountFunds(Wallet.UK).Result; if (acc.HasError) { throw new ApplicationException(); } Console.WriteLine(acc.Response.AvailableToBetBalance); Console.WriteLine("BetfairClient.ListClearedOrders()"); var clearedOrders = client.ListClearedOrders(BetStatus.SETTLED).Result; if (clearedOrders.HasError) { throw new ApplicationException(); } var marketCatalogues = client.ListMarketCatalogue( BFHelpers.HorseRaceFilter(), BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 25).Result.Response; marketCatalogues.ForEach(c => { Markets.Enqueue(c); Console.WriteLine(c.MarketName); }); Console.WriteLine(); var marketListener = MarketListener.Create(client, BFHelpers.HorseRacePriceProjection(), 1); while (Markets.Count > 0) { AutoResetEvent waitHandle = new AutoResetEvent(false); MarketCatalogue marketCatalogue; Markets.TryDequeue(out marketCatalogue); var marketSubscription = marketListener.SubscribeMarketBook(marketCatalogue.MarketId) .SubscribeOn(Scheduler.Default) .Subscribe( tick => { Console.WriteLine(BFHelpers.MarketBookConsole(marketCatalogue, tick, marketCatalogue.Runners)); }, () => { Console.WriteLine("Market finished"); waitHandle.Set(); }); waitHandle.WaitOne(); marketSubscription.Dispose(); } Console.WriteLine("done."); Console.ReadLine(); }