Skip to content

Commit 0b1485b

Browse files
author
pseudocode88
committed
Conslidated multiple js file and css to client folder
1 parent 6783a7e commit 0b1485b

File tree

8 files changed

+216
-220
lines changed

8 files changed

+216
-220
lines changed

client/index.html

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="UTF-8"/>
6+
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
7+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"/>
8+
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'"/>
9+
<title>Trader Bruh</title>
10+
<link rel="stylesheet" href="./style.css" type="text/css"/>
11+
</head>
12+
13+
<body>
14+
<main class="fc f-wrap-32">
15+
16+
<div class="Credits">
17+
<div class="fr f-wrap-12">
18+
<img alt="logo" src="../assets/logo-1000.png" class="Logo"/>
19+
<div class="fc">
20+
<p class="Credits-Title">Trader Bruh - v3.0</p>
21+
<p class="Credits-Creator">by @PseudoCode88</p>
22+
</div>
23+
</div>
24+
</div>
25+
26+
<section>
27+
<!-- Data Section-->
28+
<section id="result-panel" class="Wrapper-Position-Size-Result">
29+
<div class="fc f-wrap-24">
30+
<div class="fc">
31+
<p class="label">Position Size (units)</p>
32+
<p class="value" id="label-position-size-units">0</p>
33+
</div>
34+
<div class="fc">
35+
<p class="label">Position Size (USD)</p>
36+
<p class="value" id="label-position-size-usd">$0</p>
37+
</div>
38+
<div class="fc">
39+
<p class="label">Margin (USD)</p>
40+
<p class="value" id="label-margin-usd">$0.00</p>
41+
</div>
42+
</div>
43+
</section>
44+
45+
<!-- Form Section-->
46+
<section class="Wrapper-Position-Size-Form">
47+
<div class="fc f-wrap-24">
48+
<div class="fc f-wrap-8">
49+
<h2>Size Builder</h2>
50+
<p class="Heading-Subtitle">Build your position size based on the stop loss and the risk you defined in
51+
the account settings.</p>
52+
</div>
53+
54+
<div class="fr f-wrap-24">
55+
<div class="strech">
56+
<label for="entry-price">Entry Point</label>
57+
<input type="number" id="entry-price" value="1"/>
58+
</div>
59+
60+
<div class="strech">
61+
<label for="stop-loss">Stop Loss</label>
62+
<input type="number" id="stop-loss" value="1"/>
63+
</div>
64+
</div>
65+
66+
<div class="fr f-wrap-24">
67+
<div class="strech">
68+
<label for="risk-amount">Risk Amount</label>
69+
<input type="number" id="risk-amount" value="1"/>
70+
</div>
71+
72+
<div class="strech">
73+
<label for="leverage">Leverage</label>
74+
<input type="number" step="1" id="leverage" value="10"/>
75+
</div>
76+
</div>
77+
</div>
78+
</section>
79+
</section>
80+
81+
82+
</main>
83+
<script type="text/javascript" src="./script.js"></script>
84+
</body>
85+
86+
</html>

client/script.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const $ = require('jquery');
2+
3+
let PositionSizeBuilder = ($) => {
4+
5+
let data = {
6+
stopLoss: 0,
7+
entryPrice: 0,
8+
leverage: 1,
9+
risk: 0,
10+
direction: 'long',
11+
positionSizeUnit: 0,
12+
positionSizeUSD: 0,
13+
margin: 0
14+
};
15+
16+
let el = {
17+
textfield: {
18+
stopLoss: $('#stop-loss'),
19+
entryPrice: $('#entry-price'),
20+
leverage: $('#leverage'),
21+
riskAmount: $('#risk-amount')
22+
},
23+
label: {
24+
positionSizeUnit: $('#label-position-size-units'),
25+
positionSizeUSD: $('#label-position-size-usd'),
26+
margin: $('#label-margin-usd')
27+
},
28+
wrapper: {
29+
result: $('#result-panel')
30+
}
31+
}
32+
33+
let eventBindings = () => {
34+
Object.keys(el.textfield).forEach(function (id) {
35+
el.textfield[id].on("keyup", updatePositionSize)
36+
})
37+
}
38+
39+
let getFormData = () => {
40+
const formFields = {
41+
stopLoss: el.textfield.stopLoss,
42+
entryPrice: el.textfield.entryPrice,
43+
leverage: el.textfield.leverage,
44+
risk: el.textfield.riskAmount
45+
};
46+
47+
return Object.entries(formFields).reduce((acc, [key, element]) => {
48+
acc[key] = (element.val()) ? element.val() : '1';
49+
return acc;
50+
}, {});
51+
}
52+
53+
let updatePositionSize = () => {
54+
const formData = getFormData();
55+
const data = calculatePositionSize(formData);
56+
updateData(data);
57+
render();
58+
}
59+
60+
let updateData = (formData) => {
61+
Object.keys(formData).forEach((key) => {
62+
data[key] = formData[key];
63+
})
64+
}
65+
66+
let calculatePositionSize = (data) => {
67+
const {risk, entryPrice, stopLoss, leverage} = data;
68+
69+
const priceDifference = (stopLoss > entryPrice) ? stopLoss - entryPrice : entryPrice - stopLoss;
70+
71+
72+
if (priceDifference === 0) {
73+
data.positionSizeUnit = 0;
74+
data.positionSizeUSD = 0;
75+
76+
} else {
77+
data.positionSizeUnit = Math.round(risk / Math.abs(priceDifference));
78+
data.positionSizeUSD = (data.positionSizeUnit * entryPrice).toFixed(2);
79+
}
80+
81+
data.margin = ((data.positionSizeUnit * entryPrice) / leverage).toFixed(2);
82+
data.direction = (stopLoss > entryPrice) ? 'short' : 'long'
83+
84+
return data;
85+
}
86+
87+
let render = () => {
88+
const elementsToUpdate = {
89+
positionSizeUnit: data.positionSizeUnit,
90+
positionSizeUSD: "$" + data.positionSizeUSD,
91+
margin: "$" + data.margin
92+
};
93+
94+
Object.entries(elementsToUpdate).forEach(([elementKey, value]) => {
95+
el.label[elementKey].html(value);
96+
});
97+
}
98+
99+
let init = () => {
100+
eventBindings();
101+
}
102+
103+
return {
104+
init: init
105+
}
106+
}
107+
108+
document.addEventListener('DOMContentLoaded', () => {
109+
PositionSizeBuilder($).init();
110+
});
File renamed without changes.

index.html

Lines changed: 0 additions & 89 deletions
This file was deleted.

index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
const { app, BrowserWindow } = require('electron');
1+
const {app, BrowserWindow} = require('electron');
22

33
const createWindow = () => {
4-
const win = new BrowserWindow({
5-
width: 400,
6-
minWidth: 400,
7-
height: 752,
8-
minHeight: 752,
9-
webPreferences: {
10-
nodeIntegration: true,
11-
contextIsolation: false
12-
},
13-
icon: 'assets/logo-1000.png',
14-
})
4+
const win = new BrowserWindow({
5+
width: 400,
6+
minWidth: 400,
7+
height: 752,
8+
minHeight: 752,
9+
webPreferences: {
10+
nodeIntegration: true,
11+
contextIsolation: false
12+
},
13+
icon: 'assets/logo-1000.png',
14+
})
1515

16-
win.resizable = true;
17-
win.setAlwaysOnTop(true);
16+
win.resizable = true;
17+
win.setAlwaysOnTop(true);
1818

19-
win.loadFile('index.html')
19+
win.loadFile('client/index.html')
2020
}
2121

2222
app.setName("Trader Bruh");
2323

2424
app.whenReady().then(() => {
25-
createWindow()
25+
createWindow()
2626

27-
app.on('activate', () => {
28-
if (BrowserWindow.getAllWindows().length === 0) createWindow()
29-
})
27+
app.on('activate', () => {
28+
if (BrowserWindow.getAllWindows().length === 0) createWindow()
29+
})
3030
})
3131

3232
app.on('window-all-closed', () => {
33-
if (process.platform !== 'darwin') app.quit()
33+
if (process.platform !== 'darwin') app.quit()
3434
})

scripts/deps.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)