Skip to content

Stop from receiving the data #8

@ajay92x

Description

@ajay92x

I'm using the following code multiple times to get the odds of different event.

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");
});

function getMarketData(marketIdArray, eventTypeIdArray, eventIdArray) {
/* Send authentication message */
client.write('{"op": "authentication", "appKey": "APIKEY", "session": "TOKEN"}\r\n');

/* Subscribe to order/market stream */
stream.write({"op":"marketSubscription","marketFilter":{"marketIds":[${marketIdArray}],"bettingTypes":["ODDS"],"eventTypeIds":[${eventTypeIdArray}],"eventIds":[${eventIdArray}]},"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);
});
}

router.get('/getMarketData', function(req, res, next) {

getMarketData(req.marketIdArray, req.eventTypeIdArray, req.eventIdArray);

})

The problem is that once I start getting the odds then it continue even if I close my browser.
Lets suppose in one browser tab I have open odds for cricket and in 2nd browser tab for tennis. Now, I'm getting the odds for both which is good. Now, if I close the first browser tab of cricket then I want to stop receiving the odds but in my server I can still see the odds receiving.

So, how can I stop receiving the odds once the browser is closed or is there any event to stop receving the odds.

Any help or suggestions or ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions