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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>BTC Ticker</title>
<script src="https://cdn.usefathom.com/script.js" data-site="YZVJPTBZ" defer></script>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #121212;
color: #ffffff;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
.container {
text-align: center;
width: 90%;
max-width: 1000px;
}
#price {
font-size: 3rem;
font-weight: bold;
margin: 10px 0;
color: #f7931a;
/* Bitcoin orange */
text-shadow: 0 0 10px rgba(247, 147, 26, 0.5);
}
#chart-container {
width: 100%;
height: 300px;
position: relative;
background-color: #1e1e1e;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
overflow: hidden;
}
canvas {
position: absolute;
top: 0;
left: 0;
}
.info {
margin-top: 20px;
font-size: 0.9rem;
color: #aaaaaa;
}
.back-link {
margin-top: 20px;
font-size: 0.9rem;
}
.back-link a {
color: #f7931a;
text-decoration: none;
padding: 5px 10px;
border-radius: 5px;
transition: all 0.3s ease;
}
.back-link a:hover {
background-color: rgba(247, 147, 26, 0.2);
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>BTC/USDT Live Ticker</h1>
<div id="price">Loading...</div>
<div id="chart-container">
<canvas id="priceChart"></canvas>
</div>
<div class="info">Showing last 60 seconds of price data</div>
<div class="back-link">
<a href="../index.html">← Back to Vibes Home</a>
</div>
</div>
<script>
// Price history array to store the last minute of data
const priceHistory = [];
const MAX_DATA_POINTS = 60; // One minute at one data point per second
let lastPrice = null;
let highestPrice = 0;
let lowestPrice = Infinity;
// Canvas setup
const chartCanvas = document.getElementById('priceChart');
const chartCtx = chartCanvas.getContext('2d');
// Resize canvases to match container size
function resizeCanvases() {
const container = document.getElementById('chart-container');
const width = container.clientWidth;
const height = container.clientHeight;
chartCanvas.width = width;
chartCanvas.height = height;
}
// Initial resize and listen for window resize
resizeCanvases();
window.addEventListener('resize', resizeCanvases);
// Function to add a price to history
function addPriceToHistory(price) {
const timestamp = Date.now();
priceHistory.push({ price: parseFloat(price), timestamp });
// Keep only the last minute of data
while (priceHistory.length > 0 && timestamp - priceHistory[0].timestamp > 60000) {
priceHistory.shift();
}
// Update min/max prices for scaling
highestPrice = Math.max(...priceHistory.map(p => p.price));
lowestPrice = Math.min(...priceHistory.map(p => p.price));
// Add a small buffer to min/max for better visualization
const buffer = (highestPrice - lowestPrice) * 0.1 || highestPrice * 0.01;
highestPrice += buffer;
lowestPrice = Math.max(0, lowestPrice - buffer);
}
// Function to draw the price chart
function drawChart() {
if (priceHistory.length < 2) return;
const width = chartCanvas.width;
const height = chartCanvas.height;
// Clear the canvas
chartCtx.clearRect(0, 0, width, height);
// Draw background gradient
const bgGradient = chartCtx.createLinearGradient(0, 0, 0, height);
bgGradient.addColorStop(0, 'rgba(30, 30, 30, 1)');
bgGradient.addColorStop(1, 'rgba(10, 10, 10, 1)');
chartCtx.fillStyle = bgGradient;
chartCtx.fillRect(0, 0, width, height);
// Draw grid lines
chartCtx.strokeStyle = 'rgba(100, 100, 100, 0.2)';
chartCtx.lineWidth = 1;
// Horizontal grid lines
const gridLines = 5;
for (let i = 0; i <= gridLines; i++) {
const y = height - (height * (i / gridLines));
chartCtx.beginPath();
chartCtx.moveTo(0, y);
chartCtx.lineTo(width, y);
chartCtx.stroke();
// Price labels
const labelPrice = lowestPrice + ((highestPrice - lowestPrice) * (i / gridLines));
chartCtx.fillStyle = 'rgba(200, 200, 200, 0.7)';
chartCtx.font = '10px Arial';
chartCtx.textAlign = 'left';
chartCtx.fillText(labelPrice.toFixed(2), 5, y - 5);
}
// Draw the price line
chartCtx.beginPath();
const firstPoint = priceHistory[0];
const startTime = priceHistory[0].timestamp;
const endTime = priceHistory[priceHistory.length - 1].timestamp;
const timeRange = endTime - startTime;
// Map the first point
const x1 = 0;
const y1 = height - ((firstPoint.price - lowestPrice) / (highestPrice - lowestPrice) * height);
chartCtx.moveTo(x1, y1);
// Create gradient for line
const lineGradient = chartCtx.createLinearGradient(0, 0, 0, height);
lineGradient.addColorStop(0, '#f7931a'); // Bitcoin orange
lineGradient.addColorStop(1, '#e67e22');
// Draw each point
for (let i = 1; i < priceHistory.length; i++) {
const point = priceHistory[i];
const x = ((point.timestamp - startTime) / timeRange) * width;
const y = height - ((point.price - lowestPrice) / (highestPrice - lowestPrice) * height);
chartCtx.lineTo(x, y);
}
// Style and stroke the line
chartCtx.strokeStyle = lineGradient;
chartCtx.lineWidth = 3;
chartCtx.stroke();
// Create area fill
chartCtx.lineTo(width, height);
chartCtx.lineTo(0, height);
chartCtx.closePath();
// Fill with gradient
const areaGradient = chartCtx.createLinearGradient(0, 0, 0, height);
areaGradient.addColorStop(0, 'rgba(247, 147, 26, 0.5)');
areaGradient.addColorStop(1, 'rgba(247, 147, 26, 0.0)');
chartCtx.fillStyle = areaGradient;
chartCtx.fill();
// Draw the latest price point with a glowing effect
const latestPoint = priceHistory[priceHistory.length - 1];
const latestX = width;
const latestY = height - ((latestPoint.price - lowestPrice) / (highestPrice - lowestPrice) * height);
// Glow effect
chartCtx.beginPath();
chartCtx.arc(latestX, latestY, 5, 0, Math.PI * 2);
chartCtx.fillStyle = '#f7931a';
chartCtx.fill();
// Outer glow
chartCtx.beginPath();
chartCtx.arc(latestX, latestY, 8, 0, Math.PI * 2);
const glowGradient = chartCtx.createRadialGradient(latestX, latestY, 5, latestX, latestY, 15);
glowGradient.addColorStop(0, 'rgba(247, 147, 26, 0.8)');
glowGradient.addColorStop(1, 'rgba(247, 147, 26, 0)');
chartCtx.fillStyle = glowGradient;
chartCtx.fill();
}
// WebSocket connection
const socket = new WebSocket("wss://stream.binance.com:9443/stream");
socket.onopen = () => {
socket.send(JSON.stringify({
"method": "SUBSCRIBE",
"params": ["btcusdt@trade"],
"id": 1
}));
};
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.data !== undefined) {
const d = data.data;
const price = d.p;
const priceElement = document.querySelector("#price");
// Update price display
priceElement.innerText = `$${parseFloat(price).toFixed(2)}`;
// Add price to history
addPriceToHistory(price);
lastPrice = parseFloat(price);
// Draw the chart
drawChart();
}
};
// Throttled chart update for smoother performance
setInterval(() => {
if (priceHistory.length > 0) {
drawChart();
}
}, 100); // Update chart once per second
</script>
</body>
</html>
|