{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8b2334dd",
   "metadata": {},
   "source": [
    "# 01 — Descarga Masiva de Datos Historicos (Binance)\n",
    "\n",
    "Dos metodos para obtener datos historicos:\n",
    "\n",
    "1. **REST API** (`/api/v3/klines`) — Paginado, max 1000 velas por request. Ideal para 7 dias.\n",
    "2. **Data Vision** (`data.binance.vision`) — CSVs comprimidos diarios/mensuales. Ideal para meses/anos.\n",
    "\n",
    "**Rate limits REST:** 6000 weight/min, klines cuesta 2 weight.\n",
    "\n",
    "| Endpoint | Max/req | Weight | Uso |\n",
    "|---|---|---|---|\n",
    "| `/api/v3/klines` | 1000 velas | 2 | Candlesticks OHLCV |\n",
    "| `/api/v3/aggTrades` | 1000 trades | 2 | Trades agregados (max 1h window) |\n",
    "| `/api/v3/historicalTrades` | 1000 trades | 25 | Trades individuales (requiere API key) |\n",
    "| `data.binance.vision` | Sin limite | 0 | CSVs bulk diarios/mensuales |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3fe45a0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import time\n",
    "import datetime\n",
    "import io\n",
    "import zipfile\n",
    "import pandas as pd\n",
    "\n",
    "BASE = \"https://api.binance.com\"\n",
    "DATA_VISION = \"https://data.binance.vision\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "721f68a0",
   "metadata": {},
   "source": [
    "## Metodo 1: REST API — Klines con paginacion automatica\n",
    "\n",
    "`GET /api/v3/klines` devuelve max 1000 velas. Paginamos con `startTime`/`endTime`.\n",
    "\n",
    "Para 7 dias de velas 1m: ceil(7*24*60/1000) = **11 requests** (22 weight total, trivial)."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
