import requests import pandas as pd from datetime import datetime def get_historical_data(coin_id="bitcoin", vs_currency="usd", days=1): url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart" params = { "vs_currency": vs_currency, "days": days, "interval": "minutely" } response = requests.get(url, params=params) data = response.json() prices = data.get("prices", []) # Converter para DataFrame df = pd.DataFrame(prices, columns=["timestamp", "price"]) df["timestamp"] = pd.to_datetime(df["timestamp"], unit='ms') # Agregar em candles de 15 minutos df.set_index("timestamp", inplace=True) ohlc = df["price"].resample("15T").ohlc() volume = pd.DataFrame(data.get("total_volumes", []), columns=["timestamp", "volume"]) volume["timestamp"] = pd.to_datetime(volume["timestamp"], unit='ms') volume.set_index("timestamp", inplace=True) volume_15min = volume["volume"].resample("15T").sum() ohlc["volume"] = volume_15min ohlc.dropna(inplace=True) return ohlc if __name__ == "__main__": df_15min = get_historical_data() print(df_15min) - Follow Up Deployment
Browse files- index.html +68 -29
index.html
CHANGED
|
@@ -459,13 +459,7 @@
|
|
| 459 |
</div>
|
| 460 |
</div>
|
| 461 |
|
| 462 |
-
<!--
|
| 463 |
-
<div class="glass-card p-6 mb-6">
|
| 464 |
-
<h3 class="text-lg font-semibold text-cyan-400 mb-4">Neural Network Evolution</h3>
|
| 465 |
-
<div class="h-64">
|
| 466 |
-
<canvas id="trainingChart"></canvas>
|
| 467 |
-
</div>
|
| 468 |
-
</div>
|
| 469 |
|
| 470 |
<!-- Performance Comparison -->
|
| 471 |
<div class="glass-card p-6 mb-6">
|
|
@@ -529,35 +523,80 @@
|
|
| 529 |
</div>
|
| 530 |
|
| 531 |
<script>
|
| 532 |
-
// API caller
|
| 533 |
-
async function fetchCandleData(coin="bitcoin", days=1) {
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
}
|
| 553 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
}
|
| 555 |
|
| 556 |
// Global storage
|
| 557 |
window.candleData = [];
|
| 558 |
|
| 559 |
async function initCharts() {
|
| 560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
|
| 562 |
// Candlestick Chart
|
| 563 |
const candleCtx = document.getElementById('candlestickChart').getContext('2d');
|
|
|
|
| 459 |
</div>
|
| 460 |
</div>
|
| 461 |
|
| 462 |
+
<!-- (removed duplicate neural-network-evolution section) -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
<!-- Performance Comparison -->
|
| 465 |
<div class="glass-card p-6 mb-6">
|
|
|
|
| 523 |
</div>
|
| 524 |
|
| 525 |
<script>
|
| 526 |
+
// Real API caller
|
| 527 |
+
async function fetchCandleData(coin = "bitcoin", days = 1) {
|
| 528 |
+
const res = await fetch(`https://api.coingecko.com/api/v3/coins/${coin}/market_chart?vs_currency=usd&days=${days}&interval=minutely`);
|
| 529 |
+
const data = await res.json();
|
| 530 |
+
|
| 531 |
+
// Process prices data
|
| 532 |
+
const prices = data.prices.map(([timestamp, price]) => ({
|
| 533 |
+
timestamp: new Date(timestamp),
|
| 534 |
+
price: price
|
| 535 |
+
}));
|
| 536 |
+
|
| 537 |
+
// Process volumes data
|
| 538 |
+
const volumes = data.total_volumes.map(([timestamp, volume]) => ({
|
| 539 |
+
timestamp: new Date(timestamp),
|
| 540 |
+
volume: volume
|
| 541 |
+
}));
|
| 542 |
+
|
| 543 |
+
// Convert to OHLC candles (15-minute intervals)
|
| 544 |
+
const candles = [];
|
| 545 |
+
const interval = 15 * 60 * 1000; // 15 minutes in milliseconds
|
| 546 |
+
let currentCandle = {};
|
| 547 |
+
let startTime = prices[0].timestamp.getTime();
|
| 548 |
+
|
| 549 |
+
for (let i = 0; i < prices.length; i++) {
|
| 550 |
+
const priceTime = prices[i].timestamp.getTime();
|
| 551 |
+
|
| 552 |
+
// If we've moved to a new 15-minute interval
|
| 553 |
+
if (priceTime >= startTime + interval || i === prices.length - 1) {
|
| 554 |
+
if (Object.keys(currentCandle).length > 0) {
|
| 555 |
+
candles.push({
|
| 556 |
+
timestamp: new Date(startTime),
|
| 557 |
+
open: currentCandle.open,
|
| 558 |
+
high: currentCandle.high,
|
| 559 |
+
low: currentCandle.low,
|
| 560 |
+
close: prices[i-1].price
|
| 561 |
+
});
|
| 562 |
+
}
|
| 563 |
+
// Reset for next candle
|
| 564 |
+
currentCandle = {
|
| 565 |
+
open: prices[i].price,
|
| 566 |
+
high: prices[i].price,
|
| 567 |
+
low: prices[i].price
|
| 568 |
+
};
|
| 569 |
+
startTime = priceTime;
|
| 570 |
+
} else {
|
| 571 |
+
// Update high/low for current candle
|
| 572 |
+
if (prices[i].price > currentCandle.high) currentCandle.high = prices[i].price;
|
| 573 |
+
if (prices[i].price < currentCandle.low) currentCandle.low = prices[i].price;
|
| 574 |
+
}
|
| 575 |
}
|
| 576 |
+
|
| 577 |
+
return candles.map(c => ({
|
| 578 |
+
x: c.timestamp,
|
| 579 |
+
o: c.open,
|
| 580 |
+
h: c.high,
|
| 581 |
+
l: c.low,
|
| 582 |
+
c: c.close
|
| 583 |
+
}));
|
| 584 |
}
|
| 585 |
|
| 586 |
// Global storage
|
| 587 |
window.candleData = [];
|
| 588 |
|
| 589 |
async function initCharts() {
|
| 590 |
+
try {
|
| 591 |
+
window.candleData = await fetchCandleData("bitcoin", 1);
|
| 592 |
+
} catch (error) {
|
| 593 |
+
console.error("Error fetching candle data:", error);
|
| 594 |
+
// Fallback to static data if API fails
|
| 595 |
+
window.candleData = [
|
| 596 |
+
{ x: new Date(), o: 62000, h: 62500, l: 61800, c: 62450 },
|
| 597 |
+
{ x: new Date(Date.now() - 86400000), o: 61500, h: 62200, l: 61200, c: 62000 }
|
| 598 |
+
];
|
| 599 |
+
}
|
| 600 |
|
| 601 |
// Candlestick Chart
|
| 602 |
const candleCtx = document.getElementById('candlestickChart').getContext('2d');
|