API help using JavaScript / node.js

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

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 auth.sh file which logs me in fine and I pass the token to the options below.
let options = {
hostname: 'api.betfair.com',
port: 443,
path: 'api.betfair.com/exchange/betting/json-rpc/v1',
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.setEncoding(DEFAULT_ENCODING);

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);
handleError(response);
// Retrieve id from response and get next available horse race
// getNextAvailableHorseRace(options, response);
});

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

req.on('error', function(e) {
console.log('Problem with request: ' + e.message);
});
}
LinusP
Posts: 1871
Joined: Mon Jul 02, 2012 10:45 pm

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

https://github.com/search?l=JavaScript& ... positories
Xeres
Posts: 52
Joined: Mon Jun 03, 2019 2:56 pm

Are there any you would recommend?
Post Reply

Return to “Betfair Exchange API”