From ada55995925daba29a6e5cd88faa7d54dff01e93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=B0brahim=20Ataberk=20Gen=C3=A7?=
<55658834+Ataberkgenc@users.noreply.github.com>
Date: Wed, 7 Jul 2021 00:05:26 +0300
Subject: [PATCH 1/3] Changed BTC With TRY In The PNL Section
Changed The BTC Styled PNL With Turkis Lira for Turkish people. Yes it was hard yo calculate :( Now there is no problem :)
---
index.js | 290 +++++++++++++++++++++++++++----------------------------
1 file changed, 145 insertions(+), 145 deletions(-)
diff --git a/index.js b/index.js
index 00e700f..e63ad4d 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,9 @@
// ==UserScript==
// @name FTX Custom Theme
// @namespace http://github.com/tradersamwise/
-// @version 1.0.0
+// @version 1.0.3
// @description Custom theme for FTX
-// @author @TraderSamwise
+// @author @TraderSamwise - @Ataberkgenc
// @match https://ftx.com/*
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant none
@@ -17,63 +17,63 @@ const DISABLE_CELL_WRAPPING = true;
const BACKGROUND_COLOR = '#587369';
const TABLE_BODY_COLOR = '#273a3a';
const TABLE_HEADER_COLOR = '#0a1f1f';
-const SHOW_BTC_PNL = true;
-const BTC_PNL_PRECISION = 4;
-const BTC_SUFFIX = "₿";
+const SHOW_TRY_PNL = true;
+const TRY_PNL_PRECISION = 2;
+const TRY_SUFFIX = "₺";
const SHOW_PNL_PERCENT = true;
const PNL_PERCENT_PRECISION = 2;
// set specific style
function addGlobalStyle(css) {
- var head, style;
- head = document.getElementsByTagName('head')[0];
- if (!head) {
- return;
- }
- style = document.createElement('style');
- style.type = 'text/css';
- style.innerHTML = css;
- head.appendChild(style);
+ var head, style;
+ head = document.getElementsByTagName('head')[0];
+ if (!head) {
+ return;
+ }
+ style = document.createElement('style');
+ style.type = 'text/css';
+ style.innerHTML = css;
+ head.appendChild(style);
}
-// reference btc price
-let btcPrice;
+// reference try price
+let tryPrice;
-// fetch the last btc price
-function fetchBtcPrice() {
- fetch('https://ftx.com/api/markets/BTC-PERP')
- .then(response => response.json())
+// fetch the last try price
+function fetchTryPrice() {
+ fetch('https://ftx.com/api/markets/TRYB-PERP')
+ .then(response => response.json())
.then(data => {
- btcPrice = data.result.price;
+ tryPrice = data.result.price;
}).catch((error) => {
- console.log(error);
+ console.log(error);
});
- // recheck every 10 minutes
- setTimeout(fetchBtcPrice, 1000 * 60 * 10);
+ // recheck every 10 minutes
+ setTimeout(fetchTryPrice, 1000 * 60 * 10);
}
// US Number Formatter
var formatter = new Intl.NumberFormat(undefined, {
- style: 'currency',
- currency: 'USD',
+style: 'currency',
+currency: 'USD',
- // These options are needed to round to whole numbers if that's what you want.
- //minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
- //maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
+// These options are needed to round to whole numbers if that's what you want.
+//minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
+//maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});
// function to parse USD notional string value for all possible locals and formats
function parseNotionalString(val) {
- val = val.replace(/\./g, '');
- val = val.replace(/,/g, '');
- val = val.replace(/US\$/g, '');
- val = val.replace(/USD/g, '');
- val = val.replace(/ /g, '');
- val = val.replace(/\$/g, '');
- val = val.trim()
- val = val.substr(0, val.length - 2) + "." + val.substr(val.length - 2, val.length);
- val = parseFloat(val);
- return val;
+ val = val.replace(/\./g, '');
+ val = val.replace(/,/g, '');
+ val = val.replace(/US\$/g, '');
+ val = val.replace(/USD/g, '');
+ val = val.replace(/ /g, '');
+ val = val.replace(/\$/g, '');
+ val = val.trim()
+ val = val.substr(0, val.length - 2) + "." + val.substr(val.length - 2, val.length);
+ val = parseFloat(val);
+ return val;
}
// whether we are currently updating the table
@@ -81,125 +81,125 @@ let updating = false;
// converts pnl for all rows and updates the cells and the top header row
function convertPnlHelper() {
- let rows = document.getElementsByClassName("MuiTableBody-root")[3].children;
- let totalUsdPnl = 0;
- let totalNotional = 0;
- for (var i = 0; i < rows.length; i++) {
- let pnlCell = rows[i].children[6].children[0];
- let formattedPnl = pnlCell.innerText;
-
- // USED FOR TESTING! DO NOT DELETE
-
- // if (!formattedPnl.includes("|")) {
- // formattedPnl = formattedPnl.replace(/\./g, '_');
- // formattedPnl = formattedPnl.replace(/,/g, '.');
- // formattedPnl = formattedPnl.replace(/_/g, ',');
- // formattedPnl = formattedPnl.replace(/\$/g, 'US$ ');
- // pnlCell.innerText = formattedPnl;
- // }
-
- let rawPnl = formattedPnl.split("|")[0];
- rawPnl = parseNotionalString(rawPnl)
- totalUsdPnl += rawPnl;
-
- let percentagePnl;
- if (SHOW_PNL_PERCENT) {
- let formattedNotionalSize = rows[i].children[3].innerText;
- let rawNotionalSize = parseNotionalString(formattedNotionalSize);
- percentagePnl = (rawPnl / rawNotionalSize * 100).toFixed(PNL_PERCENT_PRECISION);
- totalNotional += rawNotionalSize;
- }
-
- if (!formattedPnl.includes("|")) {
- let btcPnl = (rawPnl / btcPrice);
- let formattedPnlBtc = btcPnl.toFixed(BTC_PNL_PRECISION)
-
- pnlCell.innerHTML = pnlCell.innerText + " | " + formattedPnlBtc + " " + BTC_SUFFIX;
- if (SHOW_PNL_PERCENT) {
- pnlCell.innerHTML += " | " + percentagePnl + '%';
- }
- pnlCell.style["white-space"] = "nowrap";
- }
-
- }
- // if we have any open positions, add total to row header
- if (rows.length > 0) {
- let formattedBtcTotal = (totalUsdPnl / btcPrice).toFixed(BTC_PNL_PRECISION) + " " + BTC_SUFFIX;
- let formattedUsdTotal = formatter.format(totalUsdPnl);
- let pnlRowHeader = document.querySelector('[title="PnL since you were last flat"]');
- pnlRowHeader.style["padding-top"] = "5px";
- pnlRowHeader.style["padding-bottom"] = "5px";
- let pnlColor = "#02C77A";
- if (totalUsdPnl < 0) {
- pnlColor = "#FF3B69"
- }
+ let rows = document.getElementsByClassName("MuiTableBody-root")[3].children;
+ let totalUsdPnl = 0;
+ let totalNotional = 0;
+ for (var i = 0; i < rows.length; i++) {
+ let pnlCell = rows[i].children[6].children[0];
+ let formattedPnl = pnlCell.innerText;
+
+ // USED FOR TESTING! DO NOT DELETE
+
+ // if (!formattedPnl.includes("|")) {
+ // formattedPnl = formattedPnl.replace(/\./g, '_');
+ // formattedPnl = formattedPnl.replace(/,/g, '.');
+ // formattedPnl = formattedPnl.replace(/_/g, ',');
+ // formattedPnl = formattedPnl.replace(/\$/g, 'US$ ');
+ // pnlCell.innerText = formattedPnl;
+ // }
+
+ let rawPnl = formattedPnl.split("|")[0];
+ rawPnl = parseNotionalString(rawPnl)
+ totalUsdPnl += rawPnl;
+
+ let percentagePnl;
+ if (SHOW_PNL_PERCENT) {
+ let formattedNotionalSize = rows[i].children[3].innerText;
+ let rawNotionalSize = parseNotionalString(formattedNotionalSize);
+ percentagePnl = (rawPnl / rawNotionalSize * 100).toFixed(PNL_PERCENT_PRECISION);
+ totalNotional += rawNotionalSize;
+ }
+
+ if (!formattedPnl.includes("|")) {
+ let tryPnl = (rawPnl / tryPrice);
+ let formattedPnlTry = tryPnl.toFixed(TRY_PNL_PRECISION)
+
+ pnlCell.innerHTML = pnlCell.innerText + " | " + formattedPnlTry + " " + TRY_SUFFIX;
+ if (SHOW_PNL_PERCENT) {
+ pnlCell.innerHTML += " | " + percentagePnl + '%';
+ }
+ pnlCell.style["white-space"] = "nowrap";
+ }
- if (SHOW_PNL_PERCENT) {
- let totalPercentagePnl = (totalUsdPnl / totalNotional * 100).toFixed(PNL_PERCENT_PRECISION);
- pnlRowHeader.innerHTML = " " + formattedUsdTotal + " | " + formattedBtcTotal + " | " + totalPercentagePnl + "% ";
}
- else {
- pnlRowHeader.innerHTML = " " + formattedUsdTotal + " | " + formattedBtcTotal + "";
+ // if we have any open positions, add total to row header
+ if (rows.length > 0) {
+ let formattedTryTotal = (totalUsdPnl / tryPrice).toFixed(TRY_PNL_PRECISION) + " " + TRY_SUFFIX;
+ let formattedUsdTotal = formatter.format(totalUsdPnl);
+ let pnlRowHeader = document.getElementsByClassName("MuiTableRow-head")[3].children[6];
+ pnlRowHeader.style["padding-top"] = "5px";
+ pnlRowHeader.style["padding-bottom"] = "5px";
+ let pnlColor = "#02C77A";
+ if (totalUsdPnl < 0) {
+ pnlColor = "#FF3B69"
+ }
+
+ if (SHOW_PNL_PERCENT) {
+ let totalPercentagePnl = (totalUsdPnl / totalNotional * 100).toFixed(PNL_PERCENT_PRECISION);
+ pnlRowHeader.innerHTML = " " + formattedUsdTotal + " | " + formattedTryTotal + " | " + totalPercentagePnl + "% ";
+ }
+ else {
+ pnlRowHeader.innerHTML = " " + formattedUsdTotal + " | " + formattedTryTotal + "";
+ }
}
- }
}
// iterate over the rows and convert pnl
function convertPnl() {
- // only update once we have fetched btc price
- if (!updating && btcPrice) {
- updating = true;
- let table = document.getElementsByClassName("MuiTableBody-root")[3];
- table.removeEventListener("DOMSubtreeModified", convertPnl);
- try {
- convertPnlHelper();
- }
- catch (error) {
- console.log(error);
+ // only update once we have fetched try price
+ if (!updating && tryPrice) {
+ updating = true;
+ const table = document.getElementsByClassName("MuiTableBody-root")[3];
+ table.removeEventListener("DOMSubtreeModified", convertPnl);
+ try {
+ convertPnlHelper();
+ }
+ catch (error) {
+ console.log(error);
+ }
+
+ table.addEventListener("DOMSubtreeModified", convertPnl);
+ updating = false;
}
- table.addEventListener("DOMSubtreeModified", convertPnl);
- updating = false;
- }
-
}
// set the styles according to preferences
(function () {
- 'use strict';
-
- COMPACT_TABLE && addGlobalStyle('.MuiTableCell-root {padding-top: 0px; padding-bottom: 0px;}');
- SQUARE_BUTTONS && addGlobalStyle('.MuiButton-root {border-radius: 0px;}');
- SQUARE_CARDS && addGlobalStyle('.MuiPaper-rounded {border-radius: 0px;}');
- DISABLE_CELL_WRAPPING && addGlobalStyle('.MuiTableCell-body {white-space: nowrap;}');
-
- // set background color
- addGlobalStyle('.react-grid-layout {background-color: ' + BACKGROUND_COLOR + ';}');
- addGlobalStyle('.jss11 {background-color: ' + BACKGROUND_COLOR + ';}');
-
- // set table body color
- addGlobalStyle('.MuiPaper-root {background-color: ' + TABLE_BODY_COLOR + ';}');
-
- // set table header color
- addGlobalStyle('.MuiAppBar-root {background-color: ' + TABLE_HEADER_COLOR + ';}');
- addGlobalStyle('.jss305 {background-color: ' + TABLE_HEADER_COLOR + ';}');
-
- // fix toastr font color
- addGlobalStyle('.MuiSnackbarContent-message {color: white;}');
-
- // show btc pnl
- if (SHOW_BTC_PNL) {
- fetchBtcPrice();
- setTimeout(function () {
- const table = document.getElementsByClassName("MuiTableBody-root")[3];
- table.addEventListener("DOMSubtreeModified", convertPnl);
- convertPnl();
- document.getElementsByClassName("MuiButtonBase-root MuiTab-root MuiTab-textColorInherit Mui-selected MuiTab-fullWidth")[3].children[0].addEventListener("click", function () {
+ 'use strict';
+
+ COMPACT_TABLE && addGlobalStyle('.MuiTableCell-root {padding-top: 0px; padding-bottom: 0px;}');
+ SQUARE_BUTTONS && addGlobalStyle('.MuiButton-root {border-radius: 0px;}');
+ SQUARE_CARDS && addGlobalStyle('.MuiPaper-rounded {border-radius: 0px;}');
+ DISABLE_CELL_WRAPPING && addGlobalStyle('.MuiTableCell-body {white-space: nowrap;}');
+
+ // set background color
+ addGlobalStyle('.react-grid-layout {background-color: ' + BACKGROUND_COLOR + ';}');
+ addGlobalStyle('.jss11 {background-color: ' + BACKGROUND_COLOR + ';}');
+
+ // set table body color
+ addGlobalStyle('.MuiPaper-root {background-color: ' + TABLE_BODY_COLOR + ';}');
+
+ // set table header color
+ addGlobalStyle('.MuiAppBar-root {background-color: ' + TABLE_HEADER_COLOR + ';}');
+ addGlobalStyle('.jss305 {background-color: ' + TABLE_HEADER_COLOR + ';}');
+
+ // fix toastr font color
+ addGlobalStyle('.MuiSnackbarContent-message {color: white;}');
+
+ // show try pnl
+ if (SHOW_TRY_PNL) {
+ fetchTryPrice();
setTimeout(function () {
- convertPnl();
- }, 200)
- });
- }, 3000);
- }
+ const table = document.getElementsByClassName("MuiTableBody-root")[3];
+ table.addEventListener("DOMSubtreeModified", convertPnl);
+ convertPnl();
+ document.getElementsByClassName("MuiButtonBase-root MuiTab-root MuiTab-textColorInherit Mui-selected MuiTab-fullWidth")[3].children[0].addEventListener("click", function () {
+ setTimeout(function () {
+ convertPnl();
+ }, 200)
+ });
+ }, 3000);
+ }
})();
From 93dcec951841ac948d8769e0b428e16da03cd3c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=B0brahim=20Ataberk=20Gen=C3=A7?=
<55658834+Ataberkgenc@users.noreply.github.com>
Date: Sat, 10 Jul 2021 13:26:39 +0300
Subject: [PATCH 2/3] TRY Style PNL with Comment Lines of BTC Styled PNL
Made easy to transform between TRY-BTC styled PNL.
---
index.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 73 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index e63ad4d..c468b3c 100644
--- a/index.js
+++ b/index.js
@@ -17,9 +17,15 @@ const DISABLE_CELL_WRAPPING = true;
const BACKGROUND_COLOR = '#587369';
const TABLE_BODY_COLOR = '#273a3a';
const TABLE_HEADER_COLOR = '#0a1f1f';
+
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
const SHOW_TRY_PNL = true;
const TRY_PNL_PRECISION = 2;
const TRY_SUFFIX = "₺";
+//const SHOW_BTC_PNL = true;
+//const BTC_PNL_PRECISION = 4;
+//const BTC_SUFFIX = "₿";
+
const SHOW_PNL_PERCENT = true;
const PNL_PERCENT_PRECISION = 2;
@@ -36,9 +42,13 @@ function addGlobalStyle(css) {
head.appendChild(style);
}
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
// reference try price
let tryPrice;
+// reference btc price
+//let btcPrice;
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
// fetch the last try price
function fetchTryPrice() {
fetch('https://ftx.com/api/markets/TRYB-PERP')
@@ -52,6 +62,19 @@ function fetchTryPrice() {
setTimeout(fetchTryPrice, 1000 * 60 * 10);
}
+// fetch the last btc price
+//function fetchBtcPrice() {
+// fetch('https://ftx.com/api/markets/BTC-PERP')
+// .then(response => response.json())
+// .then(data => {
+// btcPrice = data.result.price;
+// }).catch((error) => {
+// console.log(error);
+// });
+ // recheck every 10 minutes
+// setTimeout(fetchBtcPrice, 1000 * 60 * 10);
+//}
+
// US Number Formatter
var formatter = new Intl.NumberFormat(undefined, {
style: 'currency',
@@ -109,12 +132,18 @@ function convertPnlHelper() {
percentagePnl = (rawPnl / rawNotionalSize * 100).toFixed(PNL_PERCENT_PRECISION);
totalNotional += rawNotionalSize;
}
-
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
if (!formattedPnl.includes("|")) {
let tryPnl = (rawPnl / tryPrice);
let formattedPnlTry = tryPnl.toFixed(TRY_PNL_PRECISION)
pnlCell.innerHTML = pnlCell.innerText + " | " + formattedPnlTry + " " + TRY_SUFFIX;
+
+// if (!formattedPnl.includes("|")) {
+// let btcPnl = (rawPnl / btcPrice);
+// let formattedPnlBtc = btcPnl.toFixed(BTC_PNL_PRECISION)
+
+// pnlCell.innerHTML = pnlCell.innerText + " | " + formattedPnlBtc + " " + BTC_SUFFIX;
if (SHOW_PNL_PERCENT) {
pnlCell.innerHTML += " | " + percentagePnl + '%';
}
@@ -124,9 +153,11 @@ function convertPnlHelper() {
}
// if we have any open positions, add total to row header
if (rows.length > 0) {
+// let formattedBtcTotal = (totalUsdPnl / btcPrice).toFixed(BTC_PNL_PRECISION) + " " + BTC_SUFFIX;
let formattedTryTotal = (totalUsdPnl / tryPrice).toFixed(TRY_PNL_PRECISION) + " " + TRY_SUFFIX;
let formattedUsdTotal = formatter.format(totalUsdPnl);
let pnlRowHeader = document.getElementsByClassName("MuiTableRow-head")[3].children[6];
+// let pnlRowHeader = document.querySelector('[title="PnL since you were last flat"]');
pnlRowHeader.style["padding-top"] = "5px";
pnlRowHeader.style["padding-bottom"] = "5px";
let pnlColor = "#02C77A";
@@ -144,6 +175,7 @@ function convertPnlHelper() {
}
}
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
// iterate over the rows and convert pnl
function convertPnl() {
// only update once we have fetched try price
@@ -164,6 +196,25 @@ function convertPnl() {
}
+//function convertPnl() {
+ // only update once we have fetched btc price
+// if (!updating && btcPrice) {
+// updating = true;
+// let table = document.getElementsByClassName("MuiTableBody-root")[3];
+// table.removeEventListener("DOMSubtreeModified", convertPnl);
+// try {
+// convertPnlHelper();
+// }
+// catch (error) {
+// console.log(error);
+// }
+
+// table.addEventListener("DOMSubtreeModified", convertPnl);
+ // updating = false;
+// }
+
+//}
+
// set the styles according to preferences
(function () {
'use strict';
@@ -187,6 +238,7 @@ function convertPnl() {
// fix toastr font color
addGlobalStyle('.MuiSnackbarContent-message {color: white;}');
+// Transform this section into comment lines and uncomment the following section for BTC style PNL
// show try pnl
if (SHOW_TRY_PNL) {
fetchTryPrice();
@@ -203,3 +255,23 @@ function convertPnl() {
}
})();
+
+
+
+
+// show btc pnl
+// if (SHOW_BTC_PNL) {
+// fetchBtcPrice();
+// setTimeout(function () {
+// const table = document.getElementsByClassName("MuiTableBody-root")[3];
+// table.addEventListener("DOMSubtreeModified", convertPnl);
+// convertPnl();
+// document.getElementsByClassName("MuiButtonBase-root MuiTab-root MuiTab-textColorInherit Mui-selected MuiTab-fullWidth")[3].children[0].addEventListener("click", function () {
+// setTimeout(function () {
+// convertPnl();
+// }, 200)
+// });
+// }, 3000);
+// }
+//
+//})();
From 8c78db9d743d868a72641852eb62d39814da5d33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=B0brahim=20Ataberk=20Gen=C3=A7?=
<55658834+Ataberkgenc@users.noreply.github.com>
Date: Sat, 10 Jul 2021 13:28:42 +0300
Subject: [PATCH 3/3] Added TRY Stlyed PNL and Commented BTC Styled PNL
Easy to transform between TRY-BTC styled PNL with comment lines.
---
index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/index.js b/index.js
index c468b3c..4b88e72 100644
--- a/index.js
+++ b/index.js
@@ -3,7 +3,7 @@
// @namespace http://github.com/tradersamwise/
// @version 1.0.3
// @description Custom theme for FTX
-// @author @TraderSamwise - @Ataberkgenc
+// @author @TraderSamwise
// @match https://ftx.com/*
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant none