diff --git a/iol/handler.py b/iol/handler.py index 0c01cce..c40159d 100644 --- a/iol/handler.py +++ b/iol/handler.py @@ -62,13 +62,13 @@ def get_accion(secret, pais, accion): raise Exception("BAD") pais = pais.upper() accion = accion.upper() - access, refresh = get_token(ttl_hash=get_ttl_hash()) - url = ( - BASE_URL - + f"/api/v2/Cotizaciones/acciones/{pais}/Todos?cotizacionInstrumentoModel.instrumento=acciones&cotizacionInstrumentoModel.pais={paises[pais]}&api_key={access}" - ) - data = get(url, ttl_hash=get_ttl_hash()) try: + access, refresh = get_token(ttl_hash=get_ttl_hash()) + url = ( + BASE_URL + + f"/api/v2/Cotizaciones/acciones/{pais}/Todos?cotizacionInstrumentoModel.instrumento=acciones&cotizacionInstrumentoModel.pais={paises[pais]}&api_key={access}" + ) + data = get(url, ttl_hash=get_ttl_hash()) last_results[f"accion/{pais}/{accion}"] = [ a for a in data["titulos"] if a["simbolo"] == accion ][0] @@ -83,12 +83,12 @@ def get_bono(secret, nombre): raise Exception("BAD") nombre = nombre.upper() access, refresh = get_token(ttl_hash=get_ttl_hash()) - url = ( - BASE_URL - + f"/api/v2/Cotizaciones/titulosPublicos/ar/Todos?cotizacionInstrumentoModel.instrumento=titulosPublicos&cotizacionInstrumentoModel.pais=argentina&api_key={access}" - ) - data = get(url, ttl_hash=get_ttl_hash()) try: + url = ( + BASE_URL + + f"/api/v2/Cotizaciones/titulosPublicos/ar/Todos?cotizacionInstrumentoModel.instrumento=titulosPublicos&cotizacionInstrumentoModel.pais=argentina&api_key={access}" + ) + data = get(url, ttl_hash=get_ttl_hash()) last_results[f"bono/{nombre}"] = [ a for a in data["titulos"] if a["simbolo"] == nombre ][0] @@ -103,12 +103,12 @@ def get_cedear(secret, nombre): raise Exception("BAD") nombre = nombre.upper() access, refresh = get_token(ttl_hash=get_ttl_hash()) - url = ( - BASE_URL - + f"/api/v2/Cotizaciones/cedears/ar/Todos?cotizacionInstrumentoModel.instrumento=cedears&cotizacionInstrumentoModel.pais=argentina&api_key={access}" - ) - data = get(url, ttl_hash=get_ttl_hash()) try: + url = ( + BASE_URL + + f"/api/v2/Cotizaciones/cedears/ar/Todos?cotizacionInstrumentoModel.instrumento=cedears&cotizacionInstrumentoModel.pais=argentina&api_key={access}" + ) + data = get(url, ttl_hash=get_ttl_hash()) last_results[f"cedear/{nombre}"] = [ a for a in data["titulos"] if a["simbolo"] == nombre ][0] @@ -123,12 +123,12 @@ def get_on(secret, nombre): raise Exception("BAD") nombre = nombre.upper() access, refresh = get_token(ttl_hash=get_ttl_hash()) - url = ( - BASE_URL - + f"/api/v2/Cotizaciones/obligacionesnegociables/ar/Todos?cotizacionInstrumentoModel.instrumento=obligacionesNegociables&cotizacionInstrumentoModel.pais=argentina&api_key={access}" - ) - data = get(url, ttl_hash=get_ttl_hash()) try: + url = ( + BASE_URL + + f"/api/v2/Cotizaciones/obligacionesnegociables/ar/Todos?cotizacionInstrumentoModel.instrumento=obligacionesNegociables&cotizacionInstrumentoModel.pais=argentina&api_key={access}" + ) + data = get(url, ttl_hash=get_ttl_hash()) last_results[f"ON/{nombre}"] = [ a for a in data["titulos"] if a["simbolo"] == nombre ][0] @@ -143,12 +143,12 @@ def get_adrs(secret, nombre): raise Exception("BAD") nombre = nombre.upper() access, refresh = get_token(ttl_hash=get_ttl_hash()) - url = ( - BASE_URL - + f"/api/v2/Cotizaciones/adrs/us/Todos?cotizacionInstrumentoModel.instrumento=aDRs&cotizacionInstrumentoModel.pais=estados_Unidos&api_key={access}" - ) - data = get(url, ttl_hash=get_ttl_hash()) try: + url = ( + BASE_URL + + f"/api/v2/Cotizaciones/adrs/us/Todos?cotizacionInstrumentoModel.instrumento=aDRs&cotizacionInstrumentoModel.pais=estados_Unidos&api_key={access}" + ) + data = get(url, ttl_hash=get_ttl_hash()) last_results[f"ADR/{nombre}"] = [ a for a in data["titulos"] if a["simbolo"] == nombre ][0]