I am still struggling to understand the instructions for the API. I have a working app but it stops every few hours because I cannot work out how to operate keepAlive. The best I can understand is to treat it like any other operation eg listMarketBook and run it at intervals. So using Javascript and node that is what I have done and the relevant lines of code are shown below. Trouble is I get a No Such Operation error report and the whole thing comes to a halt.
To log in I am logging in to the website manually and then generating a Session Token which is the ssid in options. I can then run every other Exchange Operation using the code below with whatever exchange operation it is substituting for keepAlive.
I have searched the forum for a program example of how to do keepAlive with no success and hope someone can explain where I am going wrong.
I get exactly the same error code DSC-0021 if I run keepAlive directly so I believe the problem is with function keepAlive(options) rather than the syntax of my setInterval
var options = {
hostname: 'api.betfair.com',
port: 443,
path: '/exchange/betting/json-rpc/v1',
method: 'POST',
headers: {
'X-Application' : appkey,
'Accept': 'application/json',
'Content-type' : 'application/json',
'X-Authentication' : ssid
}
}
setInterval(keepAlive,1000*60*15,options);
function constructJsonRpcRequest(operation, params) {
return '{"jsonrpc":"2.0","method":"SportsAPING/v1.0/' + operation + '", "params": ' + params + ', "id": 1}';
}
function keepAlive(options) {
var str = '';
var requestFilters = '{"filter":{}}';
var jsonRequest = constructJsonRpcRequest('keepAlive', requestFilters );
var req = https.request(options,function (res){
res.setEncoding(DEFAULT_ENCODING);
res.on('data', function (chunk) {
str += chunk;
});
res.on('end', function (chunk) {
var response = JSON.parse(str);
handleError(response);
console.log("keep Alive = ");
console.log(JSON.stringify(response, null, DEFAULT_JSON_FORMAT));
});
});
req.write(jsonRequest, DEFAULT_ENCODING);
req.end();
req.on('error', function(e) {
console.log('Problem with request: ' + e.message);
});
} // end of keepAlive
To log in I am logging in to the website manually and then generating a Session Token which is the ssid in options. I can then run every other Exchange Operation using the code below with whatever exchange operation it is substituting for keepAlive.
I have searched the forum for a program example of how to do keepAlive with no success and hope someone can explain where I am going wrong.
I get exactly the same error code DSC-0021 if I run keepAlive directly so I believe the problem is with function keepAlive(options) rather than the syntax of my setInterval
var options = {
hostname: 'api.betfair.com',
port: 443,
path: '/exchange/betting/json-rpc/v1',
method: 'POST',
headers: {
'X-Application' : appkey,
'Accept': 'application/json',
'Content-type' : 'application/json',
'X-Authentication' : ssid
}
}
setInterval(keepAlive,1000*60*15,options);
function constructJsonRpcRequest(operation, params) {
return '{"jsonrpc":"2.0","method":"SportsAPING/v1.0/' + operation + '", "params": ' + params + ', "id": 1}';
}
function keepAlive(options) {
var str = '';
var requestFilters = '{"filter":{}}';
var jsonRequest = constructJsonRpcRequest('keepAlive', requestFilters );
var req = https.request(options,function (res){
res.setEncoding(DEFAULT_ENCODING);
res.on('data', function (chunk) {
str += chunk;
});
res.on('end', function (chunk) {
var response = JSON.parse(str);
handleError(response);
console.log("keep Alive = ");
console.log(JSON.stringify(response, null, DEFAULT_JSON_FORMAT));
});
});
req.write(jsonRequest, DEFAULT_ENCODING);
req.end();
req.on('error', function(e) {
console.log('Problem with request: ' + e.message);
});
} // end of keepAlive


Comment