Permalink
Browse files

add convenience trade handlers

  • Loading branch information...
robertkowalski committed Sep 23, 2018
1 parent c156c93 commit 18d2b536780a7e6900ece2b5b37d138073e683c6
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/mandelbrot-ws-base.js
View
@@ -29,6 +29,7 @@ class MandelbrotBase extends EventEmitter {
this._channels = {}
this._bookHandlers = {}
this._tradeHandlers = {}
this._infoHandlers = {}
this._managedHandlers = {}
@@ -179,6 +180,20 @@ class MandelbrotBase extends EventEmitter {
const [ chanId, data ] = msg
if (data === 'te' || data === 'tu') {
const { symbol } = this._channels['trades'][chanId]
const handler = this._tradeHandlers[symbol]
if (!handler) return
handler(msg)
return
}
if (!this._channels['book'][chanId]) {
console.error('received invalid channel id from api, id:', chanId)
return
}
const { symbol } = this._channels['book'][chanId]
const tOpts = this.conf.transform.orderbook
@@ -270,6 +285,12 @@ class MandelbrotBase extends EventEmitter {
this._infoHandlers[k] = handler
}
onTrades (filter, handler) {
const { symbol } = filter
this._tradeHandlers[symbol] = handler
}
onTradeUpdate (filter, handler) {
const { symbol } = filter

0 comments on commit 18d2b53

Please sign in to comment.