Betfair Exchange API : API help using JavaScript / node.js

Post Reply
Posts: 46
Joined: Mon Jun 03, 2019 2:56 pm

Mon Aug 03, 2020 11:37 am

Hi All,

I've always used R for all my Betfair programming and it's worked well but it's quite slow. It's ok for pulling off the price/volume and the metadata etc. but I'm finding now that once I've run the data though my algorithm the prices have moved such that there is no longer any value so I am missing out in some cases.

I've thought about switching to JavaScript since it's something I recently started learning and I was wondering if anyone had a working example of submitting a simple 'listEventTypes' request they can share.

I've pieced some code together from the examples in the API docs but it doesn't seem to work. I get a response from the request but it doesn't make sense.

I have a file which logs me in fine and I pass the token to the options below.
let options = {
hostname: '',
port: 443,
path: '',
method: 'POST',
headers: {
'X-Application' : "r1ZYqRWZ552ClKaI",
'Accept': 'application/json',
'Content-type' : 'application/json',
'X-Authentication' : token[1]
function constructJsonRpcRequest(operation, params) {
return '[{"jsonrpc":"2.0","method":"SportsAPING/v1.0/' + operation + '", "params": ' + params + ', "id": 1}]';
function findHorseRaceId(options) {
console.log("Get horse racing event id");
// Define Horse Racing in filter object
var requestFilters = '{"filter":{}}';
var jsonRequest = constructJsonRpcRequest('listEventTypes', requestFilters);

var str = '';
var req = https.request(options, function (res){

res.on('data', function (chunk) {
str += chunk;

res.on('end', function (chunk) {
// On resposne parse Json and check for errors
var response = JSON.parse(str);
// Retrieve id from response and get next available horse race
// getNextAvailableHorseRace(options, response);

// Send Json request object
req.write(jsonRequest, DEFAULT_ENCODING);

req.on('error', function(e) {
console.log('Problem with request: ' + e.message);

Posts: 1740
Joined: Mon Jul 02, 2012 10:45 pm

Mon Aug 03, 2020 1:08 pm

Quite a few wrappers available, recommend either using them or reading the code: ... positories

Posts: 46
Joined: Mon Jun 03, 2019 2:56 pm

Mon Aug 03, 2020 2:23 pm

Are there any you would recommend?

Post Reply

Return to “Betfair Exchange API”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest