Betfairng
C# API for Betfair API-NG
Install / Use
/learn @joelpob/BetfairngREADME
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.
Related Skills
node-connect
337.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.2kCommit, push, and open a PR
