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()
 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()
Esempio n. 3
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()
Esempio n. 5
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()
    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()
Esempio n. 7
0
class TestSubscribeBinaryOption(unittest.TestCase):
    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()

    def turbo_option(self, active):

        self.iq_api.subscribe_live_deal_binary(active, True)

        start_t = time.time()
        while True:
            entrances = self.iq_api.get_live_deal_binary(active)
            if time.time() - start_t > 60:
                raise TimeoutError
            if entrances:
                print("__For_turbo_option__ data size: " + str(len(entrances)))
                for entrance in entrances:
                    print(entrance)
                break

        self.iq_api.unsubscribe_live_deal_binary(active, True)
        print("_____________unsubscribe_live_deal_______________")

        time.sleep(5)

        all_deals = self.iq_api.get_all_deals_binary(active, True)
        tot_all = len(all_deals)
        print('list of all deals ( {} ) turbo -> {}'.format(
            tot_all, all_deals))

    def binary_option(self, active):
        self.iq_api.subscribe_live_deal_binary(active, False)
        start_t = time.time()

        while True:
            entrances = self.iq_api.get_live_deal_binary(active, False)
            if time.time() - start_t > 60:
                raise TimeoutError
            if entrances:
                print("__For_binary_option__ data size: " +
                      str(len(entrances)))
                for entrance in entrances:
                    print(entrance)
                break
        self.iq_api.unsubscribe_live_deal_binary(active, False)
        print("_____________unscribe_live_deal_______________")
        all_deals = self.iq_api.get_all_deals_binary(active, False)
        tot_all = len(all_deals)
        print('list of all deals ( {} ) binary -> {}'.format(
            tot_all, all_deals))
    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()