Get start¶
document version¶
last update:2024/11/15
v 9.0
fix opcode
version 8.7 fix set_call_back_for_client
version 8.6
add get_all_profit_v2
version 8.5 fix get_realtime_strike_list
version 8.4.1
fix get_all_profit
Version 8.4
fix digital spot
Version 8.3
- fix and update proxy better
Version 8.0
- if iqoption close, that will auto reconnect not effect
- more stable
install iqoptionapi¶
download the source code and run this
python setup.py install
little sample¶
import time
from iqoptionapi.stable_api import IQ_Option
I_want_money=IQ_Option("email","password")
I_want_money.connect()#connect to iqoption
goal="EURUSD"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))
Import¶
from iqoptionapi.stable_api import IQ_Option
Login¶
I_want_money.connect() will return (check,reason)
if connect sucess return True,None
if connect fail return False,reason
from iqoptionapi.stable_api import IQ_Option
import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")
check, reason=I_want_money.connect()#connect to iqoption
print(check, reason)
Login by pass 2FA¶
from iqoptionapi.stable_api import IQ_Option
import json
account=IQ_Option("email","password")
_,r=account.connect()
if r !="":
r=json.loads(r)
if "method" in r:
r=account.TWO_FA(method="sms",token=r["token"])
code=input("Please input SMS CODE\n")
r=account.TWO_FA(code=code,token=r["token"])
if r["code"]=="success":
account.setting_2FA_TOKEN(r["token"])
check,_=account.connect()
if check:
print("Login OK!!")
proxy¶
from iqoptionapi.stable_api import IQ_Option
#!!!Just a Sample host prot and auth!!!!
http_proxy_host="xxx.com"
http_proxy_port="7788"
http_proxy_auth=["account","password"]
I_want_money=IQ_Option("email","password",http_proxy_host=http_proxy_host,http_proxy_port=http_proxy_port,http_proxy_auth=http_proxy_auth)
check, reason=I_want_money.connect()#connect to iqoption
print(check, reason)
Debug mode on¶
import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
Connect&Check connect¶
some time connect will close so this way can check connect and reconnect
try close your network and restart network in this sample
from iqoptionapi.stable_api import IQ_Option
error_password="""{"code":"invalid_credentials","message":"You entered the wrong credentials. Please check that the login/password is correct."}"""
iqoption = IQ_Option("email", "password")
check,reason=iqoption.connect()
if check:
print("Start your robot")
#if see this you can close network for test
while True:
if iqoption.check_connect()==False:#detect the websocket is close
print("try reconnect")
check,reason=iqoption.connect()
if check:
print("Reconnect successfully")
else:
if reason==error_password:
print("Error Password")
else:
print("No Network")
else:
if reason=="[Errno -2] Name or service not known":
print("No Network")
elif reason==error_password:
print("Error Password")
set_session¶
Default User-Agent is "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"
from iqoptionapi.stable_api import IQ_Option
import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")
#Default is "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"
header={"User-Agent":r"Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"}
cookie={"I_want_money":"GOOD"}
I_want_money.set_session(header,cookie)
I_want_money.connect()#connect to iqoption
Check version¶
from iqoptionapi.stable_api import IQ_Option
print(IQ_Option.__version__)
Check connect¶
return True/False
print(I_want_money.check_connect())
Reconnect¶
I_want_money.connect()
time¶
get_server_timestamp the get_server_timestamp time is sync with iqoption
I_want_money.get_server_timestamp()