I'm attempting to login via the non-interactive login and access streaming via Node.js.
There was a useful example (which I now can't find) of someone logging into the Betting API via Node.js, which I managed to replicate, however the Streaming API is currently proving difficult.
I have also played around with Betfairlightweight (i.e. the Python wrapper) and from that and the Node.js example (that I can't find), I know my certs / credentials are correct.
However, if I attempt to access the streaming API, I get the following error:
If I'm interpreting that correctly then I believe my certificate / key are probably not being passed to the server correctly (however I may be wrong).
I'm hoping with all the smart people on here, someone will be able to spot my error and then I can continue to upload sample code as the project progresses.
Here is my code:
I'm at a dead end here, so any pointers would be greatly appreciated.
There was a useful example (which I now can't find) of someone logging into the Betting API via Node.js, which I managed to replicate, however the Streaming API is currently proving difficult.
I have also played around with Betfairlightweight (i.e. the Python wrapper) and from that and the Node.js example (that I can't find), I know my certs / credentials are correct.
However, if I attempt to access the streaming API, I get the following error:
Code:
Received: {"op":"connection","connectionId":"003-310119210425-261018"}
Received: {"op":"status","statusCode":"FAILURE","errorCode":"INVALID_SESSION_INFORMATION","errorMessage":"InvalidCredentials","connectionClosed":true,"connectionId":"003-310119210425-261018"}
I'm hoping with all the smart people on here, someone will be able to spot my error and then I can continue to upload sample code as the project progresses.
Here is my code:
Code:
var https = require('https');
var fs = require('fs');
var tls = require('tls');
//'use strict';
const PORT = 443;
const HOST = 'stream-api.betfair.com';
// Pass the certs to the server and let it know to process even unauthorized certs.
var options = {
key: fs.readFileSync('FULL_FILE_PATH.key'),
cert: fs.readFileSync('FULL_FILE_PATH.crt')
};
var client = tls.connect(PORT, HOST, options, function() {
console.log("Connected");
client.on('data', function(data) {
console.log('Received: ' + data);
client.write('{"op": "authentication", "id": "1", "username": "USERNAME", "password": "PASSWORD", "appKey": "APPKEY", "session": "' + data.sessionToken + '"}\r\n');
});
});


Comment