Skip to content

Instantly share code, notes, and snippets.

@prem911
Last active September 3, 2021 18:41
Show Gist options
  • Save prem911/1736ba2571de56547d7c143a176776a5 to your computer and use it in GitHub Desktop.
Save prem911/1736ba2571de56547d7c143a176776a5 to your computer and use it in GitHub Desktop.
  • Install TamperMonkey in Chrome/Edge browser
  • Press the "Raw" button for the gist named "exitAll.user.js"
  • Press Install
  • Go to TT's strategies page and refresh if needed
  • Press the Exit All button will full care, note it is your responsibility from now on
// ==UserScript==
// @name TT Bulk Trade Exit
// @version 1.0
// @author prem911
// @icon https://www.google.com/s2/favicons?domain=red.com
// @description Adds a styled button in top of the page to trigger the Exit All. This is a dangerous action and needs to be done after careful thought.
// @match https://tradetron.tech/deployed-strategies
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// ==/UserScript==
//Insert a styled button
var str = '<a id="exitAllBtn" class="strategy__filter-btn">&#9760; EXIT ALL LIVE DEPLOYMENTS &#9760;</a>';
var x = document.getElementsByClassName('deployed__summary-title pb-3')[0];
var y = document.createElement('div');
y.className = 'pb-2';
y.insertAdjacentHTML( 'beforeend', str );
x.parentElement.insertBefore(y,x); //Insert as first children
x.parentElement.removeChild(x); //Remove "Summary" paragraph
//Click handler
document.getElementById ("exitAllBtn").addEventListener (
"click", ButtonClickAction, false
);
//Dangerous Magic happens here
function ButtonClickAction (zEvent) {
if (confirm('Do you want to proceed with this operation?')) {
GM_xmlhttpRequest({
method: "GET",
responseType: "json",
headers: {
"Accept": "application/json",
"x-requested-with":"XMLHttpRequest"
},
url: "https://tradetron.tech/api/deployed-strategies?creator_id=&execution=LIVE%20AUTO",
onload: onDeployedFetch
});
}
}
//Live-Entered -> Exited
//Active -> Paused
//Paused -> Start
function onDeployedFetch (res) {
let strategies = JSON.parse(res.responseText).data;
let warningText = '';
let toExitStrategies = [];
strategies.forEach((element) => {
console.log(element.deployment_type, element.id, element.status, element.sum_of_pnl, element.template.name);
if(element.status === "Live-Entered"){//Live-Entered Exited Active Paused
warningText += element.template.name.concat(' with PNL ', parseFloat(element.sum_of_pnl).toFixed(2), '\r\n');
toExitStrategies.push(element.id);
}
});
if(toExitStrategies.length == 0) {
alert("You dont have any Live-Entered deployment, Aborting the mission here.");
return;
}
warningText += 'Review the names carefully.By clicking "OK", you agree that you are solely responsible for this Act. The creator of this script will not be held responsible for any Tradetron mishaps.\r\n\r\nAre you sure you want to proceed to exit all of these?'
let counter = 0;
let totalDeployments = toExitStrategies.length;
if (confirm(warningText)) {
toExitStrategies.forEach((element) => {
GM_xmlhttpRequest({
method: "POST",
data: `{"exchange":"NFO","status":"Exited","id":${element}}`,//Exited or Paused or Start
responseType: "json",
headers: {
"Content-Type": "application/json",
"x-requested-with":"XMLHttpRequest"
},
mode: "cors",
credentials: "include",
url: "https://tradetron.tech/api/deployed/status",
onload: function(res){
counter++;
console.log(res.responseText);
if(counter == totalDeployments) {
alert('Refreshing the page now will show the new status. Sometimes Tradetron is slow, so please be careful about the final status');
location.reload();
}
}
});
});
} else {
// Do nothing!
console.log('Damn!, Aborted');
}
}
//--- Style our newly added elements using CSS.
GM_addStyle ( `
#exitAllBtn {
cursor: pointer;
font-size: x-large;
text-align: center;
background: linear-gradient(0deg, red, yellow);
border:none;
text-decoration:none;
display:block;
width:100%;
margin:0 auto;
}
#exitAllBtn:hover {
background: linear-gradient(0deg, yellow, red);
color:white;
}
#exitAllBtn:active {
transform: translateY(-2px);
}
` );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment