forked from moataz-metwally/mt4-ea-web-interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.js
84 lines (58 loc) · 1.6 KB
/
webserver.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
/**
* @author Moataz Metwally <[email protected]>
*/
var express = require("express");
var app = express();
var path = require("path");
var bodyParser = require('body-parser');
var status = 0;
var close_all_orders = 0;
var close_all_pending_orders = 0;
app.engine('html', require('ejs').renderFile)
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/ea-check',function(req,res){
var outObj = {
status: status,
close_all_orders: close_all_orders,
close_all_pending_orders: close_all_pending_orders
}
close_all_orders = 0;
close_all_pending_orders = 0;
res.send(JSON.stringify(outObj)); //Write the response
});
app.get('/ea-web',function(req,res){
var status_text="";
if(status){
status_text="Running";
}else{
status_text="Stopped";
}
res.render('web_ea.html',{status_ea:status_text});
});
app.post('/ea-web',function(req,res){
if(req.body.start){
status = 1 ;
}else if(req.body.stop){
status = 0 ;
}
else if(req.body.close_all_orders){
close_all_orders = 1;
}
else if(req.body.close_all_pendings){
close_all_pending_orders = 1;
}
var status_text="";
if(status){
status_text="Running";
}else{
status_text="Stopped";
}
console.log("Status:"+status+"\r\n");
console.log("close_all_orders:"+close_all_orders+"\r\n");
console.log("close_all_pending_orders:"+close_all_pending_orders+"\r\n");
res.render('web_ea.html',{status_ea:status_text});
});
app.listen(3000);
console.log("Running at Port 3000");