-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
108 lines (95 loc) · 2.5 KB
/
server.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Add required coins to the ledg vatiable
ticker coins should be added to thr tick variable
*/
let ledg = {
REP: {},
KNC: {},
};
let tick = ['XMR', 'DASH', 'XRP']
const express = require('express');
const server = express();
const servermod = require('http').createServer(server);
// socket.io
const io = require('socket.io')(servermod);
io.on('connection', client => {
client.emit('list', [Object.keys(ledg), tick]);
gloBus.emit('ready', 'balls')
});
// telebot
// const TeleBot = require('telebot');
// const bot = new TeleBot('455360254:YOUR_API_KEY');
// serve
server.use(express.static(__dirname + '/node_modules'));
server.use('/public', express.static('public'));
server.get('/', (req, res) => {
res.sendFile('index.html', {
root: __dirname
});
});
servermod.listen(5555, function() {
console.log('arbMan listening on port 5555');
});
// globus
const EventEmitter = require('events');
const gloBus = new EventEmitter();
gloBus.on('order', obj => {
ledg[obj.name][obj.asks[0].exchange] = obj;
globook = Object.keys(ledg[obj.name]).reduce(
(i, elm) => {
return {
asks: i.asks.concat(ledg[obj.name][elm].asks),
bids: i.bids.concat(ledg[obj.name][elm].bids)
};
}, {
asks: [],
bids: []
}
);
const fbook = {
asks: globook.asks.sort((a, b) => a.price - b.price),
bids: globook.bids.sort((a, b) => b.price - a.price),
name: obj.name
};
io.emit('order', fbook);
require('./arbMain.js').go(gloBus, fbook);
});
gloBus.on('trade', obj => {
io.emit('trade', obj);
// bot.sendMessage(442494900, 'trade \n' + JSON.stringify(obj));
});
gloBus.on('balance', obj => {
io.emit('balance', obj);
});
gloBus.on('rate', obj => {
io.emit('rate', obj);
});
gloBus.on('arb', obj => {
io.emit('arb', obj);
let flat = obj.reduce(
(flat, elm) => {
flat.profit += parseFloat(elm.profit);
flat.tokens += parseFloat(elm.tokens);
flat.buy.push(elm.buy);
flat.sell.push(elm.sell);
return flat;
}, {
profit: 0,
tokens: 0,
buy: [],
sell: [],
}
);
// bot.sendMessage(442494900, obj[0].name + '\n' + JSON.stringify(flat));
});
gloBus.on('play', name => {
io.emit('play', name);
});
// main app pages
gloBus.on('tick', name => {
io.emit('tick', name);
});
require('./exc/ede.js').listnr(gloBus, Object.keys(ledg));
require('./exc/bin.js').listnr(gloBus, Object.keys(ledg), tick);
require('./exc/liv.js').listnr(gloBus, Object.keys(ledg));
require('./exc/ide.js').listnr(gloBus, Object.keys(ledg));