Giter Club home page Giter Club logo

iqoptionapi's Introduction

IQ Option API

last Version:3.4

last update:2018/11/22

Version 3.4

FIX buy id None:Lu-Yi-Hsun#52

FIX Options Profits Lu-Yi-Hsun#50

Version 3.3

Version 3.2

Version 3.1

Version 3.0

sucess on python3.6.5


About API

#hight level api ,This api is write base on ""iqoptionapi.api" for more easy
from iqoptionapi.stable_api import IQ_Option
#low level api
from iqoptionapi.api import IQOptionAPI
.
├── docs
├── iqoptionapi(API code)
    ├── http(doing http get/post)
    └── ws
        ├── chanels(Doing websocket action)
        └── objects(Get back data from websocket action)

Can not loging problem

this problem i have been pull request to websocket-client

If you get this problem

error from callback <bound method WebsocketClient.on_message of <iqoptionapi.ws.client.WebsocketClient object at 0x7f174fdb5e48>>: on_message() missing 1 required positional argument: 'message'
  File "/usr/lib/python3.7/site-packages/websocket/_app.py", line 343, in _callback
   callback(*args)

fix way 1(install old websocket-client version)

sudo pip3 uninstall websocket-client
sudo pip3 install websocket-client==0.47.0

fix way 2(install my fix version on latest)

sudo pip3 install -U git+git://github.com/Lu-Yi-Hsun/websocket-client.git

Installation & GET new version

For Python3

sudo pip3 install -U git+git://github.com/Lu-Yi-Hsun/iqoptionapi.git

For Python2

sudo pip2 install -U git+git://github.com/Lu-Yi-Hsun/iqoptionapi.git

Littile sample

import time
from iqoptionapi.stable_api import IQ_Option
I_want_money=IQ_Option("email","password")
goal="EURUSD"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))

Find ticker symbol

when you buy some thing you need to know ""ticker"" symbol

if you want to buy ""Alphabet Inc."" ticker symbol:""GOOGL"" buysomeapi("GOOGL")

you can find ticker symbol here

https://iqoption.com/en/assets


Document

Import

from iqoptionapi.stable_api import IQ_Option

Debug mode on

import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')

Login

!!!

Login NOT support SMS Authorization yet

I suggest close it because your robot will stop to wait you to check sms code (on phone)....

!!!

I_want_money=IQ_Option("email","password")

default number is 5

Lu-Yi-Hsun#22

Protect if you get some error (iqoptionapi auto reconnect) too many time,IQoption will ban your IP

I_want_money.set_max_reconnect(number)

Reconnect&check connect

some time connect will close so this way can check connect and reconnect

sample

I_want_money=IQ_Option("email","password")
#check if connect
if I_want_money.check_connect()==False:
    I_want_money.connect()#if not connect it will reconnect

Check version

I_want_money=IQ_Option("email","password")
print(I_want_money.__version__)

View all ACTIVES Name

you will get right all ACTIVES and code

ACTIVE_CODE.txt

print(I_want_money.get_all_ACTIVES_OPCODE())

For Options

Sample

from iqoptionapi.stable_api import IQ_Option
import logging
import time
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","pass")
goal="EURUSD"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))
Money=1
ACTIVES="EURUSD"
ACTION="call"#or "put"
expirations_mode=1
force_buy= False#i suggest use False
I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode,force_buy)
I_want_money.buy(Money,ACTIVES,ACTION,expirations,force_buy)
                #Money:How many you want to buy type(int)
                #ACTIVES:sample input "EURUSD" OR "EURGBP".... you can view by get_all_ACTIVES_OPCODE
                #ACTION:"call"/"put" type(str)
                #expirations:input minute,careful too large will false to buy(Closed market time)thank Darth-Carrotpie's code (int)https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
                #force_buy= True: if fail try buy untill sucess 
                            #False:if fail break
                #return:(None/id_number):if sucess return (id_number) esle return(None) 2.1.5 change this 
I_want_money.sell_option(sell_all)#input int or list

Sample

from iqoptionapi.stable_api import IQ_Option
import time
print("login...")
I_want_money=IQ_Option("email","password")

Money=1
ACTIVES="EURUSD"
ACTION="call"#or "put"
expirations_mode=1
force_buy= False
id=I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode,force_buy)
id2=I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode,force_buy)

time.sleep(5)
sell_all=[]
sell_all.append(id)
sell_all.append(id2)
print(I_want_money.sell_option(sell_all))

check win

(only for option)

It will do loop until get win or loose

it have a little problem when network close and reconnect miss get "listInfoData"

this function will doing Infinity loop

I_want_money.check_win(23243221)
#""you need to get id_number from buy function""
#I_want_money.check_win(id_number)
#this function will do loop check your bet until if win/equal/loose
check_win_v2

(only for option)

more better way

an other way to fix that(implement by get_betinfo)

input by int

I_want_money.check_win_v2(23243221)
#""you need to get id_number from buy function""
#I_want_money.check_win_v2(id_number)
#this function will do loop check your bet until if win/equal/loose

"get_binary_option_detail" and "get_all_profit" are base on "get_all_init()",if you want raw data you can call

I_want_money.get_all_init()

get_binary_option_detail

sample

from iqoptionapi.stable_api import IQ_Option
print("login...")
I_want_money=IQ_Option("email","password")
d=I_want_money.get_binary_option_detail()
print(d["CADCHF"]["turbo"])
print(d["CADCHF"]["binary"])

get all profit

sample

from iqoptionapi.stable_api import IQ_Option
print("login...")
I_want_money=IQ_Option("email","password")
d=I_want_money.get_all_profit()
print(d["CADCHF"]["turbo"])
print(d["CADCHF"]["binary"])

get_betinfo

(only for option)

it will get infomation about Bet by "id"

if your bet(id) not have answer yet(game_state) or wrong id it will return False input by int

 
isSuccessful,dict=I_want_money.get_betinfo(4452272449)
#I_want_money.get_betinfo 
#INPUT: int
#OUTPUT:isSuccessful,dict

input how many data you want to get from Trading History(only for binary option)

print(I_want_money.get_optioninfo(10))


Sample

from iqoptionapi.stable_api import IQ_Option
import time
import random
I_want_money=IQ_Option("email","password")

ACTIVES="EURUSD"
duration=1#minute 1 or 5
amount=1
I_want_money.subscribe_strike_list(ACTIVES)
#get strike_list
data=I_want_money.get_realtime_strike_list(ACTIVES, duration)
print("get strike data")
print(data)
"""data
{'1.127100': 
    {  'call': 
            {   'profit': None, 
                'id': 'doEURUSD201811120649PT1MC11271'
            },   
        'put': 
            {   'profit': 566.6666666666666, 
                'id': 'doEURUSD201811120649PT1MP11271'
            }	
    }............
} 
"""
#get price list
price_list=list(data.keys())
#random choose Strategy
choose_price=price_list[random.randint(0,len(price_list)-1)]
#get instrument_id
instrument_id=data[choose_price]["call"]["id"]
#get profit
profit=data[choose_price]["call"]["profit"]
print("choose you want to buy")
print("price:",choose_price,"side:call","instrument_id:",instrument_id,"profit:",profit)
#put instrument_id to buy
buy_check,id=I_want_money.buy_digital(amount,instrument_id)
if buy_check:
    print("wait for check win")
    #check win
    while True:
        check_close,win_money=I_want_money.check_win_digital(id)
        if check_close:
            if float(win_money)>0:
                win_money=("%.2f" % (win_money))
                print("you win",win_money,"money")
            else:
                print("you loose")
            break
    I_want_money.unsubscribe_strike_list(ACTIVES)
else:
    print("fail to buy,please run again")

Get all strike list data

Data format
{'1.127100': {  'call': {'profit': None, 'id': 'doEURUSD201811120649PT1MC11271'},   'put': {'profit': 566.6666666666666, 'id': 'doEURUSD201811120649PT1MP11271'}	}.......}  
sample
from iqoptionapi.stable_api import IQ_Option
import time
I_want_money=IQ_Option("email","password")
ACTIVES="EURUSD"
duration=1#minute 1 or 5
I_want_money.subscribe_strike_list(ACTIVES)
while True:
    data=I_want_money.get_realtime_strike_list(ACTIVES, duration)
    for price in data:
        print("price",price,data[price])
    time.sleep(5)
I_want_money.unsubscribe_strike_list(ACTIVES)

Buy digit

buy_check,id=I_want_money.buy_digital(amount,instrument_id)
#get instrument_id from I_want_money.get_realtime_strike_list

check win for digital

I_want_money.check_win_digital(id)#get the id from I_want_money.buy_digital
#return:check_close,win_money
#return sample
#if you loose:Ture,o
#if you win:True,1232.3
#if trade not clode yet:False,None

close digital

I_want_money.close_position(id)

get digital data

print(I_want_money.get_order(id))
print(I_want_money.get_positions("digital-option"))
print(I_want_money.get_position_history("digital-option"))

For Forex&Stock&Commodities&Crypto&ETFs

you need to check Asset is open or close!

About instrument_type

Forex Stock Commodities Crypto ETFs
instrument_type "forex" "cfd" "cfd" "crypto" "cfd"

About active

if you want to buy ""Alphabet Inc.""

find ticker symbol

https://iqoption.com/en/assets

you can find "Alphabet Inc."'s ticker symbol is "GOOGLE"

instrument_id="GOOGL"

Sample

from iqoptionapi.stable_api import IQ_Option
import logging
import time
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")

instrument_type="crypto"
instrument_id="BTCUSD"
side="buy"#sell
type="market"#limit
amount=11
limit_price=2#for limit ,if you choose market this not work,
leverage=3#you can get more information in get_available_leverages()
stop_lose_price=1#
take_profit_price=20000#

check,order_id=I_want_money.buy_order(instrument_type,instrument_id,side,type,amount,limit_price,leverage,stop_lose_price,take_profit_price)
print(I_want_money.get_order(order_id))
print(I_want_money.get_positions("crypto"))
print(I_want_money.get_position_history("crypto"))
print(I_want_money.get_available_leverages("crypto","BTCUSD"))
print(I_want_money.close_position(order_id))
print(I_want_money.get_overnight_fee("crypto","BTCUSD"))

Buy

return (True/False,buy_order_id/False)

if Buy sucess return (True,buy_order_id)

instrument_type="crypto"
instrument_id="BTCUSD"
side="buy"#sell
type="market"#limit
amount=11#How many money you want investment
limit_price=2#for limit ,if you choose market this not work,
leverage=3#you can get more information in get_available_leverages()
stop_lose_price=1#stop lose price
take_profit_price=20000#take profit price

I_want_money.buy_order(instrument_type,instrument_id,side,type,amount,limit_price,leverage,stop_lose_price,take_profit_price)
change_order(buy_order_id,stop_lose,take_profit,use_trail_stop)

sample

from iqoptionapi.stable_api import IQ_Option
import time
print("login...")
I_want_money=IQ_Option("email","password")
instrument_type="crypto"
instrument_id="BTCUSD"
side="buy"#sell
type="market"#limit
amount=11
limit_price=2#for limit ,if you choose market this not work,
leverage=3#you can get more information in get_available_leverages()
stop_lose_price=1#
take_profit_price=20000#
print("doing buy_order stop_lose_price="+str(stop_lose_price)+"take_profit_price"+str(take_profit_price)+"use_trail_stop=False")
check,order_id=I_want_money.buy_order(instrument_type,instrument_id,side,type,amount,limit_price,leverage,stop_lose_price,take_profit_price)
time.sleep(20)
print("doing change_order stop_lose_price="+str(stop_lose_price+2)+"take_profit_price"+str(take_profit_price-500)+"use_trail_stop=True")
print("change_order respond")
print(I_want_money.change_order(order_id,stop_lose_price+2,take_profit_price-500,True))

get_order

get infomation about buy_order_id

return (True/False,get_order,None)

I_want_money.get_order(buy_order_id)

get_positions

you will get there data

return (True/False,get_positions,None)

I_want_money.get_positions(instrument_type)

get_position_history

you will get there data

return (True/False,position_history,None)

I_want_money.get_position_history(instrument_type)

get_available_leverages

get available leverages

return (True/False,available_leverages,None)

I_want_money.get_available_leverages(instrument_type,actives)

cancel_order

you will do this

return (True/False)

I_want_money.cancel_order(buy_order_id)

close_position

you will do this

return (True/False)

I_want_money.close_position(buy_order_id)

get_overnight_fee

return (True/False,overnight_fee,None)

I_want_money.get_overnight_fee(instrument_type,active)


Candle

get candles

get_candles can not get "real time data" ,it will late about 30sec

if you very care about real time you need use

"get realtime candles" OR "collect realtime candles"

sample

""now"" time 1:30:45sec

  1. you want to get candles 1:30:45sec now

    you may get 1:30:15sec data have been late approximately 30sec

  2. you want to get candles 1:00:33sec

    you will get the right data

I_want_money.get_candles(ACTIVES,interval,count,endtime)
            #ACTIVES:sample input "EURUSD" OR "EURGBP".... youcan
            #interval:duration of candles
            #count:how many candles you want to get from now to past
            #endtime:get candles from past to "endtime"

❗ try this code to get more than 1000 candle

from iqoptionapi.stable_api import IQ_Option
import time
I_want_money=IQ_Option("email","password")
end_from_time=time.time()
ANS=[]
for i in range(70):
    data=I_want_money.get_candles("EURUSD", 60, 1000, end_from_time)
    ANS =data+ANS
    end_from_time=int(data[0]["from"])-1
print(ANS)

get realtime candles

Sample
from iqoptionapi.stable_api import IQ_Option
import logging
import time
#logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
print("login...")
I_want_money=IQ_Option("email","password")
goal="EURUSD"
size="all"#size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
maxdict=10
print("start stream...")
I_want_money.start_candles_stream(goal,size,maxdict)
#DO something
print("Do something...")
time.sleep(10)

print("print candles")
cc=I_want_money.get_realtime_candles(goal,size)
for k in cc:
    print(goal,"size",k,cc[k])
print("stop candle")
I_want_money.stop_candles_stream(goal,size)
start_candles_stream
  • input:
    • goal:"EURUSD"...
    • size:[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
    • maxdict:set max buffer you want to save

size

get_realtime_candles
  • input:
    • goal:"EURUSD"...
    • size:[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
  • output:
    • dict
stop_candles_stream
  • input:
    • goal:"EURUSD"...
    • size:[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]

time

the get_server_timestamp time is sync with iqoption

I_want_money.get_server_timestamp()

this sample get the Purchase time clock

import time

#get the end of the timestamp by expiration time
def get_expiration_time(t):
    exp=time.time()#or I_want_money.get_server_timestamp() to get more Precision
    if (exp % 60) > 30:
        end = exp - (exp % 60) + 60*(t+1)
    else:
        end = exp - (exp % 60)+60*(t)
    return end
    
expiration_time=2

end_time=0
while True:
    if end_time-time.time()-30<=0:
        end_time = get_expiration_time(expiration_time)
    print(end_time-time.time()-30)
    time.sleep(1)

Get mood

Sample

from iqoptionapi.stable_api import IQ_Option
I_want_money=IQ_Option("email","password")
goal="EURUSD"
I_want_money.start_mood_stream(goal)
print(I_want_money.get_traders_mood(goal))
I_want_money.stop_mood_stream(goal)

get_traders_mood

get percent of higher(call)

if you want to know percent of lower(put) just 1-higher

I_want_money.get_traders_mood(goal)
#input:input "EURUSD" OR "EURGBP".... you can view by get_all_ACTIVES_OPCODE
#output:(float) the higher(call)%
#if you want to know lower(put)% try 1-I_want_money.get_traders_mood(goal)

get_all_traders_mood

get all you start mood

I_want_money.get_all_traders_mood(goal)
#output:(dict) all mood you start

Account

get balance

I_want_money.get_balance()

Change real/practice Account

I_want_money.change_balance(MODE)
                        #MODE: "PRACTICE"/"REAL"

iqoptionapi's People

Contributors

freenetwork avatar gobbluth avatar jacekv avatar lu-yi-hsun avatar n1nj4z33 avatar perryawesome avatar tejado avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.