window.onload = function(){
const list = document.getElementsByTagName("fieldset");
for (var i = 0; i < list.length; i++) {
let id = list[i].id;
//console.log(id);
const DBTime = document.getElementById("DBTime-"+id);
sessionStorage.setItem("DBTime",DBTime.value);
// console.log(DBTime.value);
const PNL = document.getElementById("PNL-"+id);
PNL.value = sessionStorage.getItem("PNL-"+id);
const BuyPrice = document.getElementById("BuyPrice-"+id);
BuyPrice.value = sessionStorage.getItem("BuyPrice-"+id);
const EstWin = document.getElementById("EstWin-"+id);
EstWin.value = sessionStorage.getItem("EstWin-"+id);
const EstLoss = document.getElementById("EstLoss-"+id);
EstLoss.value = sessionStorage.getItem("EstLoss-"+id);
//console.log("BuyPrice Session getted" +BuyPrice.value);
const Delete = document.getElementById("Delete-"+id);
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+id);
const WinSellPrice = document.getElementById("WinSellPrice-"+id);
const LossTriggerPrice = document.getElementById("LossTriggerPrice-"+id);
const LossSellPrice = document.getElementById("LossSellPrice-"+id);
const PanicPrice = document.getElementById("PanicPrice-"+id);
const APIOrderID = document.getElementById("APIOrderID-"+id).value;
const OrderFilled = document.getElementById("OrderFilled-"+id).value;
if(APIOrderID==="")
{
}
else
{ if (OrderFilled == "0")
{
Delete.style.background='#dd5252';
Delete.disabled=true;
}
WinTriggerPrice.disabled=true;
WinSellPrice.disabled=true;
LossTriggerPrice.disabled=true;
LossSellPrice.disabled=true;
PanicPrice.disabled=true;
}
if(PNL.value > 0.00)
{
PNL.style.background="green";
PNL.style.color="white";
}
else if(PNL.value < 0.00)
{
PNL.style.background="red";
PNL.style.color="white";
}
else
{
PNL.style.background="white";
PNL.style.color="black";
}
if(EstWin.value > 0.00)
{
EstWin.style.background="green";
EstWin.style.color="white";
}
else if(EstWin.value < 0.00)
{
EstWin.style.background="red";
EstWin.style.color="white";
}
else
{
EstWin.style.background="white";
EstWin.style.color="black";
}
if(EstLoss.value > 0.00)
{
EstLoss.style.background="green";
EstLoss.style.color="white";
}
else if(EstLoss.value < 0.00)
{
EstLoss.style.background="red";
EstLoss.style.color="white";
}
else
{
EstLoss.style.background="white";
EstLoss.style.color="black";
}
}
};
let x=0;
setInterval(function() {
const Sides = document.getElementsByClassName("Side");
const list = document.getElementsByTagName("fieldset");
for (var i = 0; i < Sides.length; i++) {
let id = list[i].id;
let DBTime = document.getElementById("DBTime-"+id).value;
let TargetTextBox = document.getElementById("Timer-"+id).value;
var OldDate = new Date(DBTime).getTime();
var now = new Date().getTime();
var distance = now - OldDate;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("Timer-"+id).value = hours + ":"+ minutes + ":" + seconds;
const Delete = document.getElementById("Delete-"+id);
const APIOrderID = document.getElementById("APIOrderID-"+id).value;
const OrderFilled = document.getElementById("OrderFilled-"+id).value;
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+id);
const WinSellPrice = document.getElementById("WinSellPrice-"+id);
const LossTriggerPrice = document.getElementById("LossTriggerPrice-"+id);
const LossSellPrice = document.getElementById("LossSellPrice-"+id);
const PanicPrice = document.getElementById("PanicPrice-"+id);
if(APIOrderID==="")
{
}
else
{
if (OrderFilled == "0")
{
Delete.style.background='#dd5252';
Delete.disabled=true;
}
WinTriggerPrice.disabled=true;
WinSellPrice.disabled=true;
LossTriggerPrice.disabled=true;
LossSellPrice.disabled=true;
PanicPrice.disabled=true;
}
BuyPriceChange(list[i].id);
$.ajax({
url:"lib/myChart.php",
method:"POST",
dataType:"text",
success:function(data)
{
}
});
}
}, 1000);
setInterval(function() {
x++;
const legends = document.getElementsByTagName("legend");
const Sides = document.getElementsByClassName("Side");
const list = document.getElementsByTagName("fieldset");
for (var i = 0; i < Sides.length; i++) {
let id = list[i].id;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
//updateFields(id, myArr[0]);
//"CoinPrice","CoinBal", "APIOrderID", "Side"
document.getElementById(`CoinPrice-`+id).value = myArr[0]['CoinPrice'];
document.getElementById("CoinPrice-"+id).setAttribute("data-Price",myArr[0]['CoinPrice']);
// console.log("data-Price " +document.getElementById("CoinPrice-"+id).getAttribute("data-Price"));
document.getElementById(`CoinBal-`+id).value = myArr[0]['CoinBal'];
document.getElementById(`APIOrderID-`+id).value = myArr[0]['APIOrderID'];
document.getElementById(`Side-`+id).value = myArr[0]['Side'];
document.getElementById(`OrderFilled-`+id).value = myArr[0]['OrderFilled'];
//
// document.getElementById(`WinTriggerPrice-`+id).value = myArr[0]['WinTriggerPrice'];
// document.getElementById(`WinSellPrice-`+id).value = myArr[0]['WinSellPrice'];
// document.getElementById(`LossTriggerPrice-`+id).value = myArr[0]['LossTriggerPrice'];
// document.getElementById(`LossSellPrice-`+id).value = myArr[0]['LossSellPrice'];
// document.getElementById(`PanicPrice-`+id).value = myArr[0]['PanicPrice'];
}
};
xmlhttp.open("GET","lib/getprice.php?q="+id,true);
xmlhttp.send();
getLog(id);
let OrderFilled = document.getElementById(`OrderFilled-`+id).value;
// filled 1 2 7 animated 0
Sides[i].style.backgroundImage="url('rc_images/processing.gif')";
if(OrderFilled.includes("1"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderwin.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/filledwin.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
}
if(OrderFilled.includes("2"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderloss.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/filledloss.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
}
if(OrderFilled.includes("7"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderpanic.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/filledpanic.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
}
if(OrderFilled.includes("4"))
{
legends[i].style.backgroundImage="url('rc_images/canceled.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/canceled.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
/*
else
{
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/processing.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
}*/
}
if (OrderFilled.includes("0"))
{
if(Sides[i].value.includes("Win"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderwin.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/win.gif')";
Sides[i].style.backgroundSize="contain";
}
else if(Sides[i].value.includes("Loss"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderloss.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/loss.gif')";
Sides[i].style.backgroundSize="contain";
}
else if(Sides[i].value.includes("Panic"))
{
legends[i].style.backgroundImage="url('rc_images/coinheaderpanic.gif')";
legends[i].style.backgroundSize="contain";
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/panic.gif')";
Sides[i].style.backgroundSize="contain";
}
else
{
Sides[i].style.color="transparent";
Sides[i].style.backgroundImage="url('rc_images/processing.gif')";
Sides[i].style.backgroundRepeat="no-repeat";
Sides[i].style.backgroundSize="contain";
}
}
}
// document.getElementById("PNL-"+id);
}, 3000);
function getLog(id) {
$.ajax({
url:"lib/getLog.php",
method:"POST",
data:{CoinSymbol:id},
dataType:"text",
success:function(data)
{
const old = document.getElementById(`Log-`+id).innerHTML;
if(old.includes(data))
{}
else
{
document.getElementById(`Log-`+id).innerHTML = data;
}
//document.getElementById(`Log-`+id).scrollIntoView();
/* const element = document.createElement('p');
element.innerText = text;
const list = document.getElementById("myList");
list.appendChild(element);
*/
}
});
}
function updateFields(id, data) {
/*const fieldIds = [
"CoinPrice","CoinBal", "APIOrderID", "Side", "WinTriggerPrice",
"WinSellPrice", "LossTriggerPrice", "LossSellPrice", "PanicPrice"
];*/
const fieldIds = [
"CoinPrice","CoinBal", "APIOrderID", "Side"
];
fieldIds.forEach(field => {
document.getElementById(`${field}-${id}`).value = data[field];
});
}
function CoinPriceChange(x) {
// console.log(x.id);
var xmlhttp2 = new XMLHttpRequest();
xmlhttp2.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// console.log('visted');
}
};
xmlhttp2.open("GET","lib/myChart.php",true);
xmlhttp2.send();
}
/*
const BuyPrice<?php echo "$CoinSymbol"; ?> = document.getElementById("BuyPrice-<?php echo "$CoinSymbol"; ?>").addEventListener("change", myFunction);
console.log(BuyPrice<?php echo "$CoinSymbol"; ?>);*/
function BuyPriceChange(x) {
// console.log("x.id" +x);
const BuyPrice = document.getElementById("BuyPrice-"+x).value;
const CoinPrice = document.getElementById("CoinPrice-"+x).getAttribute("data-Price");
const CoinBal = parseFloat(document.getElementById("CoinBal-"+x).getAttribute("data-CoinBal"));
const PNL = document.getElementById("PNL-"+x); // Add it to Session
const BuyPriceSubmit = document.getElementById("BuyPriceSubmit-"+x);
const inputValue = parseFloat(BuyPrice);
const targetValue = CoinPrice/* Set your target value here */;
const threshold = targetValue * 0.4;
const isCloseToTarget = Math.abs(inputValue - targetValue) <= threshold;
calculateWinAndLoss(x);
sessionStorage.setItem("BuyPrice-"+x, inputValue);
// console.log("BuyPrice Session Setted");
PNL.value="";
sessionStorage.setItem("PNL-"+x, "");
PNL.style.background="white";
BuyPriceSubmit.disabled = true;
if (isCloseToTarget)
{
BuyPriceSubmit.disabled = false;
const Num1 = (BuyPrice * CoinBal);
const Num2 = (CoinPrice * CoinBal);
if(Num2 - Num1 > 0)
{
PNL.value = "+"+(Num2 - Num1).toFixed(2);
PNL.style.background="green";
PNL.style.color="white";
sessionStorage.setItem("PNL-"+x, "+"+(Num2 - Num1).toFixed(2));
// console.log("positive :"+sessionStorage.getItem("PNL-"+x.id));
}
else if(Num2 - Num1 < 0)
{
PNL.value = (Num2 - Num1).toFixed(2);
PNL.style.background="red";
PNL.style.color="white";
sessionStorage.setItem("PNL-"+x, (Num2 - Num1).toFixed(2));
// console.log("negative :"+sessionStorage.getItem("PNL-"+x.id));
//let PNLSession = sessionStorage.getItem("lastname");
}
else
{
PNL.style.background="white";
PNL.style.color="black";
}
}
}
function calculateWinAndLoss(x)
{
const BuyPrice = document.getElementById("BuyPrice-"+x).value;
const CoinBal = parseFloat(document.getElementById("CoinBal-"+x).getAttribute("data-CoinBal"));
const EstWin = document.getElementById("EstWin-"+x);
const EstLoss = document.getElementById("EstLoss-"+x);
const WinSellPrice = document.getElementById("WinSellPrice-"+x).value;
const LossSellPrice = document.getElementById("LossSellPrice-"+x).value;
EstWin.value="";
EstLoss.value="";
sessionStorage.setItem("EstWin-"+x, "");
sessionStorage.setItem("EstLoss-"+x, "");
//PNL.style.background="white";
if(!isNaN(BuyPrice) && !isNaN(parseFloat(BuyPrice)))
{
const EW = (CoinBal * WinSellPrice) - (CoinBal * BuyPrice);
const EL = (CoinBal * LossSellPrice) - (CoinBal * BuyPrice);
if(EW > 0)
{
EstWin.value = "+"+(EW).toFixed(2);
EstWin.style.background="green";
EstWin.style.color="white";
sessionStorage.setItem("EstWin-"+x, "+"+(EW).toFixed(2));
}
else if(EW <= 0)
{
EstWin.value = (EW).toFixed(2);
EstWin.style.background="red";
EstWin.style.color="white";
sessionStorage.setItem("EstWin-"+x, (EW).toFixed(2));
}
if(EL > 0)
{
EstLoss.value = "+"+(EL).toFixed(2);
EstLoss.style.background="green";
EstLoss.style.color="white";
sessionStorage.setItem("EstLoss-"+x, "+"+(EL).toFixed(2));
}
else if(EL <= 0)
{
EstLoss.value = (EL).toFixed(2);
EstLoss.style.background="red";
EstLoss.style.color="white";
sessionStorage.setItem("EstLoss-"+x, (EL).toFixed(2));
}
}
}
function fundel(x)
{
let APIOrderID = document.getElementById("APIOrderID-"+x.id).value;
const OrderFilled = document.getElementById("OrderFilled-"+x.id).value;
if(APIOrderID=="")
{
if (confirm("Are you sure you want to delete this Order?")) {
let CoinSymbol = x.id;
$.ajax({
url:"delete.php",
method:"POST",
data:{CoinSymbol:CoinSymbol},
dataType:"text",
success:function(data)
{
x.remove();
}
});
}
}
if (OrderFilled != 0 && APIOrderID !="")
{
if (confirm("Are you sure you want to delete this Order?")) {
let CoinSymbol = x.id;
$.ajax({
url:"delete.php",
method:"POST",
data:{CoinSymbol:CoinSymbol},
dataType:"text",
success:function(data)
{
x.remove();
}
});
}}
else
{
alert("Order can't be deleted, Ongoing..."+APIOrderID);
}
/**/
}
let WinTriggerFlag =0;
let WinSellFlag =0;
let LossTriggerFlag =0;
let LossSellFlag =0;
let PanicFlag =0;
function WinTriggerPriceChange(x) {
let WinTriggerPrice = document.getElementById("WinTriggerPrice-"+x.id).value;
const WinSellPrice = document.getElementById("WinSellPrice-"+x.id).value;
let current_price = document.getElementById("CoinPrice-"+x.id).getAttribute("data-Price");
let WinError = document.getElementById("WinError-"+x.id);
let Update1 = document.getElementById("Update1-"+x.id);
Update1.disabled = true;
Update1.style.background='white';
WinError.innerHTML="";
WinTriggerFlag = 0;
if(!WinTriggerPrice.includes("."))
{
WinTriggerPrice+=".00";
}
console.log("WinTriggerPrice"+WinTriggerPrice+",current_price"+current_price);
if( !isNaN(WinTriggerPrice) && !isNaN(parseFloat(WinTriggerPrice)) && !isNaN(WinSellPrice) && !isNaN(parseFloat(WinSellPrice)))
{
if(WinTriggerPrice < current_price)
{
WinError.innerHTML="Invalid input. The win_trigger_price cannot be lower than the current price. If this input price is not a mistake then go and sell at current market price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinTriggerFlag = 0;
}
else if(WinTriggerPrice <= current_price* 0.8 || WinTriggerPrice > current_price* 1.2)
{
WinError.innerHTML="Invalid input. The win_trigger_price must be within 20% of the coin's current price,"+
"In your case, "+x.id+" price is "+current_price+" $ => Max win input is "+current_price * 1.2+"$";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinTriggerFlag = 0;
}
else if(WinTriggerPrice < WinSellPrice)
{
WinError.innerHTML="Invalid input. The win_trigger_price must greater than win_sell_price price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinTriggerFlag = 0;
}
else
{
WinTriggerFlag = 1;
// if(WinTriggerFlag+WinSellFlag==2)
// {
Update1.disabled = false;
Update1.style.background='deepskyblue';
// }
// else
// {
// Update1.disabled = true;
// }
WinError.style.display = 'none';
}
}
else
{
WinError.innerHTML="Input accept only numbers!!";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
}
}
function WinSellPriceChange(x) {
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+x.id).value;
const WinSellPrice = document.getElementById("WinSellPrice-"+x.id).value;
const current_price = document.getElementById("CoinPrice-"+x.id).getAttribute("data-Price");
const WinError = document.getElementById("WinError-"+x.id);
const Update1 = document.getElementById("Update1-"+x.id);
Update1.disabled = true;
Update1.style.background='white';
WinError.innerHTML="";
WinSellFlag = 0;
calculateWinAndLoss(x.id);
//console.log("WinSellPrice"+WinSellPrice+",current_price"+current_price);
if( !isNaN(WinSellPrice) && !isNaN(parseFloat(WinSellPrice)) && !isNaN(WinTriggerPrice) && !isNaN(parseFloat(WinTriggerPrice)))
{
if(WinSellPrice < current_price)
{
WinError.innerHTML="Invalid input. The WinSellPrice cannot be lower than the current price. If this input price is not a mistake then go and sell at current market price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinSellFlag = 0;
}
if(WinSellPrice <= current_price* 0.8 || WinSellPrice > current_price* 1.2)
{
WinError.innerHTML="Invalid input. The WinSellPrice must be within 20% of the coin's current price,"+
"In your case, "+x.id+" price is "+current_price+" $ => Max win input is "+current_price * 1.2;
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinSellFlag = 0;
}
else if(WinSellPrice < current_price* 0.95 || WinSellPrice > WinTriggerPrice* 1.1)
{
WinError.innerHTML="Invalid input. The win_sell_price must be within 5% lower or 10% higher than the win_trigger_price,"+
"In your case,win_trigger_price is "+WinTriggerPrice+"$ => Max input is "+WinTriggerPrice*1.1 +"$ and Min input is "+WinTriggerPrice*0.95+"$,"
+"Note: If you want to change the trigger price, Exit and start over";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinSellFlag = 0;
}
else if(WinTriggerPrice < WinSellPrice)
{
WinError.innerHTML="Invalid input. The win_trigger_price must greater than win_sell_price price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
WinTriggerFlag = 0;
}
else
{
WinSellFlag = 1;
// if(WinTriggerFlag+WinSellFlag==2)
// {
Update1.disabled = false;
Update1.style.background='deepskyblue';
// }
// else
// {
// Update1.disabled = true;
// }
WinError.style.display = 'none';
}
}
else
{
WinError.innerHTML="Input accept only numbers!!";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
}
}
function LossTriggerPriceChange(x) {
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+x.id).value;
const LossTriggerPrice = document.getElementById("LossTriggerPrice-"+x.id).value;
const LossSellPrice = document.getElementById("LossSellPrice-"+x.id).value;
const current_price = document.getElementById("CoinPrice-"+x.id).getAttribute("data-Price");
const WinError = document.getElementById("WinError-"+x.id);
const Update2 = document.getElementById("Update2-"+x.id);
Update2.disabled = true;
Update2.style.background='white';
WinError.innerHTML="";
LossTriggerFlag = 0;
//console.log("WinTriggerPrice"+WinTriggerPrice+",current_price"+current_price);
if( !isNaN(LossTriggerPrice) && !isNaN(parseFloat(LossTriggerPrice)) && !isNaN(LossSellPrice) && !isNaN(parseFloat(LossSellPrice)))
{
if(LossTriggerPrice >= current_price)
{
WinError.innerHTML="Invalid input. The loss_trigger_price must be lower than the the current price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossTriggerFlag = 0;
}
else if(LossTriggerPrice >= WinTriggerPrice)
{
WinError.innerHTML="Invalid input. The loss_trigger_price must be lower than the win_trigger_price.";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossTriggerFlag = 0;
}
else if(LossTriggerPrice <= current_price* 0.8 || LossTriggerPrice > current_price* 1.2)
{
WinError.innerHTML="Invalid input. The loss_trigger_price must be within 20% of the coin's current price,"+
"In your case, "+x.id+" price is "+current_price+" $ => Max loss input is "+current_price * 1.2 +"$";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossTriggerFlag = 0;
}
else if(LossTriggerPrice < LossSellPrice)
{
WinError.innerHTML="Invalid input. The loss_trigger_price must be greater than The loss_sell_price price ";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossTriggerFlag = 0;
}
else
{
LossTriggerFlag = 1;
// if(LossTriggerFlag+LossSellFlag==2)
// {
Update2.disabled = false;
Update2.style.background='deepskyblue';
// }
// else
// {
// Update2.disabled = true;
// }
WinError.style.display = 'none';
}
}
else
{
WinError.innerHTML="Input accept only numbers!!";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
}
}
function LossSellPriceChange(x) {
const WinSellPrice = document.getElementById("WinSellPrice-"+x.id).value;
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+x.id).value;
const LossSellPrice = document.getElementById("LossSellPrice-"+x.id).value;
const LossTriggerPrice = document.getElementById("LossTriggerPrice-"+x.id).value;
const current_price = document.getElementById("CoinPrice-"+x.id).getAttribute("data-Price");
const WinError = document.getElementById("WinError-"+x.id);
const Update2 = document.getElementById("Update2-"+x.id);
Update2.disabled = true;
Update2.style.background='white';
WinError.innerHTML="";
LossSellFlag = 0;
calculateWinAndLoss(x.id);
//console.log("WinTriggerPrice"+WinTriggerPrice+",current_price"+current_price);
if( !isNaN(LossSellPrice) && !isNaN(parseFloat(LossSellPrice)) && !isNaN(LossTriggerPrice) && !isNaN(parseFloat(LossTriggerPrice)))
{
if(LossSellPrice >= current_price)
{
WinError.innerHTML="Invalid input. The loss_sell_price must be lower than the current price";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossSellFlag = 0;
}
else if(LossSellPrice >= WinSellPrice)
{
WinError.innerHTML="Invalid input. The loss_sell_price must be lower than the win_sell_price.";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossSellFlag = 0;
}
else if(LossSellPrice > LossTriggerPrice)
{
WinError.innerHTML="Invalid input. The loss_sell_price must be lower or equal the loss_trigger_price.";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossSellFlag = 0;
}
else if(LossSellPrice >= WinTriggerPrice)
{
WinError.innerHTML="Invalid input. The loss_sell_price must be lower than the win_trigger_price.";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossSellFlag = 0;
}
else if(LossSellPrice <= current_price* 0.8 || LossSellPrice < LossTriggerPrice* 0.95)
{
WinError.innerHTML="Invalid input. The loss_sell_price must be within 5% lower than the loss_trigger_price.,"+
"In your case, loss_trigger_price is "+LossTriggerPrice+" $ => Min input is "+LossTriggerPrice* 0.95 +"$";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
LossSellFlag = 0;
}
else
{
LossSellFlag = 1;
// if(LossTriggerFlag+LossSellFlag==2)
// {
Update2.disabled = false;
Update2.style.background='deepskyblue';
// }
// else
// {
// Update2.disabled = true;
// }
WinError.style.display = 'none';
}
}
else
{
WinError.innerHTML="Input accept only numbers!!";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
}
}
function PanicPriceChange(x) {
const PanicPrice = document.getElementById("PanicPrice-"+x.id).value;
const LossSellPrice = document.getElementById("LossSellPrice-"+x.id).value;
const current_price = document.getElementById("CoinPrice-"+x.id).getAttribute("data-Price");
const WinError = document.getElementById("WinError-"+x.id);
const Update3 = document.getElementById("Update3-"+x.id);
Update3.disabled = true;
Update3.style.background='white';
WinError.innerHTML="";
PanicFlag = 0;
//console.log("WinTriggerPrice"+WinTriggerPrice+",current_price"+current_price);
if( !isNaN(PanicPrice) && !isNaN(parseFloat(PanicPrice)))
{
if(PanicPrice >= LossSellPrice)
{
WinError.innerHTML="Invalid input. The panice_price cannot be Higher than loss_sell_price.";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
PanicFlag = 0;
}
/*
else if(PanicPrice <= current_price* 0.8 || PanicPrice > LossSellPrice* 0.94)
{
WinError.innerHTML="Invalid input. Panice price should be far down by more than 4% from loss_sell_price and not more than 20% from coin current price";
WinError.style.color = 'red';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = 'white';
WinError.style.border = '1px red solid';
WinTriggerFlag = 0;
} */
else
{
PanicFlag = 1;
// if(PanicFlag==1)
// {
Update3.disabled = false;
Update3.style.background='deepskyblue';
// }
// else
// {
// Update3.disabled = true;
// }
WinError.style.display = 'none';
}
}
else
{
WinError.innerHTML="Input accept only numbers!!";
WinError.style.color = 'white';
WinError.style.display = 'block';
WinError.style.padding = '10px';
WinError.style.margin = '10px';
WinError.style.background = '#6c757d';
WinError.style.border = 'white red solid';
}
}
function Update1(x){
const Update1 = document.getElementById("Update1-"+x.id);
const WinTriggerPrice = document.getElementById("WinTriggerPrice-"+x.id).value;
const WinSellPrice = document.getElementById("WinSellPrice-"+x.id).value;
let CoinSymbol = x.id;
$.ajax({
url:"lib/Update1.php",
method:"POST",
data:{CoinSymbol:CoinSymbol,
WinTriggerPrice:WinTriggerPrice,
WinSellPrice:WinSellPrice},
dataType:"text",
success:function(data)
{
Update1.disabled = true;
Update1.style.color='black';
Update1.style.background='#eee';
}
});
}
function Update2(x){
const Update2 = document.getElementById("Update2-"+x.id);
const LossTriggerPrice = document.getElementById("LossTriggerPrice-"+x.id).value;
const LossSellPrice = document.getElementById("LossSellPrice-"+x.id).value;
let CoinSymbol = x.id;
$.ajax({
url:"lib/Update2.php",
method:"POST",
data:{CoinSymbol:CoinSymbol,
LossTriggerPrice:LossTriggerPrice,
LossSellPrice:LossSellPrice},
dataType:"text",
success:function(data)
{
Update2.disabled = true;
Update2.style.color='black';
Update2.style.background='#eee';
}
});
}
function Update3(x){
const Update3 = document.getElementById("Update3-"+x.id);
const PanicPrice = document.getElementById("PanicPrice-"+x.id).value;
let CoinSymbol = x.id;
$.ajax({
url:"lib/Update3.php",
method:"POST",
data:{CoinSymbol:CoinSymbol,
PanicPrice:PanicPrice},
dataType:"text",
success:function(data)
{
Update3.disabled = true;
Update3.style.color='black';
Update3.style.background='#eee';
}
});
}