Skip to content

timmyag/betfairng

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Betfair API-NG C# Client API

A feature complete .NET Betfair API-NG C# client that builds on the Betfair sample code. It uses the Task Parallel Library and Reactive Extensions for the concurrency layer. Now with Exchange Streaming API support (early beta). Be sure to pull in the Betfair example code submodule:

git clone https://github.com/joelpob/betfairng
cd betfairng
git submodule init
git submodule update

How to use it

To login to Betfair using this library, you'll need both a) a self signed certificate (follow the process described here), and b) an application key directions here.

BetfairClient client = new BetfairClient("ASDF1234qwerty");
client.Login("client-2048.p12", "certpass", "username", "password");

Check out the ConsoleExample project (in the solution) for an example on how to use the "BetfairClient" class. If you're unfamiliar with the Task Parallel Library or Reactive Extensions, you can use the "BetfairClientSync" class.

The "MarketListener" class is where the magic happens:

AutoResetEvent waitHandle = new AutoResetEvent(false);
var marketListener = MarketListener.Create(client, BFHelpers.HorseRacePriceProjection(), 1);

var marketCatalogues = client.ListMarketCatalogue(
    BFHelpers.HorseRaceFilter(), 
    BFHelpers.HorseRaceProjection(), 
    MarketSort.FIRST_TO_START,
    25).Result.Response;
    
var marketCatalogue = marketCatalogues.First();

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();

MarketListener will poll the Betfair API-NG service (ListMarketBook) for all subscribed markets and push the result to all Rx subscribers. You can also subscribe to individual runners in a given market (MarketListener.SubscribeRunner()).

Enjoy.

About

C# API for Betfair API-NG

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%