Coder Social home page Coder Social logo

Comments (4)

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024 1

Hi. Thanks for your comments.

I'm not sure exactly what the bug you're referring to is (could you describe it ? ;)). Regarding your questions, here's my answers :

  1. clearTimeout / clearInterval

You're probably right as for consistency I should use clearInterval but nodejs will handle it properly as explained in https://nodejs.org/api/timers.html#timers_class_timeout

This object is created internally and is returned from setTimeout() and setInterval(). It can be passed to either clearTimeout() or clearInterval() in order to cancel the scheduled actions

  1. ignoreCloseEvent

This is set to false when ws is opened, since close events should be handled. But if ws is explicitely closed by calling disconnect method, event will be ignored

  1. skipCloseEvent

It is needed since in case error event is triggered, there is no need to also handle the close event

  1. doRetry

It is also necessary since in case a connection error occurs, function will be retried automatically up to 10 times (I can tell you that sometimes it can take multiple retries before connection is established). See https://github.com/tim-kos/node-retry for information regarding retry library

  1. Noop ping

If you check the code for ping method, you will notice that when doing ws.ping(noop) ws library will actually do a ping('', true) and call the noop callback. Also in the version 3.2.0 (which is used by the gateway), the prototype of ping method is a bit different and does not accept a callback. For the moment, I don't see any reason to change the version used by gateway.

  1. Arrows

This would make code clearer I agree. Will keep it in mind.

from crypto-exchanges-gateway.

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024 1

Hi
startWs will start the WS server, so that you can open WS connections to the gateway. The WS connections to the exchanges will only be opened on-demand.

WS workflow is as below :

  • gateway is listening on ws://127.0.0.1:8001
  • ws client 1 connects to ws://127.0.0.1:8001/exchanges/binance/tickers/USDT-NEO
  • gateway will open a ws connection to binance to get realtime tickers info for USDT-NEO
  • ws client 2 connects to ws://127.0.0.1:8001/exchanges/binance/tickers/USDT-NEO
  • gateway will not open a new ws connection to binance since one already exist
  • ws client 1 disconnect
  • ws connection to binance still exist because it is still used for the second client
  • ws client 2 disconnect
  • ws connection to binance still exist because it is still used for the second client

At any moment, you can check which WS connections are opened for a given exchange by doing a REST request to http://127.0.0.1:8000/exchanges/binance/connections

See https://github.com/aloysius-pgast/crypto-exchanges-gateway/blob/master/doc/ws/endpoints.adoc for WS endpoints exposed by the gateway

from crypto-exchanges-gateway.

slidenerd avatar slidenerd commented on June 6, 2024

Awesome!!! Thanks for all the replies, I am closing this issue :)

from crypto-exchanges-gateway.

slidenerd avatar slidenerd commented on June 6, 2024

I am sorry if this sounds like a silly question but I had to ask, you seem to be creating a different websocket inside the session file but for each exchange you have a stream client and an exchange class which seems to be used by subscription manager of that exchange which in turn is used inside the routes file for that exchange, when I go to gateway.js, it seems to trigger startWs inside ws/main.js which in turn manages uses the websocket inside the session object, where and how does routes/subscription manager tie into this and more importantly, can you directly use the routes without the whole session, registry and storage thingies

from crypto-exchanges-gateway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.