Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have successfully opened a websocket connection in server to an external API to get exchange ticker data but not sure how to continuously push the data to client / AngularJS.

Here is the router code:

router.get('/live-ticker', function(req, res) {


  var autobahn = require('autobahn');
  var wsuri = "wss://api.poloniex.com";
  var connection = new autobahn.Connection({
    url: wsuri,
    realm: "realm1"
  });

  connection.onopen = function(session) {

    function tickerEvent(args, kwargs) {

      res.json(args);
      console.log(args);

    }


    session.subscribe('ticker', tickerEvent);

  }

  connection.onclose = function() {
    console.log("Websocket connection closed");
  }

  connection.open();

});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
313 views
Welcome To Ask or Share your Answers For Others

1 Answer

you need to push data from the server periodically.

to get these "live updates" on the client side, a plain ajax call is not enough, you need a realtime communication.

You should use websoket even here, with socket.io and angular socket.io for example you can handle this communication easily


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...