Issue in making connections and getting data from exchange streap api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mak
    Junior Member
    • Jan 2019
    • 1

    #1

    Issue in making connections and getting data from exchange streap api

    I want to make multiple connections through one authorization and simultaneously they can receive their data i had tried two things
    1. I tried to authenticate every connection then i am getting error "MAX_CONNECTION_LIMIT_EXCEED"
    2. I tried to authenticate only once and then writing multiple queries it is working fine but i do not know how to disconnect a particular connection
    if i try to disconnect tls module in node js then all the connections got close and on reconnecting it is giving error "socket has been ended by other party"

    please help me to find a feasible solution so that i can
    1.Make multiple connections with one time authorization
    2.can disconnect particular socket with connection id or something else

    I am using this code in node js

    1. for making tls connection and authorization

    function connected(stream) {
    if (stream) {
    stream.write(`{"op": "authentication", "appKey": "${process.env.BETFAIR_API_KEY}", "session": "${sessionData.token}" }\r\n`);
    } else {
    console.log('Connection failed');
    }
    }


    var dummy = this;

    dummy = tls.connect(443, 'stream-api.betfair.com', function() {
    dummy.connected = true;
    if (dummy.authorized) {
    console.log('connection is authorizedddedede')
    dummy.setEncoding('utf-8');
    connected(dummy);
    } else {
    console.log(dummy.authorizationError);
    connected(null);
    }

    });
    global.dummy = dummy;

    2.for writing queries
    try {
    console.log('we are in try block')
    global.dummy.write(`{"op":"marketSubscription","ma rketFilter":{"marketIds":[${data.marketIdArray}],"bettingTypes":["ODDS"],"eventTypeIds":[${data.eventTypeIdArray}],"eventIds":[${data.eventId}]},"marketDataFilter":{}}\r\n`);
    } catch (e) {
    console.log('we are in catch')
    console.log(e)
    }


    users.push({ id: data.socketId, tls: global.dummy });
    global.clients = users;

    3.for disconnecting socket

    socket.on('betfair_socket_disconnect', (data) => {


    console.log('global.clients', global.clients)

    if (global.clients) {


    var x = _.filter(global.clients, function(item) {
    return item.id == data.socketId;
    });
    x[0].tls.end();
    }
Working...
X