I am working with the API of a platform to receive currency quotes minute by minute, I have a way of doing it but it is not very functional and I wanted to check if someone could help me, this is my code:
from iqoptionapi.api import IQOptionAPI
from datetime import datetime
velas = None
contador = 1
while True:
if velas is None:
api = IQOptionAPI("iqoption.com", "usuario", "contraseña") # Datos de conexión
api.connect()
api.getcandles(1,1) # (id_activo, tiempo)
velas = api.candles.candles_data # Lista con vela 1 segundo retrasada y vela actual
print ("Intento de conexion...\n")
else:
if datetime.now().second == 59 and datetime.now().microsecond > 998000: # determinar cuándo sea un minuto
print ("Peticion de velas:", contador, "-", datetime.now(), "\n")
api.getcandles(1, 1)
velas = api.candles.candles_data
print (velas, "\n")
print ("Hora primera lista:" datetime.fromtimestamp(velas[0][0]), "Hora segunda lista:", datetime.fromtimestamp(velas[1][0]), "\n")
contador += 1
else:
pass
The problem is that sometimes you get more than one quote because being a loop still falls within 59 seconds or there are even times when you do not receive anything for not falling within the range of the comparison, try to solve it with time.sleep(60)
but it introduces me a one-minute deface in the quotes that I do not know why it happens.
Thank you.