IOL: More aggressive caching, even if token fails

This commit is contained in:
Roberto Alsina 2023-08-31 15:17:58 -03:00
parent af94db7d4e
commit 3173c610bf
1 changed files with 26 additions and 26 deletions

View File

@ -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]