Lu-Yi-Hsun / iqoptionapi

IQ Option API
372 stars 289 forks source link

Get option open by "Demo Account" and Buy on "Real Account" #311

Open donfauto opened 3 years ago

donfauto commented 3 years ago

I am trying to capture incoming trades from the Demo Account and execute that same trade in the Real Account.

This is what I have:

import time
from iqoptionapi.stable_api import IQ_Option
from datetime import timedelta
import datetime
count = 0
Iq=IQ_Option("miaccount@gmail.com","mypassword")
Iq.connect()
Iq.change_balance("PRACTICE")
def run(count): 
    print("\nEsperando entrada...")
    bucle = True
    while bucle:
        if Iq.get_option_open_by_other_pc()!={}:
            bobo = Iq.get_option_open_by_other_pc()
            id=list(Iq.get_option_open_by_other_pc().keys())[0]
            Money=1
            ACTIVES=bobo[id]['msg']['active']
            ACTION=bobo[id]['msg']['dir']
            abrir = datetime.datetime.fromtimestamp(bobo[id]['msg']['created'])
            cerrar =datetime.datetime.fromtimestamp(bobo[id]['msg']['exp_time'])
            Iq.del_option_open_by_other_pc(id) 
            expirations_mode = cerrar - abrir
            print(cerrar)
            print(abrir)
            print(expirations_mode)
            expiration = 1
            Minute = 1.50
            Minute2 = 0.50
            try:
                for i in range(60): 
                    if expirations_mode < timedelta(minutes=Minute) and expirations_mode > timedelta(minutes=Minute2) or expirations_mode == timedelta(minutes=Minute):
                        Iq.change_balance("REAL")
                        check,id=Iq.buy(Money,ACTIVES,ACTION,expiration)
                        if check:
                            print("Señales restantes:",len(bobo))
                            print(id,Money, ACTIVES,ACTION,expiration, "---REALIZADO---") 
                            Iq.del_option_open_by_other_pc(id) 
                            count += 1
                            print("Operaciones realizadas:",count)
                            run(count)
                        else:
                            Iq.del_option_open_by_other_pc(id) 
                            print("No se pudo realizar.")
                            run(count)
                    else:
                        print("Buscando expiracion...",)
                        expiration += 1
                        Minute += 1
                        Minute2 += 1
                print("Final del bucle.")
            except Exception:
                Iq.del_option_open_by_other_pc(id) 
                print("No se pudo realizar.")

run(count)

btw, i don't feel so sure so i want to know your opinions.

itzVane commented 2 years ago

have you tried it ? did it work?