class MHI: def __init__(self, email, password): self.API = IQ_Option(email, password) self.config = configuration.getConfig() self.connection() def connection(self): self.API.connect() self.API.change_balance('PRACTICE') if self.API.check_connect(): print(' Conectado com sucesso!') else: print(' Erro ao conectar') sys.exit() def stop(self, lucro): if lucro <= float(-1 * abs(self.config['stop_loss'])): print('Stop Loss batido!') sys.exit() if lucro >= float(abs(self.config['stop_gain'])): print('Stop Gain Batido!') sys.exit() def Martingale(self, valor, payout): lucro_esperado = valor * payout perca = float(valor) while True: if round(valor * payout, 2) > round( abs(perca) + lucro_esperado, 2): return round(valor, 2) break valor += 0.01 def Payout(self, par=''): if par.strip() != '': self.API.subscribe_strike_list(par, 1) while True: d = self.API.get_digital_current_profit(par, 1) if d != False: d = round(int(d) / 100, 2) break time.sleep(1) self.API.unsubscribe_strike_list(par, 1) return d def isTime(self): minutos = float(((datetime.now()).strftime('%M.%S'))[1:]) return True if (minutos >= 4.58 and minutos <= 5) or minutos >= 9.58 else False def getColors(self): velas = self.API.get_candles(self.config['par'], 60, 3, time.time()) retorno = '' for i in range(len(velas)): if velas[i]['open'] < velas[i]['close']: retorno += 'g' elif velas[i]['open'] > velas[i]['close']: retorno += 'r' else: retorno += 'd' return retorno def getDirection(self, cores): dir = False if cores.count('g') > cores.count('r') and cores.count('d') == 0: dir = ('put' if self.config['tipo_mhi'] == 1 else 'call') if cores.count('r') > cores.count('g') and cores.count('d') == 0: dir = ('call' if self.config['tipo_mhi'] == 1 else 'put') return dir def buyParity(self, dir): if self.config['operacao'] == 1: return self.API.buy_digital_spot(self.config['par'], self.config['valor_entrada'], dir, 1) else: return self.API.buy(self.config['valor_entrada'], self.config['par'], dir, 1) def finishTrade(self, id): finish = (True, 0) if self.config['operacao'] == 1: finish = self.API.check_win_digital_v2(id) else: finish = (True, self.API.check_win_v3(id)) return finish def startTrade(self, dir, payout): lucro = 0 print('iniciando trader') self.config['valor_entrada'] = self.config['valor_entrada_b'] for i in range(self.config['martingale']): if i > 2: dir = 'put' if dir == 'call' else 'call' buy, id = self.buyParity(dir) if buy: print('Compra efetuada') while True: try: finish, valor = self.finishTrade(id) except: finish = True valor = 0 if finish: print('Operaçao Finalizada') valor = valor if valor > 0 else float( -1 * abs(self.config['valor_entrada'])) lucro += round(valor, 2) self.config['valor_entrada'] = self.Martingale( self.config['valor_entrada'], payout) self.stop(lucro) break if valor > 0: break def start(self): self.config['valor_entrada_b'] = self.config['valor_entrada'] print("Aguardando o horario.") while True: horas = self.isTime() payout = self.Payout(self.config['par']) if payout < (self.config['payout'] / 100): print(f'Payout abaixo do minimo permitido: {payout}') break if horas: cores = self.getColors() dir = self.getDirection(cores) if dir: self.startTrade(dir, payout) time.sleep(0.5)
class Gale: def __init__(self, user, password, valor, tempo, conta): self.API = IQ_Option(user, password) self.id_compra = '' self.loss = 0 self.win = 0 self.value = valor self.entrada = 'put' self.time = tempo self.account = conta self.pares = [ 'EURUSD-OTC', 'AUDCAD-OTC', 'NZDUSD-OTC', 'USDCHF-OTC', 'GBPUSD-OTC', 'EURJPY-OTC' ] self.par = self.pares[self.RandomNumber()] # Conectando na conta. Retorna se foi feito com sucesso ou não def Connection(self): self.API.connect() if self.API.connect(): self.Account() return print('Successfully connected :D') else: return print('Conection Error D:') # Retorna tipo de conta, se é real ou de pratica def Account(self): return self.API.change_balance(self.account) # Gerando um número random def RandomNumber(self): numberRandom = randint(0, len(self.pares) - 1) return numberRandom # Recebe valor, entrada, tempo def Compra(self): print('Make a buy...') compra_status, self.id_compra = self.API.buy_digital_spot( self.par, self.value, self.entrada, self.time) if compra_status == False: print('Buy Again') self.par = self.pares[self.RandomNumber()] self.Compra() else: print('waiting for the result of the order...') check, result = self.API.check_win_digital_v2(self.id_compra) if result > 0: self.winResult() else: self.lossResult() # Retorna se bateu a meta ou não def winResult(self): self.win += 1 self.loss = 0 if self.win == 10: return print("Meta batida ;D") self.par = self.pares[self.RandomNumber()] self.Compra() # Faz o gale e ainda entra novamente até acertar ou falhar def lossResult(self): self.loss += 1 if self.loss == 3: return print("Hit :/") else: newValue = self.galeValue() compra_status, self.id_compra = self.API.buy_digital_spot( self.par, newValue, self.entrada, self.time) check, newResult = self.API.check_win_digital_v2(self.id_compra) if newResult < 0: self.lossResult() else: newValue = self.value self.winResult() # Retorna o novo valor, fazendo o Maringale def galeValue(self): newValue = self.value newValue = (newValue * 1.15) * 2 return newValue # Verificar e retorna o valor do resultado da operação def resultVerification(self, id): self.API.check_win_digital_v2(self.id_compra) return self.API.check_win_v3(self.id_compra)
contador]: #Espera até o horario ser correto time.sleep(0.100) a = dados.check_connect() #Checa a conexão if a == False: #Caso a conexão seja perdida ele tenta a reconexão dados.connect #Tenta a reconexão print( 'A conexão foi perdida ! Tomando medidas cabiveis') else: #Caso a conexão seja True a entrada será efetuada! id, status = dados.buy( entrada[contador], par[contador], direcao[contador], timeframe[contador]) #Efetua a entrada print(contador + 1, 'º - ', 'Entrada efetuada -', par[contador], 'R$', entrada[contador], '!') #Informa que a entrada foi efetuada if status: res1, lucro1 = dados.check_win_v3( status) #Checa o resultado da operação if lucro1 > 0: print('Win R$ +', ((int(entrada[contador]) * payout) / 100)) contador = contador + 1 print('\n') pass else: print('Loss R$ -', int(entrada[contador])) print('\n') contador = contador + 1 pass if status == False: contador = contador + 1 pass else:
operar = PossoOperar( ) #Verificando se ainda esta dentro das regras da estrategia MHI... if operar == False: #Verifico se existe ou não uma sequencia de velas iguais PausarMg() status, id = API.buy_digital_spot( par, valor_entrada, dir, 1) if operacao == 1 else API.buy( valor_entrada, par, dir, 1) if status: while True: try: status, valor = API.check_win_digital_v2( id ) if operacao == 1 else True, API.check_win_v3(id) except: status = True valor = 0 if status: valor = valor if valor > 0 else float( '-' + str(abs(valor_entrada))) lucro += round(valor, 2) print('Resultado operação: ', end='') print('WIN /' if valor > 0 else 'LOSS /', round(valor, 2), '/', round(lucro, 2), ('/ ' + str(i) + ' GALE' if i > 0 else '')) valor_entrada = Martingale(valor_entrada)
if dir: print('Direção:', dir) valor_entrada = valor_entrada_b for i in range(martingale): status, id = API.buy_digital_spot( par, valor_entrada, dir, 1) if operacao == 1 else API.buy( valor_entrada, par, dir, 1) if status: while True: try: status, valor = API.check_win_digital_v2( id) if operacao == 1 else API.check_win_v3(id) except: status = True valor = 0 if status: valor = valor if valor > 0 else float( '-' + str(abs(valor_entrada))) lucro += round(valor, 2) print('Resultado operação: ') print('WIN /' if valor > 0 else 'LOSS /', round(valor, 2), '/', round(lucro, 2), ('/ ' + str(i) + ' GALE' if i > 0 else '')) # valor_entrada = Martingale(valor_entrada, payout)
class Gale: def __init__(self, user, password, valor, tempo, conta): self.API = IQ_Option(user, password) self.id_compra = '' self.loss = 0 self.galeloss = 0 self.win = 0 self.value = valor self.gale = valor self.entrada = 'put' self.time = tempo self.account = conta self.pares = ['NZDUSD-OTC', 'AUDCAD-OTC', 'EURJPY-OTC'] self.par = self.pares[self.RandomNumber()] # Conectando na conta. Retorna se foi feito com sucesso ou não def Connection(self): self.API.connect() self.Account() if self.API.connect(): return print('Successfully connected :D') else: return print('Conection Error D:') # Retorna tipo de conta, se é real ou de pratica def Account(self): return self.API.change_balance(self.account) # Gerando um número random def RandomNumber(self): numberRandom = randint(0, len(self.pares) - 1) return numberRandom # Recebe valor, entrada, tempo def Compra(self): print('Make a buy...') compra_status, self.id_compra = self.API.buy(self.value, self.par, self.entrada, self.time) if compra_status == False: print('Buy Again') self.par = self.pares[self.RandomNumber()] self.Compra() else: print('waiting for the result of the order...') result = self.resultVerification(self.id_compra) if result > 0: self.winResult() elif result == 0: self.Compra() else: self.lossResult() # Retorna se bateu a meta def winResult(self): self.win += 1 self.galeloss = 0 self.gale = self.value self.loss = 0 if self.win == 100: return print("Goal hit ;D") self.par = self.pares[self.RandomNumber()] self.Compra() # Retorna se deu loss ou hit def lossResult(self): self.loss += 1 if self.loss == 3: print("Hit :/") return self.Compra() else: newValue = self.galeValue(self.gale) compra_status, self.id_compra = self.API.buy( newValue, self.par, self.entrada, self.time) newResult = self.resultVerification(self.id_compra) if newResult < 0: self.lossResult() elif newResult == 0: self.API.buy(newValue, self.par, self.entrada, self.time) else: newValue = self.value self.winResult() # Retorna o novo valor, fazendo o Maringale def galeValue(self, galeValue): self.galeloss += 1 if self.galeloss == 1: galeValue = galeValue * 3 elif self.galeloss == 2: galeValue = galeValue * 5 self.gale = galeValue return galeValue # Verificar e retorna o valor do resultado da operação def resultVerification(self, id): return self.API.check_win_v3(self.id_compra)
print(API.get_balance()) par = 'EURUSD' vela = API.get_candles(par, 60, 1, time.time()) print(vela) print(timestamp_converter(vela[0]['from'])) #historico velas '''total = [] tempo = time.time() for i in range(2): X = API.get_candles(par,60,1000,tempo) total=X+total tempo = int(X[0]['from'])-1 for velas in total: print(timestamp_converter(velas['from']))''' #tempo real par = 'EURUSD' entrada = 2 direcao = 'call' timeframe = 1 status, id = API.buy(entrada, par, direcao, timeframe) if status: print(API.check_win_v3(id))
# Compra compra_status, id = API.buy(valor, par, entrada, tempo) print("Status da compra: ", compra_status, id) while compra_status == False: numberRandom = randint(0, 5) par = pares[numberRandom] compra_status, id = API.buy(valor, par, entrada, tempo) if compra_status == True: print("O par que esta sendo comprado: ", par) print("Status da compra: ", compra_status, id) break print("Aguardando resultado...") result = API.check_win_v3(id) if result > 0: acerto += 1 numberRandom = randint(0, 5) par = pares[numberRandom] valor = investimento acertividade = (100 * acerto) / (acerto + erroCont) erro = 0 elif result == 0: doji += 0 elif result < 0: valor = (valor * 1.15) * 2 erro += 1 if erro > gale: