Open kkagill opened 4 years ago
i'm handling like this for now
try:
pl = I_want_money.iqOptionApi.get_digital_spot_profit_after_sale(buyId)
return pl
except ZeroDivisionError as e:
logging.exception(e)
return 0.0
Thank I will fix that
fix
Hi @Lu-Yi-Hsun , Thanks for the fix, but I found some error.
from iqoptionapi.stable_api import IQ_Option
import threading
import time
I_want_money=IQ_Option("","")
markets = ["EURUSD", "AUDCAD", "GBPCHF"]
thread_list = []
def buy_digital_spot(actives, amount, action, duration):
id=I_want_money.buy_digital_spot(actives,amount,action,duration)
while True:
PL=I_want_money.get_digital_spot_profit_after_sale(id)
print(PL, actives)
time.sleep(1)
for market in markets:
I_want_money.subscribe_strike_list(market,1)
thread = threading.Thread(target=buy_digital_spot, args=[market, 1, 'put', 1], daemon=True)
thread_list.append(thread)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()
print("ended")
So I'm running multiple threads at the same time, and if you run this code you will see that sometimes it returns None
in version 5.2
I also tried this with version 5.1 and it was working fine
pip install git+git://github.com/Lu-Yi-Hsun/iqoptionapi.git@6e3526afea1c21fabcf65da71f325febf454ab04
I think you can revert it back or do more test on this?
@kkagill The answer to this is already given by @Lu-Yi-Hsun many times. The API is not thread safe. You cannot use thread with the api. Instead you can create the different applications for the different Symbols.
@JafferWilson Have you even tried to look into code or execute my code snippets?
This is caused by the recent change in version 5.2
I am aware that it's not thread safe, so I am locking it with aquire
and release
to avoid a possible race condition. Anyways, v 5.1 was fine but the latest version should be modified.
PL = I_want_money.iqOptionApi.get_digital_spot_profit_after_sale(buyId)
I found that I got this error msg
Traceback (most recent call last): currentPercent = I_want_money.iqOptionApi.get_digital_spot_profit_after_sale(buyId) File "C:\Python36\lib\site-packages\iqoptionapi\stable_api.py", line 891, in get_digital_spot_profit_after_sale instrumentStrikeValue = (instrumentStrikeValue - spotUpperInstrumentStrike) / abs(spotUpperInstrumentStrike - spotLowerInstrumentStrike); ZeroDivisionError: float division by zero
How to prevent this? maybe you can add a check for zero before you divide? Ex:
if (instrumentStrikeValue - spotUpperInstrumentStrike) == 0: if abs(spotUpperInstrumentStrike - spotLowerInstrumentStrike) == 0: ....
This bug not fix?
It fixed the division exception, but it's returning None
too many times.
Please try my code snippets in both version 5.1 and 5.2. Version 5.1 seems to be working fine, but 5.2 is not.
from iqoptionapi.stable_api import IQ_Option
import threading
import time
I_want_money=IQ_Option("","")
markets = ["EURUSD", "AUDCAD", "GBPCHF"]
thread_list = []
lock = threading.Lock()
def buy(actives, amount, action, duration):
try:
lock.acquire()
return I_want_money.buy_digital_spot(actives,amount,action,duration)
except Exception as e:
print(e)
finally:
lock.release()
def buy_digital_spot(actives, amount, action, duration):
id = buy(actives, amount, action, duration)
while True:
PL=I_want_money.get_digital_spot_profit_after_sale(id)
print(PL, actives)
time.sleep(1)
for market in markets:
I_want_money.subscribe_strike_list(market,1)
thread = threading.Thread(target=buy_digital_spot, args=[market, 1, 'put', 1], daemon=True)
thread_list.append(thread)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()
print("ended")
@kkagill thank report i roll back the get_digital_spot_profit_after_sale first, and try to improve
5.2.1 roll back the get_digital_spot_profit_after_sale,
the get_digital_spot_profit_after_sale api is not perfect because some pice of code not crack yet
i will try to decompiler other source code
PL = I_want_money.iqOptionApi.get_digital_spot_profit_after_sale(buyId)
I found that I got this error msg
How to prevent this? maybe you can add a check for zero before you divide? Ex: