Skip to content

Commit 14acdfb

Browse files
authored
Merge pull request #3 from pseudocode88/develop
V3.0
2 parents 9691934 + 42a9b9a commit 14acdfb

File tree

14 files changed

+311
-935
lines changed

14 files changed

+311
-935
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/
22
out/
3-
*.db
3+
*.db
4+
.DS_Store
5+
.fleet/

build.js

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,29 @@
1-
const fs = require('fs');
2-
const { exec } = require('child_process');
3-
const path = require('path');
1+
const {exec} = require('child_process');
42

5-
const dbFolderPath = path.join(__dirname, 'db');
6-
const fileNames = ['account-settings.db']; // Add more file names as needed
7-
8-
// Step one: Delete and recreate the files
9-
function deleteAndRecreateFiles() {
10-
return new Promise((resolve, reject) => {
11-
const deletePromises = fileNames.map((fileName) => {
12-
const filePath = path.join(dbFolderPath, fileName);
13-
14-
return new Promise((resolve, reject) => {
15-
fs.unlink(filePath, (err) => {
16-
if (err && !fs.existsSync(filePath)) {
17-
console.error('Error deleting file:', err);
18-
reject(err);
19-
return;
20-
}
21-
fs.writeFile(filePath, '', (err) => {
22-
if (err) {
23-
console.error('Error recreating file:', err);
24-
reject(err);
25-
return;
26-
}
27-
console.log('Recreated file:', filePath);
28-
resolve();
29-
});
30-
});
31-
});
32-
});
33-
34-
Promise.all(deletePromises)
35-
.then(() => {
36-
resolve();
37-
})
38-
.catch((error) => {
39-
reject(error);
40-
});
41-
});
3+
const runBuildScript = () => {
4+
return new Promise((resolve, reject) => {
5+
exec('yarn run build', (error, stdout, stderr) => {
6+
if (error) {
7+
console.error(`Error executing 'yarn run build' command: ${error.message}`);
8+
reject(error);
9+
return;
10+
}
11+
if (stderr) {
12+
console.error(`Command error: ${stderr}`);
13+
reject(stderr);
14+
return;
15+
}
16+
console.log(`Command output: ${stdout}`);
17+
resolve();
18+
});
19+
});
4220
}
4321

44-
// Step two: Run 'yarn run build' script
45-
function runBuildScript() {
46-
return new Promise((resolve, reject) => {
47-
exec('yarn run build', (error, stdout, stderr) => {
48-
if (error) {
49-
console.error(`Error executing 'yarn run build' command: ${error.message}`);
50-
reject(error);
51-
return;
52-
}
53-
if (stderr) {
54-
console.error(`Command error: ${stderr}`);
55-
reject(stderr);
56-
return;
57-
}
58-
console.log(`Command output: ${stdout}`);
59-
resolve();
60-
});
61-
});
62-
}
6322

64-
// Execute the steps sequentially
65-
deleteAndRecreateFiles()
66-
.then(() => runBuildScript())
67-
.then(() => {
68-
console.log('Build script completed successfully.');
69-
})
70-
.catch((error) => {
71-
console.error('Error encountered:', error);
72-
});
23+
runBuildScript()
24+
.then(() => {
25+
console.log('Build script completed successfully.');
26+
})
27+
.catch((error) => {
28+
console.error('Error encountered:', error);
29+
});

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 = 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: Number(data.positionSizeUnit).toFixed(4),
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+
});

0 commit comments

Comments
 (0)