Files

93 lines
3.1 KiB
C#
Raw Permalink Normal View History

2020-02-22 23:56:45 +00:00
using SuccessfulCode.BetfairApi.BettingModels;
using SuccessfulCode.BetfairApi.BettingModels.Enums;
2020-02-22 22:56:06 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2020-02-22 23:56:45 +00:00
namespace SuccessfulCode.BetfairApi
2020-02-22 22:56:06 +00:00
{
public class BetfairHorseRacingQueries
{
private readonly BettingApiClient _client;
private string _horseRacingId;
public BetfairHorseRacingQueries(BettingApiClient client)
{
_client = client;
}
public async Task<MarketCatalogue[]> GetHorseWinCatalogue(DateTime from, DateTime to, params string[] countries)
{
await EnsureHorseRacingIdFound();
var horseRacingMarket = new MarketFilter()
{
EventTypeIds = new[] { _horseRacingId },
MarketStartTime = new TimeRange()
{
From = from,
To = to,
},
MarketTypeCodes = new[] { "WIN" },
MarketCountries = countries,
};
var events = await _client.ListMarketCatalogue(horseRacingMarket,
marketProjection:
new[]
{
MarketProjection.MarketStartTime,
MarketProjection.Event,
MarketProjection.RunnerDescription,
MarketProjection.RunnerMetadata
},
maxResults: 10,
sort: MarketSort.FirstToStart
);
return events;
}
public async Task<EventTypeResult[]> GetHorseRacingMarketTypes()
{
var horseRacingMarket = new MarketFilter()
{
EventTypeIds = new[] { _horseRacingId }
};
var eventTypes = await _client.ListEventTypes(horseRacingMarket);
return eventTypes;
}
public async Task<MarketBook[]> GetMarketBookPrices(MarketCatalogue[] catalogue)
{
var marketsFound = await _client.ListMarketBook(catalogue.Select(e => e.MarketId).ToArray(),
new PriceProjection()
{
PriceData = new[]
{
PriceData.ExBestOffers,
PriceData.ExTraded,
},
Virtualise = true
});
return marketsFound;
}
public async Task<MarketBook[]> GetBestPrices(params string[] marketId)
{
var result = await _client.ListMarketBook(marketId, new PriceProjection() { PriceData = new[] { PriceData.ExBestOffers } });
return result;
}
private async Task EnsureHorseRacingIdFound()
{
if (_horseRacingId == null)
{
var eventTypes = await _client.ListEventTypes(new MarketFilter());
_horseRacingId = eventTypes.First(e => e.EventType.Name.Equals("Horse racing", StringComparison.InvariantCultureIgnoreCase)).EventType.Id;
}
}
}
}