<commit_before>Logger = require '../utils/Logger'
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
WebSocket = require 'ws'

class Buttercoin

  NAME = 'BUTTERCOIN'
  CURRENCY = 'BTC'
  INTERVAL = 10000

  cb = null
  ws = null
  wsLoop = null
  getTickerMessage = "{\"query\":\"TICKER\",\"currencies\":[\"USD\",\"BTC\"]}"

  lastBid = null
  lastAsk = null


  @start = (callback) ->
    cb = callback
    restartWebSocket()
    return {
      name: NAME,
      metadata: {
        image: 'http://static.bitcointicker.matthisp.com/buttercoin.png'
      }
    }


  restartWebSocket = ->
    try
      ws.close() if ws?
      clearInterval wsLoop if wsLoop?
      ws = new WebSocket 'wss://api.buttercoin.com/api/v1/websocket', { protocolVersion: 13, origin: 'https://www.buttercoin.com' }

      ws.on 'message', (data) ->
        handleMessage data

      ws.on 'open', () ->
        sendMessage getTickerMessage
        wsLoop = setInterval () ->
          sendMessage getTickerMessage
        , INTERVAL

      ws.on 'close', () ->
        Logger.error 'Buttercoin websocket closed'
        restartWebSocket()

      ws.on 'error', (err) ->
        Logger.error 'Buttercoin error\n' + err
        restartWebSocket()<commit_msg>Updated Buttercoin API url<commit_after>Logger = require '../utils/Logger'
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
WebSocket = require 'ws'

class Buttercoin

  NAME = 'BUTTERCOIN'
  CURRENCY = 'BTC'
  INTERVAL = 10000

  cb = null
  ws = null
  wsLoop = null
  getTickerMessage = "{\"query\":\"TICKER\",\"currencies\":[\"USD\",\"BTC\"]}"

  lastBid = null
  lastAsk = null


  @start = (callback) ->
    cb = callback
    restartWebSocket()
    return {
      name: NAME,
      metadata: {
        image: 'http://static.bitcointicker.matthisp.com/buttercoin.png'
      }
    }


  restartWebSocket = ->
    try
      ws.close() if ws?
      clearInterval wsLoop if wsLoop?
      ws = new WebSocket 'wss://wsio.buttercoin.com/api/v1/websocket', { protocolVersion: 13, origin: 'https://www.buttercoin.com' }

      ws.on 'message', (data) ->
        handleMessage data

      ws.on 'open', () ->
        sendMessage getTickerMessage
        wsLoop = setInterval () ->
          sendMessage getTickerMessage
        , INTERVAL

      ws.on 'close', () ->
        Logger.error 'Buttercoin websocket closed'
        restartWebSocket()

      ws.on 'error', (err) ->
        Logger.error 'Buttercoin error\n' + err
        restartWebSocket()
{'fraction_non_alphanumeric': 0.13962873284907182, 'fraction_numerical': 0.007263922518159807, 'mean_word_length': 2.3958904109589043, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305665', 'n_tokens_mistral': 884, 'n_tokens_neox': 815, 'n_words': 172}