harwee / IQOption-Api

** Unmaintained ** I have rewritten some of the functionality using async if you are want to use the updated code you can use the code from `async` branch
Apache License 2.0
53 stars 54 forks source link

Expiration list doesn't works #12

Closed gpiedimonte closed 5 years ago

gpiedimonte commented 6 years ago

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

remarco commented 6 years ago

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

harwee commented 6 years ago

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.

SeanStayn commented 6 years ago

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

  1. Make request
  2. While(true)
    1. Delay(5) // 5ms
    2. 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.

harwee commented 5 years ago

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