Example #1
0
    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 BetfairServerResponse<List<TimeRangeResult>> ListTimeRanges(MarketFilter marketFilter, TimeGranularity timeGranularity)
 {
     return client.ListTimeRanges(marketFilter, timeGranularity).Result;
 }
 public BetfairServerResponse<List<VenueResult>> ListVenues(MarketFilter marketFilter)
 {
     return client.ListVenues(marketFilter).Result;
 }
 public BetfairServerResponse<List<MarketCatalogue>> ListMarketCatalogue(
     MarketFilter marketFilter,
     ISet<MarketProjection> marketProjections = null,
     MarketSort? sort = null,
     int maxResult = 1)
 {
     return client.ListMarketCatalogue(
         marketFilter,
         marketProjections,
         sort,
         maxResult).Result;
 }
 public BetfairServerResponse<List<EventTypeResult>> ListEventTypes(MarketFilter marketFilter)
 {
     return client.ListEventTypes(marketFilter).Result;
 }
 public BetfairServerResponse<List<CountryCodeResult>> ListCountries(MarketFilter marketFilter)
 {
     return client.ListCountries(marketFilter).Result;
 }
 public BetfairServerResponse<List<CompetitionResult>> ListCompetitions(MarketFilter marketFilter)
 {
     return client.ListCompetitions(marketFilter).Result;
 }
Example #8
0
    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();
        }
    }