Python Forum
Create bot to automate operations in IQ Option - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Create bot to automate operations in IQ Option (/thread-28436.html)



Create bot to automate operations in IQ Option - JonatasCavalini - Jul-19-2020

Hello everyone!
I come to you in need of immense help!

I want to create a bot to automate entries in binary options at the brokerage IQ Option based on a particular strategy.

The strategy can be found here:https://br.tradingview.com/script/hCdpb2YB

This strategy is very effective, but its signals are very fast, and you need a lot of time in front of the screen to get them, in addition to needing extreme speed to get the price rate at the right time.

I don't have a lot of knowledge on the subject. What I have so far are these codes, which I got through google:

That was the beginning: https://github.com/Lu-Yi-Hsun/iqoptionapi

 from iqoptionapi.stable_api import IQ_Option
import time, json, logging, configparser
from datetime import datetime, date, timedelta
from dateutil import tz
import sys

logging.disable(level=(logging.DEBUG))

API = IQ_Option('login', 'senha')
API.connect()

API.change_balance('PRACTICE') # PRACTICE / REAL

while True:
	if API.check_connect() == False:
		print('Erro ao se conectar')
		
		API.connect()
	else:
		print('\n\nConectado com sucesso')
		break
	
	time.sleep(1)

def perfil():
	perfil = json.loads(json.dumps(API.get_profile_ansyc()))
	
	return perfil
	
	'''
		name
		first_name
		last_name
		email
		city
		nickname
		currency
		currency_char 
		address
		created
		postal_index
		gender
		birthdate
		balance		
	'''

def timestamp_converter(x, retorno = 1):
	hora = datetime.strptime(datetime.utcfromtimestamp(x).strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
	hora = hora.replace(tzinfo=tz.gettz('GMT'))
	
	return str(hora.astimezone(tz.gettz('America/Sao Paulo')))[:-6] if retorno == 1 else hora.astimezone(tz.gettz('America/Sao Paulo'))

def banca():
	return API.get_balance()

def payout(par, tipo, timeframe = 1):
	if tipo == 'turbo':
		a = API.get_all_profit()
		return int(100 * a[par]['turbo'])
		
	elif tipo == 'digital':
	
		API.subscribe_strike_list(par, timeframe)
		while True:
			d = API.get_digital_current_profit(par, timeframe)
			if d != False:
				d = int(d)
				break
			time.sleep(1)
		API.unsubscribe_strike_list(par, timeframe)
		return d

def configuracao():
	arquivo = configparser.RawConfigParser()
	arquivo.read('config.txt')	
		
	return {'seguir_ids': arquivo.get('GERAL', 'seguir_ids'),'stop_win': arquivo.get('GERAL', 'stop_win'), 'stop_loss': arquivo.get('GERAL', 'stop_loss'), 'payout': 0, 'banca_inicial': banca(), 'filtro_diferenca_sinal': arquivo.get('GERAL', 'filtro_diferenca_sinal'), 'martingale': arquivo.get('GERAL', 'martingale'), 'sorosgale': arquivo.get('GERAL', 'sorosgale'), 'niveis': arquivo.get('GERAL', 'niveis'), 'filtro_pais': arquivo.get('GERAL', 'filtro_pais'), 'filtro_top_traders': arquivo.get('GERAL', 'filtro_top_traders'), 'valor_minimo': arquivo.get('GERAL', 'valor_minimo'), 'paridade': arquivo.get('GERAL', 'paridade'), 'valor_entrada': arquivo.get('GERAL', 'valor_entrada'), 'timeframe': arquivo.get('GERAL', 'timeframe')}

def entradas(config, entrada, direcao, timeframe):
	status,id = API.buy_digital_spot(config['paridade'], entrada, direcao, timeframe)

	if status:
		# STOP WIN/STOP LOSS
		banca_att = banca()
		stop_loss = False
		stop_win = False

		if round((banca_att - float(config['banca_inicial'])), 2) <= (abs(float(config['stop_loss'])) * -1.0):
			stop_loss = True
			
		if round((banca_att - float(config['banca_inicial'])) + (float(entrada) * float(config['payout'])) + float(entrada), 2) >= abs(float(config['stop_win'])):
			stop_win = True
		
		while True:
			status,lucro = API.check_win_digital_v2(id)
			
			if status:
				if lucro > 0:		
					return 'win',round(lucro, 2),stop_win
				else:				
					return 'loss',0,stop_loss
				break
		
		
	else:
		return 'error',0,False

def sorosgale (perca):
	lucro_total = 0
	nivel = 2   
	mao = 1
	lucro = 0
	print ('\ n Perca total:', perca, '- entrada inicial:', (perca / 2))

	enquanto True:
		
		resultado, lucro = entradas ('EURUSD', (perca / 2) + lucro, 'put', 1)
		
		se resultado == 'ganhar':
			lucro_total + = lucro
			print ('\ n', nivel, '-', mao, '|', resultado, '- lucro:', lucro, '- perder:', perder)
			mao + = 1
		outro:
			lucro_total = 0
			mao = 1
			perder + = perder / 2
			print ('\ n', nivel, '-', mao, '|', resultado, '- lucro:', lucro, '- perder:', perder)
			nĂ­vel + = 1
			
		
		se lucro_total> = perca:
			print ('FIM \ n', nivel, '-', mao, '|', perca, '->', lucro_total)
			pausa
		outro:
			print ('perca atual:', perca, 'lucro:', lucro)[python][python]
Archives: https://drive.google.com/drive/folders/1QoenNg8enx8XYRpPrI7fudygYvD9i5-S?usp=sharing

WHAT I NEED:

I want to automate the inputs using two indicators, Bollinger band (period 20 and deviation 2.5) and exponential moving average (period 100).

The rules would be these:
When the candle touches one of the lines of the bollinger band, the bot will enter in the opposite direction (CALL or PUTT) always in the direction of the trend. Example: price above the moving average and candle touches the bottom line Bollinger Band, CALL, expiring for the same candle.
-If you win the first, add the profit plus the fixed value entry to make the second entry. Afterwards, make the next entry with the fixed value again, that is, use level 2 sorogale.
-If you lose, do not martingale.

Rules for not making the operation:
-Do not perform the operation in the opposite direction of the trend, that is, price above the moving average and the candle touches the upper line of the Bollinger band, do not perform the operation, and vice versa.
-Do not perform the operation if the candle crosses the trend line and then touches the line of the Bollinger band.
-if the candle has an expiration less than or equal to 1m29s and touch the line of the Bollinger band, do not perform the operation.

I need to get these signals to arrive at IQ Option and I thought of 3 ways: receiving these signals from MT4, receiving these signals from tradingview.com itself or receiving from the IQ Option itself. From IQ Option I was able to receive data from the moving average, but I was unable to receive data from Bollinger bands.

I want to learn how to create these codes! Please give me directions on how to proceed. If you know something relevant that would make it easier, share it too. I would like to keep this code open after completion for everyone to use!

Thanks for your attention! Big Grin

[Image: 4SG1nby]