-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathticksAgent.js
More file actions
30 lines (24 loc) · 815 Bytes
/
ticksAgent.js
File metadata and controls
30 lines (24 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import socketIo from 'socket.io-client'
import { convertCryptocompareObject, Progress } from './util'
import fetch from 'node-fetch'
global.fetch = fetch
export default function (produceCallback) {
// FIXME: stale code
var socket = socketIo.connect('https://streamer.cryptocompare.com/')
socket.emit('SubAdd', { 'subs': ['0~Coinbase~ETH~USD'] })
let tickProgress = new Progress('tick', 0).read()
socket.on('m', (message) => {
let [type, ...rest] = message.split('~')
switch (type) {
case '0':
let priceObject = convertCryptocompareObject(rest)
if (tickProgress.value < priceObject.tick) {
produceCallback(priceObject.tick, [priceObject.price])
tickProgress.value = priceObject.tick
}
break
case '3':
break
}
})
}