Cliente Python para la API de Invertir Online
Project description
pyIOL
Cliente Python para interactuar con la API REST de Invertir Online (IOL), una plataforma de trading e inversiones de Argentina.
Disclaimer
ADVERTENCIA IMPORTANTE
Esta libreria NO es oficial de Invertir Online. Es un proyecto independiente desarrollado por la comunidad.
El desarrollador NO se hace responsable por cualquier dano, perdida financiera, o perjuicio que pueda ocasionar el uso de esta libreria, incluyendo pero no limitado a:
- Perdidas economicas por operaciones ejecutadas
- Errores en la interpretacion de datos
- Fallos en la ejecucion de ordenes
- Cualquier otro problema derivado del uso de este software
Esta libreria puede contener bugs no descubiertos. Usela bajo su propia responsabilidad y con extrema precaucion, especialmente en operaciones que involucren dinero real.
Se recomienda encarecidamente probar primero en el entorno sandbox de IOL antes de usar en produccion.
Objetivos
- Proporcionar una interfaz Python simple y tipada para la API de IOL
- Facilitar la automatizacion de consultas de cotizaciones y datos de mercado
- Permitir la gestion programatica de portafolios e inversiones
- Ofrecer modelos de datos tipados para una mejor experiencia de desarrollo
Caracteristicas
- Autenticacion OAuth2 con cache automatico de tokens
- Modelos de datos tipados (dataclasses) para todas las respuestas
- Soporte para multiples mercados (BCBA, NYSE, NASDAQ, etc.)
- Metodos para cotizaciones, portafolio, operaciones, FCI, y mas
- Context manager para manejo seguro de conexiones
Requisitos
- Python >= 3.8
- Cuenta activa en Invertir Online con API habilitada
Instalacion
Desde PyPI
pip install pyiol-client
Desde el repositorio (desarrollo)
# Clonar el repositorio
git clone https://github.com/ezeprimo/py_iol.git
cd py_iol
# Instalar con uv (recomendado)
uv sync
# O con pip en modo desarrollo
pip install -e ".[dev]"
Dependencias
httpx>=0.24.0- Cliente HTTPcachetools>=5.0.0- Cache para tokens
Configuracion
- Crear archivo
.enven la raiz del proyecto:
cp .env.example .env
- Editar
.envcon tus credenciales de IOL:
IOL_USERNAME=tu_usuario_iol
IOL_PASSWORD=tu_password_iol
Uso Basico
Consultar Cotizaciones
from pyIol import IOLClient, Markets, SettlementTerms
# Crear cliente (usa context manager para cerrar conexion automaticamente)
with IOLClient("usuario", "password") as client:
# Cotizacion de GGAL
cotizacion = client.get_stock_quote("GGAL")
print(f"GGAL: ${cotizacion.ultimo_precio}")
print(f"Variacion: {cotizacion.variacion}%")
# Cotizacion con plazo T2
cotizacion_t2 = client.get_stock_quote(
"GGAL",
settlement_term=SettlementTerms.T2
)
Consultar Portafolio
from pyIol import IOLClient, Countries
with IOLClient("usuario", "password") as client:
# Obtener portafolio de Argentina
portafolio = client.get_portfolio(Countries.ARGENTINA)
print(f"Total valorizado: ${portafolio.total_valorizado:,.2f}")
print(f"Ganancia total: ${portafolio.total_ganancia:,.2f}")
# Listar posiciones
for titulo in portafolio.todos_los_titulos:
print(f"{titulo.simbolo}: {titulo.cantidad} unidades")
print(f" Ganancia: {titulo.ganancia_porcentaje:+.2f}%")
Cotizaciones Masivas
from pyIol import IOLClient
with IOLClient("usuario", "password") as client:
# Todas las acciones argentinas
cotizaciones = client.get_massive_quotes("acciones", "argentina")
for titulo in cotizaciones.titulos[:5]:
print(f"{titulo.simbolo}: ${titulo.ultimo_precio}")
# Panel MERVAL
merval = client.get_panel_quotes("acciones", "merval", "argentina")
for titulo in merval.titulos:
print(f"{titulo.simbolo}: {titulo.variacion_porcentual:+.2f}%")
Consultar Operaciones
from pyIol import IOLClient, OperationStates
from datetime import datetime, timedelta
with IOLClient("usuario", "password") as client:
# Operaciones de los ultimos 30 dias
operaciones = client.get_operations(
estado=OperationStates.ALL,
fecha_desde=datetime.now() - timedelta(days=30),
fecha_hasta=datetime.now()
)
for op in operaciones:
print(f"#{op.numero}: {op.tipo} {op.simbolo} - {op.estado}")
Usando Variables de Entorno
import os
from dotenv import load_dotenv
from pyIol import IOLClient
load_dotenv()
with IOLClient(
os.getenv("IOL_USERNAME"),
os.getenv("IOL_PASSWORD")
) as client:
if client.test_authentication():
print("Autenticacion exitosa!")
Estructura del Proyecto
py_iol/
├── pyIol/ # Paquete principal
│ ├── __init__.py # Exports publicos
│ ├── client.py # Cliente HTTP para la API
│ ├── models.py # Dataclasses para respuestas
│ └── constants.py # URLs, mercados, plazos
├── doc/ # Documentacion y ejemplos
│ ├── README.md # Indice de documentacion
│ ├── iol_api_doc.MD # Documentacion de la API de IOL
│ └── notebooks/ # Jupyter notebooks de ejemplo
│ ├── 01_autenticacion.ipynb
│ ├── 02_cotizaciones_basicas.ipynb
│ ├── 03_cotizaciones_avanzadas.ipynb
│ ├── 04_cuenta_portafolio.ipynb
│ ├── 05_trading.ipynb
│ ├── 06_fci.ipynb
│ ├── 07_mep_simplificado.ipynb
│ ├── 08_cpd.ipynb
│ └── 09_asesores.ipynb
├── pyproject.toml # Configuracion del proyecto
├── .env.example # Ejemplo de credenciales
└── README.md # Este archivo
Documentacion
La documentacion completa se encuentra en la carpeta doc/:
- Documentacion de la API - Referencia completa de endpoints de IOL
- Notebooks de ejemplo - Jupyter notebooks interactivos para cada funcionalidad
Endpoints Disponibles
| Categoria | Metodos |
|---|---|
| Autenticacion | test_authentication() |
| Perfil | get_profile_data() |
| Cotizaciones | get_stock_quote(), get_stock_data(), get_stock_options(), get_massive_quotes(), get_panel_quotes(), get_stock_quote_detailed() |
| Cuenta | get_account_status(), get_portfolio() |
| Operaciones | get_operations(), get_operation_detail() |
| Trading | buy_stock(), sell_stock() |
| FCI | get_fci_list(), get_fci_detail(), subscribe_fci(), rescue_fci() |
| Dolar MEP | get_mep_dollar_rate(), estimate_mep_operation() |
Cada metodo tiene su version
_raw()que retorna el JSON original de la API.
Constantes Disponibles
Mercados
from pyIol import Markets
Markets.BCBA # Bolsa de Buenos Aires
Markets.NYSE # New York Stock Exchange
Markets.NASDAQ # NASDAQ
Markets.AMEX # American Stock Exchange
Markets.BCS # Bolsa de Santiago
Markets.ROFX # ROFEX (Futuros)
Plazos de Liquidacion
from pyIol import SettlementTerms
SettlementTerms.T0 # Contado inmediato
SettlementTerms.T1 # 24 horas (default)
SettlementTerms.T2 # 48 horas
SettlementTerms.T3 # 72 horas
Estados de Operacion
from pyIol import OperationStates
OperationStates.ALL # Todas
OperationStates.PENDING # Pendientes
OperationStates.FINISHED # Terminadas
OperationStates.CANCELLED # Canceladas
Contribuir
Las contribuciones son bienvenidas. Consulta la Guia de Contribucion para detalles sobre:
- Configuracion del entorno de desarrollo
- Sistema de versionado semantico
- Proceso de publicacion a PyPI
- Estandares de codigo
Resumen rapido:
- Fork el repositorio
- Crea una rama para tu feature (
git checkout -b feature/nueva-funcionalidad) - Commit tus cambios (
git commit -am 'Agrega nueva funcionalidad') - Push a la rama (
git push origin feature/nueva-funcionalidad) - Abre un Pull Request
Licencia
Este proyecto esta bajo la licencia especificada en el archivo LICENCE.
Autor
Ezequiel Primon - ezeprimo@gmail.com
Enlaces
Recuerda: Esta libreria interactua con sistemas financieros reales. Usala con responsabilidad y siempre verifica las operaciones antes de ejecutarlas.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyiol_client-0.1.0.tar.gz.
File metadata
- Download URL: pyiol_client-0.1.0.tar.gz
- Upload date:
- Size: 181.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e58966f7ba5a4d3ba4b9692155d276c807adc7abe50e8bf8635964c97927b5
|
|
| MD5 |
f3572e1afedc88783553ff2275d6a1d6
|
|
| BLAKE2b-256 |
4825ffe8e7e5b6794098de8d039ecea683d69293ad1d60adf090024bda5c8e2f
|
Provenance
The following attestation bundles were made for pyiol_client-0.1.0.tar.gz:
Publisher:
publish.yml on ezeprimo/py_iol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyiol_client-0.1.0.tar.gz -
Subject digest:
14e58966f7ba5a4d3ba4b9692155d276c807adc7abe50e8bf8635964c97927b5 - Sigstore transparency entry: 1005541226
- Sigstore integration time:
-
Permalink:
ezeprimo/py_iol@7c14fbb69ba127ef07756386fa004ab4681e0154 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ezeprimo
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c14fbb69ba127ef07756386fa004ab4681e0154 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyiol_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyiol_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20b6f4a34157093d35fa43c31fe8df9997a64c207966e182b62698bf7b4854d0
|
|
| MD5 |
ec2876a148c4c1f51f45efa2365498ea
|
|
| BLAKE2b-256 |
7950efd78a1b95b3d8c3efb51e229b32ba5d9457444f88c32d77940c57ee474a
|
Provenance
The following attestation bundles were made for pyiol_client-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on ezeprimo/py_iol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyiol_client-0.1.0-py3-none-any.whl -
Subject digest:
20b6f4a34157093d35fa43c31fe8df9997a64c207966e182b62698bf7b4854d0 - Sigstore transparency entry: 1005541227
- Sigstore integration time:
-
Permalink:
ezeprimo/py_iol@7c14fbb69ba127ef07756386fa004ab4681e0154 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ezeprimo
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c14fbb69ba127ef07756386fa004ab4681e0154 -
Trigger Event:
push
-
Statement type: