-
Notifications
You must be signed in to change notification settings - Fork 63
Description
I have tried using the following code to get the market data and it is working but sometimes I'm getting the error "socket has been ended by other party" and then I have to restart the server to make it work again.
var tls = require('tls');
/* Socket connection options */
var options = {
host: 'stream-api.betfair.com',
// host: 'stream-api-integration.betfair.com',
port: 443
}
/* Establish connection to the socket */
var client = tls.connect(options, function () {
console.log("Connected");
});
/* Send authentication message */
client.write('{"op": "authentication", "appKey": "APIKEY", "session": "TOKEN"}\r\n');
/* Subscribe to order/market stream */
stream.write({"op":"marketSubscription","marketFilter":{"marketIds":["1.160865586"],"bettingTypes":["ODDS"],"eventTypeIds":["2"],"eventIds":["29390842"]},"marketDataFilter":{}}\r\n);
client.on('data', function(data) {
console.log('Received: ' + data);
});
client.on('close', function() {
console.log('Connection closed');
});
client.on('error', function(err) {
console.log('Error:' + err);
})