public BetfairClientSync(Exchange exchange, string appKey, Action preNetworkRequest = null, WebProxy proxy = null) { client = new BetfairClient(exchange, appKey, preNetworkRequest, proxy); }
public static List <string> GetVenues(BetfairClient client, ILogger log) { var marketFilter = new MarketFilter(); marketFilter.EventTypeIds = new HashSet <string>() { "7" }; marketFilter.MarketCountries = new HashSet <string>() { "AU" }; marketFilter.MarketStartTime = new TimeRange() { From = DateTime.Now, To = DateTime.Now.AddDays(3) }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; //var events = client.ListEvents(marketFilter).Result; List <EventResult> events = client.ListEvents( marketFilter).Result.Response; VenueEngine venueEngine = new VenueEngine(); venueEngine.Execute(events.Select(e => e.Event).Distinct().ToList(), log); var venues = events.Select(mark => mark.Event.Venue + "|" + mark.Event.Name + "|" + mark.Event.Id).Distinct(); return(venues.ToList()); }
// public static ConcurrentQueue<MarketCatalogue> Markets = new ConcurrentQueue<MarketCatalogue>(); 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"); // Exchange Streaming API example, see: http://docs.developer.betfair.com/docs/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API // TODO:// replace with your app deatils and Betfair username/password, and enable streaming support on your Betfair account //StreamingBetfairClient streamingClient = new StreamingBetfairClient("stream-api-integration.betfair.com", "APPKEY"); //streamingClient.Login("username", "password"); /* * OriginalExample runs the code originally in here, using the standard MarketListener * PeriodicExample runs a version of MarketListener (MarketListenerPeriodic), using an RX interval, specified in seconds * MultiPeriodExample runs a version of MarketListenerPeriodic (MarketListenerMultiPeriod), using potentially differing poll intervals per market book */ var example = new OriginalExample(client); // This example blocks within GO //var example = new StreamingExample(client, streamingClient); // Betfair Exchange Streaming API example //var example = new PeriodicExample(client, 0.5); //var example = new MultiPeriodExample(client); example.Go(); if (!example.IsBlocking) { Thread.Sleep(TimeSpan.FromMinutes(20)); } Console.WriteLine("done."); Console.ReadLine(); }
public static List <Tuple <DateTime, string> > GetRaces(BetfairClient client, string venueId) { var marketFilter = new MarketFilter(); marketFilter.EventIds = new HashSet <string>() { venueId }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; //var events = client.ListEvents(marketFilter).Result; List <MarketCatalogue> marketCatalogues = client.ListMarketCatalogue( marketFilter, BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 100).Result.Response; VenueEngine venueEngine = new VenueEngine(); var venue = venueEngine.GetFromApiId(venueId); RaceEngine raceEngine = new RaceEngine(); raceEngine.Execute(marketCatalogues, venue); var races = marketCatalogues.Select(race => new Tuple <DateTime, String> (race.Description.MarketTime, race.MarketName + "|" + "|" + race.MarketId) ); return(races.ToList()); }
public static void Main() { // TODO:// replace with your app details and Betfair username/password BetfairClient client = new BetfairClient("APPKEY"); client.Login(@"client-2048.p12", "certpass", "username", "password"); // Exchange Streaming API example, see: http://docs.developer.betfair.com/docs/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API // TODO:// replace with your app deatils and Betfair username/password, and enable streaming support on your Betfair account //StreamingBetfairClient streamingClient = new StreamingBetfairClient("stream-api-integration.betfair.com", "APPKEY"); //streamingClient.Login("username", "password"); /* * OriginalExample runs the code originally in here, using the standard MarketListener * PeriodicExample runs a version of MarketListener (MarketListenerPeriodic), using an RX interval, specified in seconds * MultiPeriodExample runs a version of MarketListenerPeriodic (MarketListenerMultiPeriod), using potentially differing poll intervals per market book */ var example = new OriginalExample(client); // This example blocks within GO //var example = new StreamingExample(client, streamingClient); // Betfair Exchange Streaming API example //var example = new PeriodicExample(client, 0.5); //var example = new MultiPeriodExample(client); example.Go(); if(!example.IsBlocking) Thread.Sleep(TimeSpan.FromMinutes(20)); Console.WriteLine("done."); Console.ReadLine(); }
public ApiConfig(ExecutionContext context) { #if DEBUG BetfairClient = new BetfairClient("UhwmsL3EqCwjEKwH"); BetfairClient.Login(@"/etc/client-2048.p12", "REDsky.123", "*****@*****.**", "REDsky.123", null); #else var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) // <- This gives you access to your application settings in your local development environment .AddEnvironmentVariables() // <- This is what actually gets you the application settings in Azure .Build(); ThumbPrint = config["WEBSITE_LOAD_CERTIFICATES"]; bool validOnly = false; using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser)) { certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find( X509FindType.FindByThumbprint, // Replace below with your certificate's thumbprint ThumbPrint, validOnly); // Get the first cert with the thumbprint X509Certificate2 cert = (X509Certificate2)certCollection.OfType <X509Certificate>().FirstOrDefault(); BetfairClient = new BetfairClient("UhwmsL3EqCwjEKwH"); BetfairClient.Login(@"/etc/client-2048.p12", "REDsky.123", "*****@*****.**", "REDsky.123", cert); } #endif }
public BetfairClientSync(string appKey, string sessionToken, Action preNetworkRequest = null, WebProxy proxy = null) { client = new BetfairClient(appKey, sessionToken, preNetworkRequest, proxy); }
private MarketListener(BetfairClient client, PriceProjection priceProjection, int connectionCount) { this.client = client; this.priceProjection = priceProjection; this.connectionCount = connectionCount; Task.Run(() => PollMarketBooks()); }
public static MarketListener Create(BetfairClient client, PriceProjection priceProjection, int connectionCount, int samplePeriod = 0) { if (listener == null) listener = new MarketListener(client, priceProjection, connectionCount, samplePeriod); return listener; }
private MarketListenerPeriodic(BetfairClient client, PriceProjection priceProjection, double periodInSec) { _client = client; _priceProjection = priceProjection; _polling = Observable.Interval(TimeSpan.FromSeconds(periodInSec), NewThreadScheduler.Default).Subscribe(l => DoWork()); }
public static List <string> GetRunners(BetfairClient client, string raceId) { var marketFilter = new MarketFilter(); marketFilter.MarketIds = new HashSet <string>() { raceId }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; List <MarketCatalogue> marketCatalogues = client.ListMarketCatalogue( marketFilter, BFHelpers.HorseRaceProjection(), MarketSort.FIRST_TO_START, 100).Result.Response; var marketIds = new HashSet <String>() { raceId }; var marketBooks = client.ListMarketBook(marketIds).Result.Response; List <Runner> runnersForMarket = marketBooks.First().Runners; RunnerEngine runnerEngine = new RunnerEngine(); RaceEngine raceEngine = new RaceEngine(); var race = raceEngine.GetFromApiId(raceId); runnerEngine.Execute(marketCatalogues.First().Runners, runnersForMarket, race); var runners = marketCatalogues.First().Runners.Select(runner => runner.RunnerName + "|" + runner.Metadata.GetValueOrDefault("JOCKEY_NAME") + "^" + runner.Metadata.GetValueOrDefault("TRAINER_NAME") + "^" + runner.Metadata.GetValueOrDefault("WEIGHT_VALUE") + "^" + runner.Metadata.GetValueOrDefault("FORM") + "^" + runner.Metadata.GetValueOrDefault("STALL_DRAW") + "|" + runner.SelectionId + "|" + runnersForMarket.Find(rfm => rfm.SelectionId == runner.SelectionId).LastPriceTraded );; //{[WEIGHT_VALUE,]} //{[JOCKEY_NAME, T P Mccarthy]} //{[TRAINER_NAME, T J Munday]} //{[FORM, 83]} //{[STALL_DRAW, 3]} return(runners.ToList()); }
private MarketListener(BetfairClient client, PriceProjection priceProjection, int connectionCount, int samplePeriod) { this.client = client; this.priceProjection = priceProjection; this.connectionCount = connectionCount; this.samplePeriod = samplePeriod; if (samplePeriod >= 1000) this.sampleFrequency = samplePeriod/1000; else this.sampleFrequency = samplePeriod/100; Task.Run(() => PollMarketBooks()); }
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 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 static void Main() { BetfairClient client; //TODO: see chat re TLS1.0 vs 2.0 bug + urls: #FRAMEWORK? if (File.Exists("App.config")) { client = new BetfairClient(ConfigurationManager.AppSettings["bfAppKey"]); client.Login(ConfigurationManager.AppSettings["logOnCertFile"], SecureStringManager.Unprotect("logOnCertFilePassword", true), SecureStringManager.Unprotect("bfUsername", true), SecureStringManager.Unprotect("bfPassword", true)); } else { // TODO:// replace with your app details and Betfair username/password client = new BetfairClient("APPKEY"); client.Login(@"client-2048.p12", "certpass", "username", "password"); } /* * OriginalExample runs the code originally in here, using the standard MarketListener * PeriodicExample runs a version of MarketListener (MarketListenerPeriodic), using an RX interval, specified in seconds * MultiPeriodExample runs a version of MarketListenerPeriodic (MarketListenerMultiPeriod), using potentially differing poll intervals per market book */ var example = new OriginalExample(client); // This example blocks within GO //var example = new StreamingExample(client, streamingClient); // Betfair Exchange Streaming API example //var example = new PeriodicExample(client, 0.5); //var example = new MultiPeriodExample(client); example.Go(); if (!example.IsBlocking) { Thread.Sleep(TimeSpan.FromMinutes(20)); } Console.WriteLine("done."); Console.ReadLine(); }
public static MarketListenerPeriodic Create(BetfairClient client, PriceProjection priceProjection, double periodInSec) { return new MarketListenerPeriodic(client, priceProjection, periodInSec); }
private MarketListenerMultiPeriod(BetfairClient client, PriceProjection priceProjection) { _client = client; _priceProjection = priceProjection; }
private void Dispose(bool disposing) { if (!disposed) { disposed = true; if (disposing) { if (client != null) { client.Dispose(); client = null; } } } }
public bool Login(string applicationId, string username, string password) { this.client = new BetfairClient(); isLoggedOn = this.client.Login(applicationId, username, password); return isLoggedOn; }
public static void Main() { // TODO:// replace with your app details and Betfair username/password BetfairClient client = new BetfairClient(Exchange.UK); client.Login( "nur1euro", "niedero", "nur1euro"); // 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(1) }; marketFilter.MarketTypeCodes = new HashSet<String>() { "WIN" }; var eventTypes = client.ListEventTypes(marketFilter); Console.WriteLine("BetfairClient.ListTimeRanges()"); var timeRanges = client.ListTimeRanges(marketFilter, TimeGranularity.HOURS).Result; if (timeRanges.HasError) throw new ApplicationException(); var marketCatalogues = client.ListMarketCatalogue( BFUtil.HorseRaceFilter("GB"), BFUtil.HorseRaceProjection(), MarketSort.FIRST_TO_START, 100).Result.Response; marketCatalogues.ForEach(c => { //Markets.Enqueue(c); List<String> marketIdList = new List<string>(); marketIdList.Add(c.MarketId); OrderProjection orderProjection = OrderProjection.ALL; MatchProjection matchProjection = MatchProjection.NO_ROLLUP; var marketBook = client.ListMarketBook( marketIdList, BFUtil.HorseRacePriceProjection(), orderProjection, matchProjection ).Result.Response; Console.WriteLine(BFUtil.checkMarket(c, marketBook[0])); //Console.WriteLine(c.MarketName); }); Console.WriteLine(); var marketListener = MarketListener.Create(client, BFUtil.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(BFUtil.MarketBookConsole(marketCatalogue, tick, marketCatalogue.Runners)); }, () => { Console.WriteLine("Market finished"); waitHandle.Set(); }); waitHandle.WaitOne(); marketSubscription.Dispose(); //} Console.WriteLine("done."); Console.ReadLine(); }
public static MarketListenerMultiPeriod Create(BetfairClient client, PriceProjection priceProjection) { return new MarketListenerMultiPeriod(client, priceProjection); }
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(); }
public StreamingExample(BetfairClient client, StreamingBetfairClient streamingClient) { _client = client; _streamingClient = streamingClient; }
public OriginalExample(BetfairClient client) { _client = client; }
public MultiPeriodExample(BetfairClient client) { _client = client; }
private void initApi() { clientDelay = new BetfairClient(Setting.Instance.delayKey, sessionToken); clientActive = new BetfairClient(Setting.Instance.realKey, sessionToken); }