-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (42 loc) · 1.47 KB
/
app.js
File metadata and controls
48 lines (42 loc) · 1.47 KB
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
let ws = new WebSocket('wss://stream.binance.com:9443/ws/ethusdt@trade');
let statu = document.getElementById('st');
let p_l =document.getElementById('l');
ws.onmessage = (event) => {
let stockObject =JSON.parse(event.data);
var g = localStorage.getItem("price");
var tar = localStorage.getItem("target");
var sl = localStorage.getItem("stoploss");
var amt = localStorage.getItem("Amount");
var z = Math.round(stockObject.p * 100)/ 100;
if (tar == 0 ){
tar = 99999;
}
if (sl == 0){
sl = 0;
}
if(z == g && statu.innerText!=="__CLOSED"){
statu.innerText = "_EXECUTED";
}else if(z!==g && statu.innerText !== "_EXECUTED" && statu.innerText!=="__CLOSED"){
statu.innerText = "_PENDING_";
}
if (statu.innerText !=="__CLOSED" && statu.innerText!=="_PENDING_"){
var t = Math.round(((z-g)/g)*amt*10*100)/100
localStorage.setItem("pro",t)
}
if (statu.innerText =="__CLOSED"){
var d = localStorage.getItem("pro")
localStorage.setItem("profit",d)
}
if (tar <= z && statu.innerText=="_EXECUTED"){
statu.innerText = "__CLOSED";
}else if (sl >= z && statu.innerText=="_EXECUTED"){
statu.innerText = "__CLOSED";
}
if (t >0 && statu.innerText!=="__CLOSED" && statu.innerText!=="_PENDING_"){
p_l.innerText ='+'+ t
document.getElementById('l').style.color = "green";
}else if (statu.innerText!=="__CLOSED" && t < 0 && statu.innerText!=="_PENDING_"){
p_l.innerText=t
document.getElementById('l').style.color="red";
}
}