Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop from receiving the data #8

Open
ajay92x opened this issue Aug 6, 2019 · 1 comment
Open

Stop from receiving the data #8

ajay92x opened this issue Aug 6, 2019 · 1 comment

Comments

@ajay92x
Copy link

ajay92x commented Aug 6, 2019

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?

@liampauling
Copy link

Not quite sure how you are running this and why a browser is involved but it’s a socket so you need to close it.

Client.Stop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants