src/exchanges/kraken-client.js
/**
    When a subscription is initiated, a subscriptionStatus event is sent.
    This message will be cached in the subscriptionLog for look up later.
    When messages arrive, they only contain the subscription id.  The
    id is used to look up the subscription details in the subscriptionLog
    to determine what the message means.
   */
When a subscription is initiated, a subscriptionStatus event is sent.
This message will be cached in the subscriptionLog for look up later.
When messages arrive, they only contain the subscription id.  The
id is used to look up the subscription details in the subscriptionLog
to determine what the message means.
When a subscription is initiated a subscriptionStatus event is sent . This message will be cached in the subscriptionLog for look up later . When messages arrive they only contain the subscription id . The id is used to look up the subscription details in the subscriptionLog to determine what the message means .
_processsMessage(msg) {
    if (msg.event === "heartbeat") {
      return;
    }
    if (msg.event === "systemStatus") {
      return;
    }
    if (msg.event === "subscriptionStatus") {
      this.subscriptionLog.set(parseInt(msg.channelID), msg);
      return;
    }
    if (!Array.isArray(msg)) {
      return;
    }
    let [subscriptionId, details] = msg;
    let sl = this.subscriptionLog.get(subscriptionId);
    let remote_id = this.fromWsMap.get(sl.pair);
    if (sl.subscription.name === "ticker") {
      let market = this._tickerSubs.get(remote_id);
      if (!market) return;
      let ticker = this._constructTicker(details, market);
      if (ticker) {
        this.emit("ticker", ticker, market);
      }
      return;
    }
    if (sl.subscription.name === "trade") {
      if (Array.isArray(msg[1])) {
        let market = this._tradeSubs.get(remote_id);
        if (!market) return;
        msg[1].forEach(t => {
          let trade = this._constructTrade(t, market);
          if (trade) {
            this.emit("trade", trade, market);
          }
        });
      }
      return;
    }
    if (sl.subscription.name === "ohlc") {
      let market = this._candleSubs.get(remote_id);
      if (!market) return;
      let candle = this._constructCandle(msg, market);
      this.emit("candle", candle, market);
      return;
    }
    if (sl.subscription.name === "book") {
      let market = this._level2UpdateSubs.get(remote_id);
      if (!market) return;
      let isSnapshot = !!msg[1].as;
      if (isSnapshot) {
        let l2snapshot = this._constructLevel2Snapshot(msg[1], market);
        if (l2snapshot) {
          this.emit("l2snapshot", l2snapshot, market);
        }
      } else {
        let l2update = this._constructLevel2Update(msg[1], market);
        if (l2update) {
          this.emit("l2update", l2update, market);
        }
      }
    }
    return;
  }
_processsMessage ( msg ) { if ( msg . event === "heartbeat" ) { return ; } if ( msg . event === "systemStatus" ) { return ; } if ( msg . event === "subscriptionStatus" ) { this . subscriptionLog . set ( parseInt ( msg . channelID ) , msg ) ; return ; } if ( ! Array . isArray ( msg ) ) { return ; } let [ subscriptionId , details ] = msg ; let sl = this . subscriptionLog . get ( subscriptionId ) ; let remote_id = this . fromWsMap . get ( sl . pair ) ; if ( sl . subscription . name === "ticker" ) { let market = this . _tickerSubs . get ( remote_id ) ; if ( ! market ) return ; let ticker = this . _constructTicker ( details , market ) ; if ( ticker ) { this . emit ( "ticker" , ticker , market ) ; } return ; } if ( sl . subscription . name === "trade" ) { if ( Array . isArray ( msg [ 1 ] ) ) { let market = this . _tradeSubs . get ( remote_id ) ; if ( ! market ) return ; msg [ 1 ] . forEach ( t => { let trade = this . _constructTrade ( t , market ) ; if ( trade ) { this . emit ( "trade" , trade , market ) ; } } ) ; } return ; } if ( sl . subscription . name === "ohlc" ) { let market = this . _candleSubs . get ( remote_id ) ; if ( ! market ) return ; let candle = this . _constructCandle ( msg , market ) ; this . emit ( "candle" , candle , market ) ; return ; } if ( sl . subscription . name === "book" ) { let market = this . _level2UpdateSubs . get ( remote_id ) ; if ( ! market ) return ; let isSnapshot = ! ! msg [ 1 ] . as ; if ( isSnapshot ) { let l2snapshot = this . _constructLevel2Snapshot ( msg [ 1 ] , market ) ; if ( l2snapshot ) { this . emit ( "l2snapshot" , l2snapshot , market ) ; } } else { let l2update = this . _constructLevel2Update ( msg [ 1 ] , market ) ; if ( l2update ) { this . emit ( "l2update" , l2update , market ) ; } } } return ; }
When a subscription is initiated, a subscriptionStatus event is sent.
When a subscription is initiated a subscriptionStatus event is sent .
// Capture the subscription metadata for use later. /*
        {
          channelID: '15',
          event: 'subscriptionStatus',
          pair: 'XBT/EUR',
          status: 'subscribed',
          subscription: { name: 'ticker' }
        }
      */ // All messages from this point forward should arrive as an array // If we don't have a subscription log entry for this event then // we need to abort since we don't know what to do with it! // From the subscriptionLog entry's pair, we can convert // the ws symbol into a rest symbol // tickers // trades // candles //l2 updates // snapshot use as/bs // updates us a/b