Skip to content

OHLC server for showing the near real time data to different subscribers, Subscribing for different stocks.

Notifications You must be signed in to change notification settings

VaibhavAjayGupta/ohlc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node OHLC server

Gihub Repo link :- https://github.com/VaibhavAjayGupta/ohlc

Steps to run

  1. git clone git@github.com:VaibhavAjayGupta/ohlc.git
  2. cd ohlc
  3. npm install
  4. npm run start
  5. open localhost:3000 on browser
  6. subscribe to XZECXXBT

Design

  1. Async line by line file reading (using stream) module readline. - for reading the data line by line using stream and non blocking.

  2. 2 workers
    generateChartData - for parsing the response , computing the OHLC packet, and constructing BAR chart data.
    webSocketServer - for implementing the websocket which maintains the client list and publish the data which is computed in realtime.

Classes & Methods

StockBarData class is used for storing the bar data.
Methods:-

  1. constructor(open,symbol,volume,bar_num) - for creating new bar with open, symbol, volume and bar_num.
  2. updateVolume(value) - for updating volume of bar.
  3. updateClose() for updating the close.
  4. updateLow(value) for updating low.
  5. updateHigh(value) for updating high.

PubSubManager is used for maintaining the list of subscribed clients and publish the data.
Methods:-

  1. subscribe(subscriber, channel) - for subscribing to a particular stock(channel).
  2. publish(channel, message) - for publishing a message to a particular stock(channel).
  3. broker() - for publishing messages to all the stocks(channels).

DataStructers

  1. Map is used for storing different subscribers for different stocks.
  2. Map is used for storing different bars.

Flow of project

  1. Reading file using a readline module which reads the file using stream, line by line without blocking the main thread.
  2. The line by line response is then posted immediately to a separate worker (generateChartData) for parsing, computing the OHLC packet, and constructing BAR chart data.
  3. Realtime computed data is then posted to a separate worker (webSocketServer).
  4. webSocketServer maintains the list of subscribed clients and publish the response in realtime as received from the generateChartData.
  5. OHLC data is sent on Every trade.
  6. Output on Every Trade {"o":0.01762,"h":0.01762,"l":0.01762,"lastTrade":0.01762,"c":0.01762,"volume":7.8251401,"event":"ohlc_notify","symbol":"XZECXXBT","bar_num":10631}

Note :

  1. You won't see any data after subscribing to a particular stock because as soon as the node server is started it's done reading all the data from file and all the data is pushed to the already exisiting clients. As there is no new data pushed to the websocket there is no data recieved by the client.
  2. TS2 TimeStamp conversion - first 16 digits are the seconds, and the last 9 are nanoseconds.

About

OHLC server for showing the near real time data to different subscribers, Subscribing for different stocks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published