Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_digital_spot_profit_after_sale division error #144

Open
kkagill opened this issue Nov 6, 2019 · 10 comments
Open

get_digital_spot_profit_after_sale division error #144

kkagill opened this issue Nov 6, 2019 · 10 comments
Labels
bug Something isn't working TODO will be add or fix something

Comments

@kkagill
Copy link

kkagill commented Nov 6, 2019

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:
         .... 
@kkagill
Copy link
Author

kkagill commented Nov 6, 2019

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

@Lu-Yi-Hsun
Copy link
Owner

Thank I will fix that

@Lu-Yi-Hsun Lu-Yi-Hsun added the TODO will be add or fix something label Nov 9, 2019
@Lu-Yi-Hsun
Copy link
Owner

fix

@Lu-Yi-Hsun Lu-Yi-Hsun added FIX already fixed the bug and removed TODO will be add or fix something labels Nov 26, 2019
@kkagill
Copy link
Author

kkagill commented Nov 27, 2019

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?

@JafferWilson
Copy link

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

@kkagill
Copy link
Author

kkagill commented Nov 27, 2019

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

@Lu-Yi-Hsun
Copy link
Owner

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?

@kkagill
Copy link
Author

kkagill commented Nov 27, 2019

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")

@Lu-Yi-Hsun
Copy link
Owner

@kkagill thank report i roll back the get_digital_spot_profit_after_sale first, and try to improve

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 27, 2019

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

@Lu-Yi-Hsun Lu-Yi-Hsun added bug Something isn't working TODO will be add or fix something and removed FIX already fixed the bug labels Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TODO will be add or fix something
Projects
None yet
Development

No branches or pull requests

3 participants