iq option api ที่ยังคงใช้งานได้ปัจจุบันแนะนำมี3ที่
เจ้าที่1
https://github.com/Lu-Yi-Hsun/iqoptionapi
เจ้าที่2
https://github.com/iqoptionapi/iqoptionapi
เจ้าที่3
https://github.com/deibsoncarvalho/py-iqoption-api
1.แตกไฟล์ ZIP แล้วเข้าไปในโฟล์เดอร์ที่เก็บไฟล์ไว้ เมื่อเข้าไปแล้วอย่าเพิ่งใช้เมาท์กดที่ไฟล์ใดๆ
2.ลากเมาท์ไปวางไว้วางไว้พื้นที่ว่างทางขวาของหน้าต่างโฟลเดอร์
3.กด Shift ที่แป้นคีย์บอร์ดค้างไว้ แล้วกดเม้าท์คลิกขวา1ครั้ง
4.เลือกที่ เปิดหน้าต่าง PowerShell แล้วก็อปปี้คำสั่งด้านล่างไปวาง แล้วกด Enter
หมายเหตุ : ถ้าใครมีเวอร์ชั่นเก่าควรถอนการตืดตั้งเสียก่อน หรือตวจสอบว่ามีหรือไม่โดยพิมพ์คำสั่งที่ PowerSell คำสั่งเช็คแพคเกจที่ติดตั้งไว้ในเครื่อง pip list ถ้ามีของเก่าอยากถอนการติดตั้งก็ใช้คำสั่ง pip uninstall ชื่อแพคเกจ
python setup.py install
การนำเข้าคำสั่งของ API
from iqoptionapi.stable_api import IQ_Option
โหมดตรวจสอบข้อบกพร่อง
import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
การเชื่อมต่อ และ การตรวจสอบสถานะการเชื่อมต่อ
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."}"""
Iq = IQ_Option("email", "password")
check,reason=Iq.connect()
if check:
print("Start your robot")
while True:
if Iq.check_connect()==False:
print("try reconnect")
check,reason=Iq.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")
ตรวจสอบเวอร์ชั่น API
from iqoptionapi.stable_api import IQ_Option
print(IQ_Option.__version__)
ตรวจสอบสถานะในการเชื่อมต่อ
print(Iq.check_connect())
คำสั่งขอเชื่อมต่อ และ เชื่อมต่อใหม่อีกครั้ง
Iq.connect()
การร้องขอข้อมูลเวลาของทางฝั่งเซิฟเวอร์
Iq.get_server_timestamp()
แสดงยอดเงินในบัญชี
Iq.get_balance()
แสดงชนิดของสกุลเงินในบัญชี
Iq.get_currency()
รีเซ็ตยอดเงินในบัญชี
ทำได้เฉพาะบัญชีฝึกหัดเท่านั้น จำนวน$10000
from iqoptionapi.stable_api import IQ_Option
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
print(Iq.reset_practice_balance())
เปลี่ยนชนิดบัญชี จริง/ฝึกหัด
MODE=PRACTICE/REAL
PRACTICE - บัญชีฝึกหัด
REAL - บัญชีจริง
balance_type="PRACTICE" #"PRACTICE"/"REAL"
Iq.change_balance(balance_type)
คำสั่งซื้อ/ขาย
Iq.buy(Money,Currency,Action,expirations)
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
import logging
import time
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
Iq=IQ_Option("email","pass")
Money=1
Currency="EURUSD"
Action="call"#or "put"
Goal="EURUSD"
expirations_mode=1
print("Get Candel")
print(Iq.get_candles(Goal,60,111,time.time()))
check,id=Iq.buy(Money,Currency,Action,expirations_mode)
if check:
print("!buy!")
else:
print("buy fail")
คำสั่งซื้อพร้อมกันหลายคู่สกุลเงิน
buy_multi()
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Money=[]
Currency=[]
Action=[]
expirations_mode=[]
Money.append(1)
Currency.append("EURUSD")
Action.append("call")#put
expirations_mode.append(1)
Money.append(1)
Currency.append("EURAUD")
Action.append("call")#put
expirations_mode.append(1)
print("buy multi")
id_list=Iq.buy_multi(Money,Currency,Action,expirations_mode)
print("check win only one id (id_list[0])")
print(Iq.check_win_v2(id_list[0],2))
การซื้อขายก่อนหมดเวลาที่กำหนด
get_remaning()
เป็นการซื้อขายก่อนจะถึง 30 วินาทีสุดท้าย
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Money=1
Currency="EURUSD"
Action="call"#or "put"
expirations_mode=1
while True:
remaning_time=Iq.get_remaning(expirations_mode)
purchase_time=remaning_time-30
if purchase_time4:#buy the binary option at purchase_time4
Iq.buy(Money,Currency,Action,expirations_mode)
break
การขายออเดอร์หรือยกเลิกก่อนถึงกำหนดเวลา
Iq.sell_option(sell_all)#input int or list order id
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
import time
print("login...")
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Money=1
Currency="EURUSD"
Action="call"#or "put"
expirations_mode=1
id=Iq.buy(Money,Currency,Action,expirations_mode)
id2=Iq.buy(Money,Currency,Action,expirations_mode)
time.sleep(5)
sell_all=[]
sell_all.append(id)
sell_all.append(id2)
print(Iq.sell_option(sell_all))
เช็คผลการซื้อขายและรายงานผลสถานะเมื่อจบออเดอร์(ไบนารี่)
check_win_v3()
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Money=1
Currency="EURUSD"
Action="call"#or "put"
expirations_mode=1
check,id = Iq.buy(Money, Currency, Action, expirations_mode)
print("start check win please wait")
if id !="error":
while True:
check,win=IQcon.check_win_v3(id)
if check:
break
if win==0:
print('Nothing : ',str(win)+' $')
elif win<0:
print('You Loss : ',str('%.2f'%win)+' $')
else:
print('You Win : ',str('%.2f'%win)+' $')
else:
print("please try again")
คำสั่งซื้อ/ขาย
buy_digital_spot
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Currency="EURUSD"
Duration=1#minute 1 or 5
Money=1
Action="call"#put
print(Iq.buy_digital_spot(Currency,Money,Action,Duration))
เช็คผลการซื้อขายและรายงานผลสถานะเมื่อจบออเดอร์(ดิจิตอล)
Iq.check_win_digital_v2(id)
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
import logging
import random
import time
import datetime
#logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
Currency="EURUSD"
Duration=1#minute 1 or 5
Money=1
Action="call"# or "put"
_,id=(Iq.buy_digital_spot(Currency,Money,Action,Duration))
print(id)
if id !="error":
while True:
check,win=Iq.check_win_digital_v2(id)
if check==True:
break
if win==0:
print('Nothing : ',str(win)+' $')
elif win<0:
print('You Loss : ',str('%.2f'%win)+' $')
else:
print('You Win : ',str('%.2f'%win)+' $')
else:
print("please try again")
คำสั่งขอเริ่มใช้ข้อมูลกราฟแท่งเทียน
Iq.start_candles_stream()
โค้ดตัวอย่าง
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"] เวลาที่ต้องการจะแสดงมีค่าเป็น วินาที "all" คือทั้งหมด
maxdict=10 #จำนวนแท่งที่ต้องการข้อมูล นับจากแท่งล่าสุด
print("start stream...")
Iq.start_candles_stream(goal,size,maxdict)
คำสั่งขอดูข้อมูลแท่งเทียนแบบเรียลไทม์
Iq.get_realtime_candles()
ก่อนจะใช้คำสั่ง get_realtime_candles() ควรใช้คำสั่ง start_candles_stream() เสียก่อน
Iq.get_realtime_candles(goal,size) #goal=คู่สกุลเงิน size=ระยะเวลาที่ต้องการแสดงผล
การหยุดคำสั่งขอใช้ข้อมูลกราฟแท่งเทียน
Iq.stop_candles_stream()
มันเป็นคำสั่งปิด get_realtime_candles() หากเราไม่ได้ใช้มันอีกต่อไป
Iq.stop_candles_stream(goal,size) #goal=คู่สกุลเงิน size=ระยะเวลาที่ต้องการแสดงผล
โค้ดตัวอย่าง(แบบกำหนดรอบในการดึงข้อมูล)
from iqoptionapi.stable_api import IQ_Option
import time
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
end_from_time=time.time()
ANS=[]
for i in range(70):
data=Iq.get_candles("EURUSD", 60, 1000, end_from_time)
ANS =data+ANS
end_from_time=int(data[0]["from"])-1
print(ANS)
กราฟแท่งเทียนแบบเรียลไทม์ + อินดิเคเตอร์พื้นฐาน (เส้น EMA)
การจะใช้โค้ดด้านล่างควรตรวจสอบเครื่องของท่านก่อนว่ามีโมดูที่ชื่อว่า TA-Lib และโมดูลชื่อ numpy หรือไม่ โดยการ run cmd ใช้คำสั่ง pip list หากไม่มี
วิธีการตดตั้ง TA-Lip -- วิธีการติดตั้ง TA-Lib
ส่วน numpy ให้ run cmd แล้วพิมพ์คำสั่งนี้ได้เลย pip install numpy
from talib.abstract import *
from iqoptionapi.stable_api import IQ_Option
import time
import numpy as np
print("login...")
Iq=IQ_Option("email","password")
Iq.connect() #connect to iqoption
goal="EURUSD" # คู่สกุลเงิน
size=10 #size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
timeperiod=10 # จำนวนแท่งเทียนที่จะให้เส้น EMA ดึงค่า เหมือนกับการตั้งค่าในโปรแกรม IQ Option
maxdict=20 # จำนวนแท่งเทียนที่ต้องการข้อมูลมาใช้คำนวน ควรตั้งให้เยอะกว่า timeperiod เล็กน้อย
print("start stream...")
Iq.start_candles_stream(goal,size,maxdict)
print("Start EMA Sample")
while True:
candles=Iq.get_realtime_candles(goal,size)
can_dles=(dict(candles))
inputs = {
'open': np.array([]),
'high': np.array([]),
'low': np.array([]),
'close': np.array([]),
'volume': np.array([])
}
for timestamp in can_dles:
inputs["open"]=np.append(inputs["open"],candles[timestamp]["open"] )
inputs["high"]=np.append(inputs["open"],candles[timestamp]["max"] )
inputs["low"]=np.append(inputs["open"],candles[timestamp]["min"] )
inputs["close"]=np.append(inputs["open"],candles[timestamp]["close"] )
inputs["volume"]=np.append(inputs["open"],candles[timestamp]["volume"] )
print("Show EMA")
print(EMA(inputs, timeperiod=timeperiod))
print("
")
time.sleep(1)
Iq.stop_candles_stream(goal,size)
การใช้โค้ดแบบเรียลไทม์ในอีกรูปแบบหนึ่ง เป็นการแสดงผลสีแท่งเทียนและค่าต่างๆภายในแท่ง
โค้ดตัวอย่าง
from iqoptionapi.stable_api import IQ_Option
import logging
import time
#logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
print("login...")
Iq=IQ_Option("email","password")
Iq.connect()#connect to iqoption
goal="EURUSD"
size=60#size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
maxdict=1 # แท่งเทียนแท่งล่าสุด
print("start stream...")
Iq.start_candles_stream(goal,size,maxdict)
while True:
realtime = Iq.get_realtime_candles(goal,size)
real_time = (dict(realtime))
for i in real_time:
OpenA = realtime[i]['open']
CloseA = realtime[i]['close']
MaxA = realtime[i]['max']
MinA = realtime[i]['min']
VolumeA = realtime[i]['volume']
Type_candle = (OpenA)-(CloseA)
if Type_candle<-0.0:
print('[[[[--Green--]]]]')
print('Open = ',OpenA)
print('Close = ',CloseA)
print('Max = ',MaxA)
print('Mim = ',MinA)
print('Volume = ',VolumeA)
print('-'*30)
elif Type_candle>0.0:
print('[[[[--Red--]]]]')
print('Open = ',OpenA)
print('Close = ',CloseA)
print('Max = ',MaxA)
print('Mim = ',MinA)
print('Volume = ',VolumeA)
print('-'*30)
else:
print('Wait Candle')
time.sleep(1)
# โค้ดนี้จะแสดงแค่สีของแท่งเทียนเท่านั้น หากจะหาค่าใส้เทียนให้ใช้ max-close หรือ close-min หรือ ค่าความยาวของแท่งทั้งหมดคือ max-min ประมาณนี้
Get Start IQ Option Robot Code with python
หากโค้ดมีปัญหา หรือต้องการศึกษาพื้นฐานเพิ่มเติมยินดีให้คำปรึกษาฟรี เพื่อปูพื้นฐานในการสร้างบอทเทรด IQ Option เพียงเข้าไลน์กลุ่มเพื่อสอบถาม(เน้นภาษา Python เท่านั้น)
เขียนโค้ด และสร้างบอท IQ Option ด้วยตัวคุณเองแบบง่ายๆ