def test_binary_option(self):
     iq_api = IQOption(email, password)
     iq_api.connect()
     iq_api.change_balance("PRACTICE")
     self.assertEqual(iq_api.check_connect(), True)
     all_assets = iq_api.get_all_open_time()
     type_active = "turbo"
     actives = []
     threads = []
     count = 0
     for active in all_assets[type_active]:
         if count == number_of_symbols:
             break
         if all_assets[type_active][active]["open"]:
             actives.append(active)
         count += 1
     for active in actives:
         th = threading.Thread(name=active,
                               target=self.process_deals,
                               args=(iq_api, active),
                               daemon=True)
         threads.append(th)
     for thread in threads:
         thread.start()
         time.sleep(.2)
     for thread in threads:
         thread.join()
     iq_api.close_connect()
示例#2
0
    def test_login(self):
        iq_api = IQOption(email, password)
        check, reason = iq_api.connect()
        self.assertTrue(check)
        self.assertIsNone(reason)
        print(
            "________________________ CONNECTED ________________________________________"
        )
        self.assertTrue(iq_api.check_connect())

        print(
            "________________________ CHANGE REAL BALANCE  ________________________________________"
        )
        res = iq_api.change_balance("REAL")
        self.assertTrue(res)
        time.sleep(3)

        print(
            "________________________ CHANGE PRACTICE BALANCE  ________________________________________"
        )
        res = iq_api.change_balance("PRACTICE")
        self.assertTrue(res)

        print(
            "________________________ RESET PRACTICE BALANCE  ________________________________________"
        )
        iq_api.reset_practice_balance()

        print(
            "________________________ CLOSE CONNECTION  ________________________________________"
        )
        iq_api.close_connect()
    def test_digital_option(self):
        iq_api = IQOption(email, password)
        iq_api.connect()
        iq_api.change_balance("PRACTICE")
        self.assertEqual(iq_api.check_connect(), True)

        time.sleep(5)

        all_assets = iq_api.get_all_open_time()
        if all_assets["digital"]["EURUSD"]["open"]:
            active = "EURUSD"
        else:
            active = "EURUSD-OTC"
        print("_____________subscribe_live_deal digital_______________")

        time.sleep(5)

        iq_api.subscribe_live_deal_digital(active)
        start_t = time.time()
        while True:
            entrances = iq_api.get_live_deal_digital(active)
            if time.time() - start_t > 60:
                raise TimeoutError
            if entrances:
                print("__For_digital_option__ data size: " +
                      str(len(entrances)))
                for entrance in entrances:
                    print(entrance)
                break
        print("_____________unsubscribe_live_deal digital_______________")

        time.sleep(5)

        iq_api.subscribe_live_deal_digital(active)
        iq_api.close_connect()
示例#4
0
 def test_traders_details(self):
     iq_api = IQOption(email, password)
     iq_api.connect()
     self.assertEqual(iq_api.check_connect(), True)
     iq_api.change_balance("PRACTICE")
     all_assets = iq_api.get_all_open_time()
     if all_assets["digital"]["EURUSD"]["open"]:
         active = "EURUSD"
     else:
         active = "EURUSD-OTC"
     print("_____________subscribe_live_deal digital_______________")
     time.sleep(3)
     iq_api.subscribe_live_deal_digital(active)
     start_t = time.time()
     start = True
     limit = 30
     count = 0
     time.sleep(3)
     while count < limit:
         entrances = iq_api.get_live_deal_digital(active)
         if entrances:
             for entrance in entrances:
                 print("_______ DEAL _______")
                 print(entrance)
                 user_id = entrance["user_id"]
                 country_id = entrance["country_id"]
                 print("_______get_user_profile_client__________")
                 pro_data = iq_api.get_user_profile_client(user_id)
                 print(pro_data)
                 time.sleep(3)
                 print(
                     "___________request_leaderboard_userinfo_deals_client______"
                 )
                 user_data = iq_api.request_leaderboard_userinfo_deals_client(
                     user_id, country_id)
                 print(user_data)
                 worldwide = user_data["result"]["entries_by_country"]["0"][
                     "position"]
                 profit = user_data["result"]["entries_by_country"]["0"][
                     "score"]
                 print("\n")
                 print("user_name:" + pro_data["user_name"])
                 print("This week worldwide:" + str(worldwide))
                 print("This week's gross profit:" + str(profit))
                 print("\n\n")
                 time.sleep(3)
                 print("___________get_users_availability____________")
                 print(iq_api.get_users_availability(user_id))
                 print("\n\n")
                 count += 1
                 time.sleep(3)
             time.sleep(3)
     print("_____________unsubscribe_live_deal digital_______________")
     iq_api.subscribe_live_deal_digital(active)
     time.sleep(3)
     iq_api.close_connect()
 def test_instruments_option(self):
     iq_api = IQOption(email, password)
     iq_api.connect()
     self.assertEqual(iq_api.check_connect(), True)
     iq_api.change_balance("PRACTICE")
     all_assets = iq_api.get_all_open_time()
     print('all assets -> {}'.format(all_assets))
     self.assertIsNotNone(all_assets)
     iq_api.update_actives()
     time.sleep(1)
     response = iq_api.get_actives_by_profit()
     self.assertIsNotNone(response)
     print(response)
     iq_api.close_connect()
示例#6
0
def connect():
    init(autoreset=True)
    #LOGIN
    logging.basicConfig(format='%(asctime)s %(message)s')
    global api
    api = IQOption("*****@*****.**", "pedropedroka")
    api.connect()
    if PRODUCION:
        api.change_balance('REAL')  #PRACTICE \ REAL
    else:
        api.change_balance('PRACTICE')  #PRACTICE \ REAL
    if api.check_connect():
        return True
    else:
        return False
示例#7
0
    def test_leader_board(self):
        iq_api = IQOption(email, password, 'DEBUG')
        check, reason = iq_api.connect()
        self.assertTrue(check)
        self.assertIsNone(reason)
        iq_api.change_balance("PRACTICE")
        self.assertTrue(iq_api.check_connect())

        print(
            '___________________________ 100 Near Traders to this ranking account ______________________'
        )
        near_traders = iq_api.get_leader_board(country=30,
                                               near_traders_count=100,
                                               pooling_time=120)
        for k, v in near_traders['near_traders'].items():
            print(' -> {} Name: {} - Profit: {} Country: {}'.format(
                k, v['user_name'], v['score'], v['flag']))

        time.sleep(30)

        print(
            '___________________________ Top 10 Countries Ranking  ______________________'
        )
        top_ten_country = iq_api.get_top_ten_countries()
        self.assertTrue(len(top_ten_country) == 10)
        for k, v in top_ten_country.items():
            print(' -> {} - {} Profit: {}'.format(k, v['country_name'],
                                                  v['profit']))

        # time.sleep(30)
        #
        # print('___________________________ Top 100000 Worldwide Traders  ______________________')
        # top_traders = iq_api.get_positional_ranking_traders(to_position=100000)
        # self.assertIsNotNone(top_traders)
        # print('Top Traders Country {} ->'.format(top_traders))

        time.sleep(30)

        print(
            '___________________________ Top 50 Brazilians Traders  ______________________'
        )
        country = 'Brazil'
        top_traders_country = iq_api.get_positional_ranking_traders(
            country=country, to_position=50)
        print('Top Traders Country {} ->  {} '.format(country,
                                                      top_traders_country))

        iq_api.close_connect()
示例#8
0
 def test_users(self):
     iq_api = IQOption(email, password)
     iq_api.connect()
     iq_api.change_balance("PRACTICE")
     self.assertEqual(iq_api.check_connect(), True)
     users = iq_api.get_leader_board('Worldwide', 1, 20, 0)
     for k, v in users['positional'].items():
         user_data = iq_api.get_users_availability(v['user_id'])
         print(user_data)
         user_datas = iq_api.request_leaderboard_userinfo_deals_client(
             v['user_id'], v['flag'])
         self.assertTrue(type(user_datas) is dict)
         print(user_datas)
         self.assertTrue(
             type(iq_api.get_user_profile_client(v['user_id'])) is dict)
         time.sleep(.2)
     iq_api.close_connect()
示例#9
0
def login():
    PRODUCION = False
    if '-P' in sys.argv:
        PRODUCION = True
    init(autoreset=True)
    #LOGIN
    logging.basicConfig(format='%(asctime)s %(message)s')
    global api
    api = IQOption("*****@*****.**", "pedroadv991@")
    api.connect()
    if PRODUCION:
        api.change_balance('REAL')#PRACTICE \ REAL
        print("Iniciando em Produção")
    else:
        api.change_balance('PRACTICE')#PRACTICE \ REAL
    if api.check_connect():
        print(Fore.RED,"Api IQ Connectada com sucesso")
        return api    
    else:
        print(Fore.RED+"Erro ao se conectar");exit()
示例#10
0
 def test_Candle(self):
     iq_api=IQOption(email, password)
     iq_api.connect()
     iq_api.change_balance("PRACTICE")
     balance = iq_api.get_balance()
     self.assertTrue(type(balance) is float)
     print('balance: {}'.format(balance))
     iq_api.reset_practice_balance()
     self.assertEqual(iq_api.check_connect(), True)
     ALL_Asset = iq_api.get_all_open_time(('turbo',))
     if ALL_Asset["turbo"]["EURUSD"]["open"]:
         ACTIVES="EURUSD"
     else:
         ACTIVES="EURUSD-OTC"
     iq_api.get_candles(ACTIVES, 60, 1000, time.time())
     size = "all"
     iq_api.start_candles_stream(ACTIVES, size, 10)
     iq_api.get_realtime_candles(ACTIVES, size)
     iq_api.stop_candles_stream(ACTIVES, size)
     iq_api.close_connect()
示例#11
0
    def test_options(self):
        self.iq_api = IQOption(email, password)
        self.iq_api.connect()
        self.iq_api.change_balance("PRACTICE")

        self.assertEqual(self.iq_api.check_connect(), True)
        all_assets = self.iq_api.get_all_open_time()

        time.sleep(5)

        if all_assets["turbo"]["EURUSD"]["open"]:
            active_turbo = "EURUSD"
        else:
            active_turbo = "EURUSD-OTC"

        if all_assets["binary"]["EURUSD"]["open"]:
            active_binary = "EURUSD"
        else:
            active_binary = "EURUSD-OTC"

        time.sleep(5)

        tht = Thread(target=self.turbo_option,
                     args=(active_turbo, ),
                     daemon=True)
        tht.start()
        thb = Thread(target=self.binary_option,
                     args=(active_binary, ),
                     daemon=True)
        time.sleep(5)
        thb.start()
        time.sleep(5)
        tht.join()
        time.sleep(5)
        thb.join()
        self.iq_api.close_connect()
示例#12
0
    def test_countries(self):
        iq_api = IQOption(email, password)
        iq_api.connect()
        iq_api.change_balance("PRACTICE")
        country = Countries(iq_api)

        print(
            "___________________ GET LIST COUNTRIES NAMES __________________________"
        )
        countries = country.get_countries_names()
        self.assertTrue(type(countries) is list)
        for c in countries:
            print(c)

        country_id_w = country.get_country_id('Worldwide')
        self.assertTrue(type(country_id_w) is int)
        print('Wordwide ID: {}'.format(country_id_w))

        print(
            "___________________ COUNTRY ID BY NAME __________________________"
        )
        country_id_b = country.get_country_id('Brazil')
        self.assertTrue(type(country_id_b) is int)
        print('Brazil ID: {}'.format(country_id_b))

        print(
            "___________________ COUNTRY ID BY SHORT NAME __________________________"
        )
        country_id_b_s = country.get_country_id('BR')
        self.assertTrue(type(country_id_b_s) is int)
        print('BR ID: {}'.format(country_id_b_s))

        print(
            "___________________ COUNTRY NAME BY ID __________________________"
        )
        country_name = country.get_country_name(country_id_b)
        self.assertIsNotNone(country_name)
        print('ID {}: {}'.format(country_id_b, country_name))

        print(
            "___________________ COUNTRY NAME BY SHORTNAME __________________________"
        )
        country_name_2 = country.get_country_name("BR")
        self.assertIsNotNone(country_name_2)
        print('ID BR: {}'.format(country_name_2))

        print(
            "___________________ COUNTRY SHORTNAME BY ID __________________________"
        )
        country_shortname = country.get_country_shortname(country_id_b)
        self.assertIsNotNone(country_shortname)
        print('ID {}: {}'.format(country_id_b, country_shortname))

        print(
            "___________________ COUNTRY SHORTNAME BY NAME __________________________"
        )
        country_shortname_2 = country.get_country_shortname("Brazil")
        self.assertIsNotNone(country_shortname_2)
        print('ID BR: {}'.format(country_shortname_2))

        iq_api.close_connect()
    def test_digital_option(self):
        iq_api = IQOption(email, password)
        iq_api.connect()
        self.assertEqual(iq_api.check_connect(), True)
        time.sleep(1)
        iq_api.change_balance("PRACTICE")

        time.sleep(5)

        all_assets = iq_api.get_all_open_time()

        if all_assets["digital"]["EURUSD"]["open"]:
            actives = "EURUSD"
        else:
            actives = "EURUSD-OTC"

        money = 1
        action_call = "call"
        expirations_mode = 1

        time.sleep(5)

        check_call, id_call = iq_api.buy_digital_spot(actives, money, action_call, expirations_mode)
        self.assertTrue(check_call)
        self.assertTrue(type(id_call) is int)
        start = time.time()

        time.sleep(5)

        iq_api.subscribe_strike_list(actives, expirations_mode)
        limit = expirations_mode*60+60

        while not iq_api.check_win_digital_v2(id_call)[0]:
            time.sleep(.2)
            if time.time()-start > limit:
                raise TimeoutError
            spot = iq_api.get_digital_spot_profit_after_sale(id_call)
            print('Current Spot After Sale: {}'.format(spot))
            time.sleep(1)

        time.sleep(1)

        iq_api.unsubscribe_strike_list(actives, expirations_mode)

        result = iq_api.check_win_digital_v2(id_call)[1]
        self.assertTrue(type(result) is float)
        print('Result: {}'.format(result))
        action_call = "put"

        time.sleep(5)

        check_put, id_put = iq_api.buy_digital_spot(actives, money, action_call, expirations_mode)
        self.assertTrue(check_put)
        self.assertTrue(type(id_put) is int)

        time.sleep(5)

        self.assertTrue(iq_api.close_digital_option(id_put))

        time.sleep(5)

        asyncio.run(iq_api.check_win_digital_v3(id_put))

        time.sleep(5)

        iq_api.get_digital_position(id_put)

        time.sleep(5)

        iq_api.check_win_digital(id_put)

        limit = 5
        duration = 1
        count = 0
        for active in all_assets['digital']:
            if not all_assets['digital'][active]['open']:
                continue
            if count == limit:
                break
            try:
                strikes = iq_api.get_strike_list(active, duration)[1]
                print('Strikes for {} ( {} ) -> {}'.format(active, "digital", strikes))
            except IndexError:
                continue
            else:
                for strike in strikes:
                    print(' -> {} -> {}'.format(strike, strikes[strike]))
            finally:
                count += 1
                time.sleep(3)
        count = 0

        time.sleep(3)

        type_asset = 'digital'
        for active in all_assets[type_asset]:
            if all_assets[type_asset][active]['open']:
                iq_api.subscribe_strike_list(active, duration)
                time.sleep(1)
                current_profit = iq_api.get_digital_current_profit(active, duration)
                print('current profit for {} ( {} ) -> {}'.format(active, type_asset, current_profit))
                time.sleep(3)
                strikes = iq_api.get_realtime_strike_list(active, duration)
                print('Strikes {} digital -> {}'.format(active, strikes))
                for strike in strikes:
                    print(' -> {} -> {}'.format(strike, strikes[strike]))
                time.sleep(3)
                quites = iq_api.get_instrument_quites_generated_data(active, duration)
                print('quites for {} ( {} ) -> {}'.format(active, type_asset, quites))
                iq_api.unsubscribe_strike_list(active, duration)
                break
        iq_api.close_connect()
    def test_binary_option(self):
        iq_api = IQOption(email, password, 'DEBUG')
        iq_api.connect()
        iq_api.change_balance("PRACTICE")
        self.assertEqual(iq_api.check_connect(), True)
        all_assets = iq_api.get_all_open_time()

        print("_______________________GET OPTION INFO___________________________")
        info_ok, option_info = iq_api.get_optioninfo(10)
        self.assertTrue(info_ok)
        self.assertIsNotNone(option_info)
        print(option_info)

        time.sleep(5)

        print("_______________________GET OPTION INFO v2___________________________")
        option_info2 = iq_api.get_optioninfo_v2(10)
        self.assertIsNotNone(option_info2)
        print(option_info2)

        time.sleep(5)

        print("_______________________BUY BINARY CALL 15 minutes expiration___________________________")
        if all_assets["binary"]["EURUSD"]["open"]:
            active = "EURUSD"
        else:
            active = "EURUSD-OTC"
        money = 1
        action_call = "call"
        expirations_mode = 15
        check_call, id_call = iq_api.buy(money, active, action_call, expirations_mode)
        self.assertTrue(check_call)
        self.assertTrue(type(id_call) is int)

        time.sleep(5)

        print("_______________________SELL BINARY CALL___________________________")
        self.assertTrue(iq_api.sell_option(id_call))

        if all_assets["turbo"]["EURUSD"]["open"]:
            active = "EURUSD"
        else:
            active = "EURUSD-OTC"
        expirations_mode = 1

        time.sleep(5)

        print("_______________________BUY TURBO PUT___________________________")
        action_call = "put"
        check_put, id_put = iq_api.buy(money, active, action_call, expirations_mode)

        time.sleep(5)

        self.assertTrue(check_put)
        self.assertTrue(type(id_put) is int)

        print("_______________________WAIT FOR RESULT TURBO PUT___________________________")
        result = iq_api.check_win_v3(id_put, expirations_mode)
        self.assertTrue(type(result) is float)
        print("RESULT FOR BUY TURBO PUT: {:.2f}".format(result))

        time.sleep(5)

        print("_______________________BINARY OPTION DETAIL___________________________")
        options_details = iq_api.get_binary_option_detail()
        print(options_details)

        time.sleep(5)

        all_profit = iq_api.get_all_profit()
        self.assertIsNotNone(all_profit)
        print(all_profit)

        time.sleep(5)

        print("_______________________BUY TURBO CALL___________________________")
        action_call = "call"
        check_call, id_call = iq_api.buy(money, active, action_call, expirations_mode)
        self.assertTrue(check_call)
        self.assertTrue(type(id_call) is int)

        print("_______________________WAIT FOR RESULT TURBO CALL___________________________")
        check = False
        start = time.time()
        limit = expirations_mode*60+10
        result = None
        while not check:
            if time.time()-start > limit:
                raise TimeoutError
            check, result = iq_api.check_win_v4(id_call)
            remaining = iq_api.get_remaning(expirations_mode)
            print("remaining: {}".format(remaining))
            time.sleep(1)
        print("RESULT FOR BUY TURBO  CALL: {:.2f}".format(result))

        print("_______________________MULTI BUY TURBO___________________________")
        actives = list()
        for k, v in all_assets['turbo'].items():
            if v['open']:
                actives.append(k)

        dirs = ['call', 'put']
        directions = list()
        prices = list()
        expirations = list()

        total_actives = len(actives)
        for _ in range(total_actives):
            directions.append(dirs[random.randrange(0, 1)])
            prices.append(random.randrange(1, 10))
            expirations.append(1)

        list_buys = iq_api.buy_multi(prices, actives, directions, expirations)

        time.sleep(1)

        for idx in range(total_actives):
            print('Buy {} at price {} of active {} on expiration {}'.format(directions[idx], prices[idx], actives[idx], expirations[idx]))

        self.assertTrue(type(list_buys) is list)

        print("_______________________ WAIT FOR RESULT MULTI BUY TURBO___________________________")

        start = time.time()
        limit = expirations_mode * 60 + 180

        results = list()
        count = 0
        tot = len(list_buys)

        self.assertTrue(total_actives == tot)

        while count < tot:
            if time.time() - start > limit:
                raise TimeoutError
            for idx in list_buys:
                if count == tot:
                    break
                if idx:
                    check, result = iq_api.check_win_v4(idx)
                    if check:
                        results.append(result)
                        count += 1
                # else:
                #     raise ValueError('this buy not ID')
                time.sleep(.2)

        # self.assertTrue(len(results) == tot)

        for idx in range(len(results)):
            print("RESULT FOR BUY TURBO CALL {} (USD {:.2f} ): {:.2f}".format(actives[idx], prices[idx], results[idx]))
        iq_api.close_connect()