harwee/IQOption-Api

Expiration list doesn't works

Closed this issue · 4 comments

Hello I've tryed the following script

### Initialisation
from iqoption_api import IQOption
api = IQOption("mail","pass")
api.login() # Returns True if successful else False

### Check Account Type
print(api.active_account) # prints `real` or `practice`
print(api.real_balance) # prints real account balance
print(api.practice_balance) # prints practice account balance
api.change_account("practice")
print(api.positions)  
print(api.tick) ## range 0, 59
api.subscribe_market("EURUSD")
print(api.instruments_to_id) ## All Instruments Websocket Returned
print(api.forex_instruments)
print(api.cfd_instruments)
print(api.crypto_instruments)
print ('UPDATE')
api.update_expiration_list("EURUSD")
print(api.binary_expiration_list)
api.open_position(direction="put", 
                expiration_time=api.binary_expiration_list["EURUSD"][-1]["time"],
                market_name="EURUSD",
                price=5,
                type="turbo"
               )

the following functions doesn't works, the update_expiration_list doesn't populate api.binary_expiration_list property

Update Expiration list
api.update_expiration_list("EURUSD")
Get Expiration List
print(api.binary_expiration_list["EURUSD"])

indeed when I try to put a buy action using:

api.open_position(direction="put", 
                expiration_time=api.binary_expiration_list["EURUSD"][-1]["time"],
                market_name="EURUSD",
                price=5,
                type="turbo"
               )

I obtain:

Traceback (most recent call last):
File "tbot-test.py", line 23, in
expiration_time=api.binary_expiration_list["EURUSD"][-1]["time"],
KeyError: 'EURUSD'

Checking api.binary_expiration_list is empty

same problem.
not all time but same ....
put not work... no action if no print error....

Every request in api is socket based and asynchronous, there will be a time delay between request and response, it depends on your Internet speed and/or response time of the server. If data is not available even after requesting it, data hasn't arrived yet.

You can handle it with a while loop and a delay, like the following:

  1. Make request
  2. While(true)
    3. Delay(5) // 5ms
    4. Check whether data exists // if true, break out
  3. The rest of your code

You should handle the posibility that you never get a response, so implement a counter in the else block and break out after x times.

It's the simplest implementation to handle this problem.

You can try the code written here https://github.com/harwee/IQOption-Api/tree/async If you face any difficulty please reopen the issue