Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

python - Meu código de plataforma de negociação sempre obtém o erro "TypeError: não pode desempacotar objeto int não iterável"

My code takes information from a .txt file (13: 55, EURUSD, CALL) and performs operations on a trade platform.

I'm having problems with the title error message.

from iqoptionapi.stable_api import IQ_Option
from datetime import datetime
from time import sleep, time
import sys

def stop(lucro, gain, loss):
    if lucro <= (abs(loss) * -1):
        print('
 Stop loss batido!')
        sys.exit()
        
    if lucro >= float(abs(gain)):
        print('
 Stop Gain batido!')
        sys.exit()

def Martingale(valor, payout): # 70% -> 0.7 / 87% -> 0.87
    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(par, timeframe = 1):
    API.subscribe_strike_list(par, timeframe)
    while True:
        d = API.get_digital_current_profit(par, timeframe)
        if d != False:
            d = round(int(d) / 100, 2)
            break
        sleep(1)
    API.unsubscribe_strike_list(par, timeframe)
    
    return d


API = IQ_Option('youremail23@gmail.com', 'xxxxx')
API.connect()

if API.check_connect():
    print(' Conectado com sucesso!')
else:
    print(' Erro ao conectar')
    input('

 Aperte enter para sair')
    sys.exit()


print(' Arquivo de sinais: ', end='')
file = input().strip()
sinais = open(file, 'r').read()

print('
 Qual o valor de entrada?: ', end='')
entrada = float(input())
entrada_b = float(entrada)

print('
 Qual o valor de Stop Loss?: ', end='')
stop_loss = float(input())
 
print('
 Qual o valor do Stop Gain?: ', end='')
stop_gain = float(input())

print('
 Quantos MARTINGALES deseja realizar?: ', end='')
mg_quantia = int(input())

print('
 Quantos SEGUNDOS de delay na m?o fixa?: ', end='')
delay = int(input())



timeframe = 1
sinais = sinais.split('
')
mg = 0
lucro = 0


for dados in sorted(sinais):
    
    if dados.strip() != '':
        dados = dados.split(',')
        # dados[0] HORA, dados[1] PARIDADE, dados[2] DIRE??O
        
        timestamp_sinal = int(datetime.timestamp(datetime.strptime((datetime.now()).strftime('%Y-%m-%d ') + dados[0].strip() + ':00', '%Y-%m-%d %H:%M:%S')))

        timeframe = dados[3]
        agora = datetime.now()
        data_atual = agora.strftime('%d/%m/%Y')
        hora_atual = agora.strftime('%H:%M')
        tempo_grafico = timeframe
        if timestamp_sinal > int(time()):
            while True:
                
                if int(time()) >= (timestamp_sinal - delay):
                    entrada = entrada_b
                    show = True


                    print('
 Entrando na Opera??o
 PARIDADE: ' + dados[1].upper() + '
 DIRE??O: ' + dados[2].upper() + '
 HORARIO: ' + str(hora_atual) )
                    
                    while mg <= mg_quantia:
                        status,id = API.buy_digital_spot(str(dados[1].upper()), float(entrada), str(dados[2].lower()), int(dados[3]))
                        payout_ = Payout(dados[1].upper(), dados[3])
                        if show : print(str(round(payout_ * 100)) + '%')
                        show = False
                        
                        while True:
                            status,valor = API.check_win_digital_v2(id)
                            
                            if status:
                                valor = valor if valor > 0 else (abs(entrada) * -1)
                                lucro += round(valor, 2)
                                
                                print('  Resultado opera??o: ', end='')
                                if valor > 0:
                                    print('WIN! +' + str(valor) + ('' if mg == 0 else ' ' + str(mg) + 'o MARTINGALE') + ' / LUCRO GERAL: ' + str(lucro))
                                    mg = mg + 10
                                else:
                                    print('LOSS! ' + str(valor) + ('' if mg == 0 else ' ' + str(mg) + 'o MARTINGALE') + ' / LUCRO GERAL: ' + str(lucro))
                                    entrada = Martingale(entrada, payout_)
                                    mg += 1
                                
                                if mg > mg_quantia : entrada = entrada_b
                                stop(lucro, stop_gain, stop_loss)
                                break
                            else:
                                sleep(0.3)
                else:
                    sleep(1)
                
                

        else:
            print('PASSOU DO HORARIO! ', dados[0], dados[1], dados[2])
            print('' * 30)

I put some print to try understand the error and the type of information is output...

Entrando na Opera??o
 PARIDADE: EURUSD
 DIRE??O: CALL
 HORARIO: 11:37
##############################
EURUSD
<class 'str'>
300.0
<class 'float'>
call
<class 'str'>
1
<class 'str'>
1
<class 'str'>
##############################

The source of 'buy_digital_spot :

def buy_digital_spot(self, active,amount, action, duration):
    #Expiration time need to be formatted like this: YYYYMMDDHHII
    #And need to be on GMT time
   
    #Type - P or C
    if action == 'put':
        action = 'P'
    elif action=='call':
        action = 'C'
    else:
        logging.error('buy_digital_spot active error')
        return -1
    #doEURUSD201907191250PT5MPSPT
    timestamp=int(self.api.timesync.server_timestamp)
    if duration==1:
        exp,_=get_expiration_time(timestamp,duration) 
    else:
        now_date = datetime.fromtimestamp(timestamp)+timedelta(minutes=1,seconds=30)
        while True:
            if now_date.minute%duration==0 and time.mktime(now_date.timetuple())-timestamp>30:
                break
            now_date = now_date+timedelta(minutes=1)
        exp=time.mktime(now_date.timetuple())
   
    dateFormated = str(datetime.utcfromtimestamp(exp).strftime("%Y%m%d%H%M"))
    instrument_id = "do" + active + dateFormated + "PT" + str(duration) + "M" + action + "SPT" 
    self.api.digital_option_placed_id=None
     
    self.api.place_digital_option(instrument_id,amount)
    while self.api.digital_option_placed_id==None:
        pass

    return  self.api.digital_option_placed_id

The error back is always this:

Traceback (most recent call last):
  File "D:Nova pastaNova pastaiqoptionapieste01.py", line 113, in <module>
    status,id = API.buy_digital_spot(str(dados[1].upper()), float(entrada), str(dados[2].lower()), int(dados[3]))
TypeError: cannot unpack non-iterable int object

The error above i fix like this:

re = identificacao = API.buy_digital_spot(dados[1].upper(), float(entrada), dados[2].lower(), int(timeframe))

But now i have a"Eternal Loop" that begins in this part:

                if int(time()) >= (timestamp_sinal - delay):
                entrada = entrada_b

                print('
 Entrando na Opera??o
 PARIDADE: ' + dados[1].upper() + '
 DIRE??O: ' + dados[2].upper() + '
 HORARIO: ' + str(hora_atual) + '
 PAYOUT ATUAL: ', end='')
                while mg <= mg_quantia:
                    re = identificacao = API.buy_digital_spot(dados[1].upper(), float(entrada), dados[2].lower(), int(timeframe))
                    payout_ = Payout(dados[1].upper(), timeframe)
                    print(str(round(payout_ * 100) ) + '%')
                    print(re)
question from:https://stackoverflow.com/questions/65895708/meu-c%c3%b3digo-de-plataforma-de-negocia%c3%a7%c3%a3o-sempre-obt%c3%a9m-o-erro-typeerror-n%c3%a3o-pode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...