-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
234 lines (204 loc) · 7.55 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Papar trading platform for Bitcoin. Track real-time price, execute trades, and visualize your trading performance with interactive charts.">
<meta name="keywords" content="paper trading, Bitcoin, cryptocurrency, trading platform, real-time price, charting, trading performance">
<meta name="author" content="Papar Trade">
<meta property="og:title" content="Papar Trade">
<meta property="og:description" content="Track Bitcoin's real-time price, execute trades, and visualize performance with our interactive trading platform.">
<meta property="og:type" content="website">
<meta name="twitter:title" content="Papar Trade">
<meta name="twitter:description" content="Track Bitcoin's real-time price, execute trades, and visualize performance with our interactive trading platform.">
<meta name="robots" content="index, follow">
<meta name="theme-color" content="#1d1d1d">
<title>Papar Trading</title>
<style>
body {
margin: 0;
background-color: #1d1d1d;
color: white;
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
}
#chart-container {
width: 90%;
height: 80vh;
}
#controls {
margin-top: 20px;
display: flex;
justify-content: center;
gap: 10px;
}
#info {
display: flex;
justify-content: space-around;
width: 90%;
margin-top: 20px;
font-size: 18px;
}
input[type=number] {
width: 60px;
padding: 5px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #444;
border: none;
color: white;
}
button:disabled {
background-color: #777;
}
#popup {
position: fixed;
bottom: 20px;
background-color: #444;
padding: 15px 25px;
border-radius: 10px;
display: none;
color: white;
font-size: 18px;
z-index: 1000;
}
.profit {
background-color: green;
}
.loss {
background-color: red;
}
#chartcc {
height:400px;
width:1000px;
}
</style>
</head>
<body>
<h1>Papar Trading [BITCOIN]</h1>
<div id="info">
<div>Current Price: <span id="current-price">-</span> USD</div>
<div>Current Profit/Loss: <span id="current-pl">-</span> USD</div>
</div>
<div id="chartcc">
<canvas id="price-chart"></canvas>
</div>
<div id="controls">
<input type="number" id="trade-amount" placeholder="Amount" min="1" value="1">
<button id="buy-button">Buy</button>
<button id="sell-button">Sell</button>
<button id="close-button" disabled>Close</button>
</div>
<div id="popup"></div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
let trade = {
position: 0,
entryPrice: 0,
currentPrice: 0,
profitLoss: 0
};
const priceHistory = [];
const ctx = document.getElementById('price-chart').getContext('2d');
const priceChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Bitcoin Price',
data: [],
borderColor: 'white',
borderWidth: 2,
fill: false
}]
},
options: {
scales: {
x: { display: false },
y: {
beginAtZero: false,
ticks: { color: 'white' }
}
},
responsive: true,
maintainAspectRatio: false
}
});
async function getPrice() {
const response = await fetch("https://api.coindesk.com/v1/bpi/currentprice/USD.json");
const data = await response.json();
return parseFloat(data.bpi.USD.rate.replace(",", ""));
}
async function updatePrice() {
const currentPrice = await getPrice();
trade.currentPrice = currentPrice;
document.getElementById('current-price').innerText = currentPrice.toFixed(2);
if (priceHistory.length >= 50) priceHistory.shift();
priceHistory.push(currentPrice);
priceChart.data.labels.push('');
if (priceChart.data.labels.length > 50) priceChart.data.labels.shift();
priceChart.data.datasets[0].data = priceHistory;
priceChart.update();
if (trade.position !== 0) {
trade.profitLoss = (currentPrice - trade.entryPrice) * trade.position;
document.getElementById('current-pl').innerText = trade.profitLoss.toFixed(2);
document.getElementById('current-pl').style.color = trade.profitLoss >= 0 ? 'green' : 'red';
} else {
document.getElementById('current-pl').innerText = "-";
}
if (trade.position !== 0) {
document.getElementById('close-button').disabled = false;
} else {
document.getElementById('close-button').disabled = true;
}
setTimeout(updatePrice, 1500);
}
document.getElementById('buy-button').onclick = () => {
const amount = parseInt(document.getElementById('trade-amount').value);
trade.position += amount;
if (trade.position === amount) {
trade.entryPrice = trade.currentPrice;
}
updateButtonColors('buy');
};
document.getElementById('sell-button').onclick = () => {
const amount = parseInt(document.getElementById('trade-amount').value);
trade.position -= amount;
if (trade.position === 0) {
closeTrade();
}
updateButtonColors('sell');
};
document.getElementById('close-button').onclick = () => {
closeTrade();
resetButtonColors();
};
function updateButtonColors(action) {
document.getElementById('buy-button').style.backgroundColor = action === 'buy' ? 'green' : '#444';
document.getElementById('sell-button').style.backgroundColor = action === 'sell' ? 'red' : '#444';
}
function resetButtonColors() {
document.getElementById('buy-button').style.backgroundColor = '#444';
document.getElementById('sell-button').style.backgroundColor = '#444';
}
function closeTrade() {
const popup = document.getElementById('popup');
popup.style.display = 'block';
popup.textContent = `Trade Closed. ${trade.profitLoss >= 0 ? 'Profit' : 'Loss'}: ${trade.profitLoss.toFixed(2)} USD`;
popup.className = trade.profitLoss >= 0 ? 'profit' : 'loss';
setTimeout(() => {
popup.style.display = 'none';
}, 3000);
trade.position = 0;
trade.entryPrice = 0;
trade.profitLoss = 0;
}
updatePrice();
</script>
</body>
</html>