import requests
from urllib.request import urlopen
from lxml import etree
import json
import pandas as pd
import config
from binance import Client as ClientBN
from mexcpy import MexcAPI
import aiohttp
import asyncio


ErrorSymbol = []

def welcome():
    while True:
        # Вывод комис с хуоби

        url = 'https://api.huobi.pro/v2/reference/currencies'
        headers = {'Content-Type': 'text/html', }
        response = requests.get(url, headers=headers)
        html = response.text
        with open('huobi_fee_html', 'w', encoding='utf-8') as r:
            r.write(html)

        local = 'file:///C:/Users/user/PycharmProjects/pythonProject/huobi_fee_html'
        response = urlopen(local)
        htmlparser = etree.HTMLParser()
        tree = etree.parse(response, htmlparser)

        DataSetNotProcessedFee_HB = tree.xpath('//body/descendant::node()/text()')

        resFee_HB = json.loads(str(*DataSetNotProcessedFee_HB))
        res_2Fee_HB = resFee_HB['data']

        Currency_HB = [] #coin
        Chains_HB = [] #networkList
        ChainAll_HB = []
        Chain_displayName_HB = [] #displayName
        Chain_fullName_HB = [] #fullName
        Chain_baseChain_HB = [] #baseChain
        DepositStatus_HB = [] #depositEnable
        WithdrawStatus_HB = [] #withdrawEnable

        for slovar in res_2Fee_HB:
            Currency_HB.append(slovar['currency'].upper())
            Chains_HB.append(slovar['chains'])

        for i in range(len(Chains_HB)):
            Chains1_HB = Chains_HB[i]
            Chain1_displayName_HB = []
            Chain1_fullName_HB = []
            Chain1_baseChain_HB = []
            DepositStatus1_HB = []
            WithdrawStatus1_HB = []
            ChainAll1_HB = []

            for slovar in Chains1_HB:
                Chain1_displayName_HB.append(slovar['displayName'])
                Chain1_fullName_HB.append((slovar['fullName']).upper().replace(' ',''))
                if 'baseChain' in slovar:
                    Chain1_baseChain_HB.append(slovar['baseChain'])
                else:
                    Chain1_baseChain_HB.append('')
                DepositStatus1_HB.append(slovar['depositStatus'])
                WithdrawStatus1_HB.append(slovar['withdrawStatus'])
                ChainAll1_HB = list(Chain1_displayName_HB+Chain1_fullName_HB+Chain1_baseChain_HB)
                DepositStatus1_HB = list(DepositStatus1_HB + DepositStatus1_HB + WithdrawStatus1_HB)
                WithdrawStatus1_HB = list(WithdrawStatus1_HB + WithdrawStatus1_HB + WithdrawStatus1_HB)

            # Chain_displayName_HB.append(Chain1_displayName_HB)
            # Chain_fullName_HB.append(Chain1_fullName_HB)
            # Chain_baseChain_HB.append(Chain1_baseChain_HB)
            ChainAll_HB.append(ChainAll1_HB)
            DepositStatus_HB.append(DepositStatus1_HB)
            WithdrawStatus_HB.append(WithdrawStatus1_HB)



        # Вывод комис с бинанса

        try:
            client = ClientBN(config.api_key, config.api_secret)
            info = client.get_all_coins_info()
        except Exception as e:
            print(e)
        # print(info)

        Currency_BN = [] #coin
        Chains_BN = [] #networkList
        ChainAll_BN = []
        # Chain_name_BN = [] #name
        # Chain_network_BN = [] #network
        DepositStatus_BN = [] #depositEnable
        WithdrawStatus_BN = [] #withdrawEnable

        for slovar in info:
            Currency_BN.append(slovar['coin'])
            Chains_BN.append(slovar['networkList'])

        for i in range(len(Chains_BN)):
            Chains1_BN = Chains_BN[i]
            Chain1_name_BN = []
            Chain1_network_BN = []
            DepositStatus1_BN = []
            WithdrawStatus1_BN = []
            ChainAll1_BN = []

            for slovar in Chains1_BN:

                DepositStatus1_BN.append(str(slovar['depositEnable']))
                WithdrawStatus1_BN.append(str(slovar['withdrawEnable']))

                _ = slovar['name'].split()
                if '(' in _[-1]:
                    Chain1_name_BN.append(_[-1].replace('(','').replace(')',''))

                else:
                    Chain1_name_BN.append(''.join(_[:len(_)]).replace('-','').upper())

                Chain1_network_BN.append(slovar['network'])
                ChainAll1_BN = list(Chain1_network_BN + Chain1_name_BN)
                DepositStatus1_BN = list(DepositStatus1_BN + DepositStatus1_BN)
                WithdrawStatus1_BN = list(WithdrawStatus1_BN + WithdrawStatus1_BN)

            # Chain_name_BN.append(Chain1_name_BN)
            # Chain_network_BN.append(Chain1_network_BN)
            DepositStatus_BN.append(DepositStatus1_BN)
            WithdrawStatus_BN.append(WithdrawStatus1_BN)
            ChainAll_BN.append(ChainAll1_BN)




        # Вывод комис с гейта

        url = 'https://api.gateio.ws/api/v4/spot/currencies'
        headers = {'Content-Type': 'text/html', }
        response = requests.get(url, headers=headers)
        html = response.text
        with open('gate_fee_html', 'w', encoding='utf-8') as g:
            g.write(html)

        local = 'file:///C:/Users/user/PycharmProjects/pythonProject/gate_fee_html'
        response = urlopen(local)
        htmlparser = etree.HTMLParser()
        tree = etree.parse(response, htmlparser)

        DataSetNotProcessedFee_GT = tree.xpath('//body/descendant::node()/text()')
        resFee_GT = json.loads(str(*DataSetNotProcessedFee_GT))

        Currency_GT1 = []
        res2Fee_GT = []

        for slovar in resFee_GT:
            Currency_GT_Сomparison1 = []
            ChainAll1_GT = []
            d = {}
            Currency_GT_Сomparison1.append(slovar['currency'].replace('_',' ').split()[0])
            if Currency_GT_Сomparison1 not in Currency_GT1:
                Currency_GT1.append(Currency_GT_Сomparison1)
                for item in resFee_GT:
                    Currency_GT_Сomparison2 = []
                    Currency_GT_Сomparison2.append(item['currency'].replace('_',' ').split()[0])
                    if Currency_GT_Сomparison2 == Currency_GT_Сomparison1:
                        ChainAll1_GT.append(item)
            else:
                Currency_GT_Сomparison1 = []

            if Currency_GT_Сomparison1 != []:
                Currency_GT_Сomparison3 = ''.join(Currency_GT_Сomparison1)
                d = dict(currency = Currency_GT_Сomparison3 , Chains = ChainAll1_GT)
                res2Fee_GT.append(d)

        Currency_GT = []
        Chains_GT = []
        ChainAll_GT = []
        DepositStatus_GT = []
        WithdrawStatus_GT = []

        for slovar in res2Fee_GT:
            Currency_GT.append(slovar['currency'])
            Chains_GT.append(slovar['Chains'])

        for i in range(len(Chains_GT)):
            Chains1_GT = Chains_GT[i]
            Chain1_GT = []
            DepositStatus1_GT = []
            WithdrawStatus1_GT = []

            for slovar in Chains1_GT:
                Chain1_GT.append(slovar['chain'])
                DepositStatus1_GT.append(str(slovar['deposit_disabled']))
                WithdrawStatus1_GT.append(str(slovar['withdraw_disabled']))

            ChainAll_GT.append(Chain1_GT)
            DepositStatus_GT.append(DepositStatus1_GT)
            WithdrawStatus_GT.append(WithdrawStatus1_GT)



        # Вывод комис с мекса

        mexc = MexcAPI(config.api_key_MX, config.api_secret_MX)
        resFee_MX = mexc.get_currency_information().json()

        Currency_MX = [] #coin
        Chains_MX = [] #networkList
        ChainAll_MX = []
        DepositStatus_MX = [] #depositEnable
        WithdrawStatus_MX = [] #withdrawEnable

        for slovar in resFee_MX:
            Currency_MX.append(slovar['coin'])
            Chains_MX.append(slovar['networkList'])

        for i in range(len(Chains_MX)):
            Chains1_MX = Chains_MX[i]
            Chain1_name_MX = []
            DepositStatus1_MX = []
            WithdrawStatus1_MX = []

            for item in Chains1_MX:
                DepositStatus1_MX.append(str(item['depositEnable']))
                WithdrawStatus1_MX.append(str(item['withdrawEnable']))

                _ = item['network'].split('(')
                if ')' in _[-1]:
                    Chain1_name_MX.append(_[0])
                else:
                    Chain1_name_MX.append(''.join(_[:len(_)]).replace('-','').upper())

            ChainAll_MX.append(Chain1_name_MX)
            DepositStatus_MX.append(DepositStatus1_MX)
            WithdrawStatus_MX.append(WithdrawStatus1_MX)



        # Вывод пар с хуоби(сделать try except)

        url = 'https://api.huobi.pro/market/tickers'
        headers = {'Content-Type': 'text/html', }
        response = requests.get(url, headers=headers)
        html = response.text
        with open('huobi_html', 'w', encoding='utf-8') as x:
            x.write(html)

        local = 'file:///C:/Users/user/PycharmProjects/pythonProject/huobi_html'
        response = urlopen(local)
        htmlparser = etree.HTMLParser()
        tree = etree.parse(response, htmlparser)

        DataSetNotProcessed_HB = tree.xpath('//body/descendant::node()/text()')

        res_HB = json.loads(str(*DataSetNotProcessed_HB))
        res_2_HB = res_HB['data']
        Symbol_HB = []
        BidPrice_HB = []
        AskPrice_HB = []
        bidAmm_HB = []
        askAmm_HB = []

        for slovar in res_2_HB:
            Symbol_HB.append(slovar['symbol'].upper())
            BidPrice_HB.append(slovar['bid'])
            AskPrice_HB.append(slovar['ask'])
            bidAmm_HB.append(slovar['bidSize'])
            askAmm_HB.append(slovar['askSize'])

        s = 0
        for i in range(0, len(BidPrice_HB)):
            if (BidPrice_HB[i] == 0.0) or (AskPrice_HB[i] == 0.0) or (Symbol_HB[i][(-3):] == ('NGN')) or (
                    Symbol_HB[i][(-8):(-4)] == ('DOWN')) or (Symbol_HB[i][(-6):(-4)] == ('UP')) or (Symbol_HB[i] == ('AXSBIDR'))\
                    or Symbol_HB[i] == ('ETHWUSDT') or Symbol_HB[i] == ('ETHFUSDT') or ('TRY') in Symbol_HB[i] or ('LSK') in Symbol_HB[i]:
                Symbol_HB.insert(i, '0')
                BidPrice_HB.insert(i, '0')
                AskPrice_HB.insert(i, '0')
                bidAmm_HB.insert(i, '0')
                askAmm_HB.insert(i, '0')

                Symbol_HB.pop(i + 1)
                BidPrice_HB.pop(i + 1)
                AskPrice_HB.pop(i + 1)
                bidAmm_HB.pop(i + 1)
                askAmm_HB.pop(i + 1)
                s = s + 1

        for i in range(s):
            Symbol_HB.remove('0')
            BidPrice_HB.remove('0')
            AskPrice_HB.remove('0')
            bidAmm_HB.remove('0')
            askAmm_HB.remove('0')

        for lenght in range(len(askAmm_HB)):
            askAmm_HB[lenght] = askAmm_HB[lenght]*AskPrice_HB[lenght]

        for lenght in range(len(bidAmm_HB)):
            bidAmm_HB[lenght] = bidAmm_HB[lenght]*BidPrice_HB[lenght]



        # Вывод пар с бинанса

        url = 'https://api2.binance.com/api/v3/ticker/bookTicker'
        headers = {'Content-Type': 'text/html', }
        response = requests.get(url, headers=headers)
        html = response.text
        with open('binance_html', 'w', encoding='utf-8') as b:
            b.write(html)

        local = 'file:///C:/Users/user/PycharmProjects/pythonProject/binance_html'
        response = urlopen(local)
        htmlparser = etree.HTMLParser()
        tree = etree.parse(response, htmlparser)

        DataSetNotProcessed_BN = tree.xpath('//body/descendant::node()/text()')
        res_BN = json.loads(str(*DataSetNotProcessed_BN))

        Symbol_BN = []
        BidPrice_BNstr = []
        AskPrice_BNstr = []
        bidAmm_BNstr = []
        askAmm_BNstr = []

        for slovar in res_BN:
            Symbol_BN.append(slovar['symbol'])
            BidPrice_BNstr.append(slovar['bidPrice'])
            AskPrice_BNstr.append(slovar['askPrice'])
            bidAmm_BNstr.append(slovar['bidQty'])
            askAmm_BNstr.append(slovar['askQty'])

        BidPrice_BN = []
        for item in BidPrice_BNstr:
            BidPrice_BN.append(float(item))

        AskPrice_BN = []
        for item in AskPrice_BNstr:
            AskPrice_BN.append(float(item))

        bidAmm_BN = []
        for item in bidAmm_BNstr:
            bidAmm_BN.append(float(item))

        askAmm_BN = []
        for item in askAmm_BNstr:
            askAmm_BN.append(float(item))

        s = 0
        for i in range(0, len(BidPrice_BN)):
            if (BidPrice_BN[i] == 0.0) or (AskPrice_BN[i] == 0.0) or (Symbol_BN[i][(-3):] == ('NGN')) or (
                    Symbol_BN[i][(-8):(-4)] == ('DOWN')) or (Symbol_BN[i][(-6):(-4)] == ('UP')) or (Symbol_BN[i] == ('AXSBIDR'))\
                    or Symbol_BN[i][:(3)] == ('NBT'):
                Symbol_BN.insert(i, '0')
                BidPrice_BN.insert(i, '0')
                AskPrice_BN.insert(i, '0')
                bidAmm_BN.insert(i, '0')
                askAmm_BN.insert(i, '0')

                Symbol_BN.pop(i + 1)
                BidPrice_BN.pop(i + 1)
                AskPrice_BN.pop(i + 1)
                bidAmm_BN.pop(i + 1)
                askAmm_BN.pop(i + 1)
                s = s + 1

        for i in range(s):
            Symbol_BN.remove('0')
            BidPrice_BN.remove('0')
            AskPrice_BN.remove('0')
            bidAmm_BN.remove('0')
            askAmm_BN.remove('0')

        for lenght in range(len(askAmm_BN)):
            askAmm_BN[lenght] = askAmm_BN[lenght] * AskPrice_BN[lenght]

        for lenght in range(len(bidAmm_BN)):
            bidAmm_BN[lenght] = bidAmm_BN[lenght] * BidPrice_BN[lenght]



        # Вывод пар с гейта

        async def get_orderbook_GT(session, symbol):
            url = f"https://api.gateio.ws/api/v4/spot/order_book?currency_pair={symbol}&limit=1"
            async with session.get(url) as response:
                data = await response.json()
                bids = data['bids']
                asks = data['asks']
                return symbol, bids, asks

        async def get_all_orderbooks_GT():
            url = "https://data.gateapi.io/api2/1/pairs"
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as response:
                    data = await response.json()
                    symbols = [symbol for symbol in data]

                orderbooks = {}
                tasks = []
                for symbol in symbols:
                    task = asyncio.ensure_future(get_orderbook_GT(session, symbol))
                    tasks.append(task)

                results = await asyncio.gather(*tasks, return_exceptions=True)
                for result in results:
                    if isinstance(result, Exception):
                        print(f"Error retrieving orderbook: {result}")
                    else:
                        symbol, bids, asks = result
                        orderbooks[symbol] = (bids, asks)

                return orderbooks

        orderbooks_GT = asyncio.run(get_all_orderbooks_GT())
        Symbol_GT = []
        BidPrice_GT = []
        bidAmm_GT = []
        AskPrice_GT = []
        askAmm_GT = []

        for symbol, (bids, asks) in orderbooks_GT.items():
            symbol = symbol.replace('_', '')
            if 'USDT' in symbol:
                try:
                    for i in range(0, 2):
                        bids[0][i] = float(bids[0][i])
                        asks[0][i] = float(asks[0][i])
                    # ощибка тут

                    Symbol_GT.append(symbol)

                    BidPrice_GT1 = bids[0][0]
                    bidAmm_GT1 = bids[0][1]
                    BidPrice_GT.append(BidPrice_GT1)
                    bidAmm_GT.append(bidAmm_GT1 * BidPrice_GT1)
                    AskPrice_GT1 = asks[0][0]
                    askAmm_GT1 = asks[0][1]
                    AskPrice_GT.append(AskPrice_GT1)
                    askAmm_GT.append(askAmm_GT1 * AskPrice_GT1)

                except Exception as e:
                    ErrorSymbol.append(symbol)



        # Вывод пар с мекса

        res_MX = MexcAPI.get_order_book_ticker().json()
        Symbol_MX = []
        BidPrice_MXstr = []
        AskPrice_MXstr = []
        bidAmm_MXstr = []
        askAmm_MXstr = []


        for slovar in res_MX:
            Symbol_MX.append(slovar['symbol'].replace('_',''))
            BidPrice_MXstr.append(slovar['bidPrice'])
            AskPrice_MXstr.append(slovar['askPrice'])
            bidAmm_MXstr.append(slovar['bidQty'])
            askAmm_MXstr.append(slovar['askQty'])

        s = 0
        for i in range(0, len(BidPrice_MXstr)):
            if (BidPrice_MXstr[i] == "") or (AskPrice_MXstr[i] == "") or (Symbol_MX[i][(-3):] == ('NGN')) or (
                    Symbol_MX[i][(-8):(-4)] == ('DOWN')) or (Symbol_MX[i][(-6):(-4)] == ('UP')) or (BidPrice_MXstr[i] == None)\
                    or (AskPrice_MXstr[i] == None) or ('3LUSDT' in Symbol_MX[i]) or ('5SUSDT' in Symbol_MX[i]) or ('3SUSDT' in Symbol_MX[i]) \
                    or ('5LUSDT' in Symbol_MX[i]) or (Symbol_MX[i] == 'ETHFUSDT') or (Symbol_MX[i] == 'ETHWUSDT') or (Symbol_MX[i] == 'ETHAUSDT'):
                Symbol_MX.insert(i, '0')
                BidPrice_MXstr.insert(i, '0')
                AskPrice_MXstr.insert(i, '0')
                bidAmm_MXstr.insert(i, '0')
                askAmm_MXstr.insert(i, '0')

                Symbol_MX.pop(i + 1)
                BidPrice_MXstr.pop(i + 1)
                AskPrice_MXstr.pop(i + 1)
                bidAmm_MXstr.pop(i + 1)
                askAmm_MXstr.pop(i + 1)
                s = s + 1

        for i in range(s):
            Symbol_MX.remove('0')
            BidPrice_MXstr.remove('0')
            AskPrice_MXstr.remove('0')
            bidAmm_MXstr.remove('0')
            askAmm_MXstr.remove('0')

        BidPrice_MX = []
        for item in BidPrice_MXstr:
            BidPrice_MX.append(float(item))

        AskPrice_MX = []
        for item in AskPrice_MXstr:
            AskPrice_MX.append(float(item))

        BidAmm_MX = []
        for item in bidAmm_MXstr:
            BidAmm_MX.append(float(item))

        AskAmm_MX = []
        for item in askAmm_MXstr:
            AskAmm_MX.append(float(item))

        askAmm_MX = []
        bidAmm_MX = []

        for lenght in range(len(AskAmm_MX)):
            askAmm_MX.append(AskAmm_MX[lenght] * AskPrice_MX[lenght])

        for lenght in range(len(BidAmm_MX)):
            bidAmm_MX.append(BidAmm_MX[lenght] * BidPrice_MX[lenght])



        Kommis_BN = 0.001
        Kommis_HB = 0.002
        Kommis_GT = 0.002
        Kommis_MX = 0
        FirstCoin = 'USDT'
        CoinNotInBundle = ['WNXM', 'COTI', 'MDX', 'SWAP', 'SKEB', 'MESA', 'BBF', 'REVV', 'VEMP', 'MCG', 'PUSH', 'ADX', 'TLOS', 'ROUTE', 'DC', 'ZIG', 'WELL', 'APED', 'MGG', 'LITH', 'BABYDOGE', 'FIU', 'ORBR', 'GMPD', 'POLC', 'BRISE', 'DEGO','GMEE', 'EGAME', 'KUBE', 'NSURE', 'MPLX','TOMS']
        CoinNotInBundle = ['COTI']
        CountUSDT = 1
        Bundledf = []
        FirstEx = []
        LastEX = []
        FirstC = []
        MidC = []
        LastC = []
        Price1 = []
        Price2 = []
        BundleData = []
        Spread = []
        Bundledfsort = []

        for t in range(0, 4):
            if t == 0:

                Symbol1 = Symbol_BN
                Kommis1 = Kommis_BN
                AskPrice1 = AskPrice_BN
                BidPrice1 = BidPrice_BN

                for q in range(0, 3):
                    if q == 0:
                        Bundle = []
                        Symbol2 = Symbol_HB
                        Kommis2 = Kommis_HB
                        AskPrice2 = AskPrice_HB
                        BidPrice2 = BidPrice_HB
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2, 'по цене',
                                                 BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2


                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2, 'по цене',
                                                 AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2, 'по цене',
                                                 AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2, 'по цене',
                                                 BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_HB.index(Bundle[l][5])
                            Index2 = Currency_BN.index(Bundle[l][5])

                            Index5 = Symbol_BN.index(SymbolLast1[l])
                            Index6 = Symbol_HB.index(SymbolLast2[l])
                            bid1 = askAmm_BN[Index5]
                            bid2 = bidAmm_HB[Index6]

                            for el in ChainAll_BN[Index2]:
                                if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_HB[Index1].index(el)
                                    Index4 = ChainAll_BN[Index2].index(el)
                                    if WithdrawStatus_BN[Index2][Index4] == 'True' and DepositStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_BN[Index2][Index4])
                                        Bundle[l].append(ChainAll_HB[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])

                    if q == 1:
                        Bundle = []
                        Symbol2 = Symbol_GT
                        Kommis2 = Kommis_GT
                        AskPrice2 = AskPrice_GT
                        BidPrice2 = BidPrice_GT
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            try:
                                Index1 = Currency_GT.index(Bundle[l][5])
                                Index2 = Currency_BN.index(Bundle[l][5])

                                Index5 = Symbol_BN.index(SymbolLast1[l])
                                Index6 = Symbol_GT.index(SymbolLast2[l])
                                bid1 = askAmm_BN[Index5]
                                bid2 = bidAmm_GT[Index6]

                                for el in ChainAll_BN[Index2]:
                                    if el in ChainAll_GT[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                        Index3 = ChainAll_GT[Index1].index(el)
                                        Index4 = ChainAll_BN[Index2].index(el)
                                        if WithdrawStatus_BN[Index2][Index4] == 'True' and DepositStatus_GT[Index1][Index3] == 'False' and Bundle[l][5] not in CoinNotInBundle:
                                            Bundle[l].append(ChainAll_BN[Index2][Index4])
                                            Bundle[l].append(ChainAll_GT[Index1][Index3])
                                            Bundle[l].append(bid1)
                                            Bundle[l].append(bid2)
                                            Bundledf.append(Bundle[l])
                            except Exception as e:
                                print(e)

                    if q == 2:
                        Bundle = []
                        Symbol2 = Symbol_MX
                        Kommis2 = Kommis_MX
                        AskPrice2 = AskPrice_MX
                        BidPrice2 = BidPrice_MX
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['бинанс', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            try:
                                Index1 = Currency_MX.index(Bundle[l][5])
                                Index2 = Currency_BN.index(Bundle[l][5])

                                Index5 = Symbol_BN.index(SymbolLast1[l])
                                Index6 = Symbol_MX.index(SymbolLast2[l])
                                bid1 = askAmm_BN[Index5]
                                bid2 = bidAmm_MX[Index6]

                                for el in ChainAll_BN[Index2]:
                                    if el in ChainAll_MX[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                        Index3 = ChainAll_MX[Index1].index(el)
                                        Index4 = ChainAll_BN[Index2].index(el)
                                        if WithdrawStatus_BN[Index2][Index4] == 'True' and DepositStatus_MX[Index1][Index3] == 'True' and Bundle[l][5] not in CoinNotInBundle:
                                            Bundle[l].append(ChainAll_BN[Index2][Index4])
                                            Bundle[l].append(ChainAll_MX[Index1][Index3])
                                            Bundle[l].append(bid1)
                                            Bundle[l].append(bid2)
                                            Bundledf.append(Bundle[l])
                            except Exception as e:
                                print(e)

            if t == 1:
                Symbol1 = Symbol_HB
                Kommis1 = Kommis_HB
                AskPrice1 = AskPrice_HB
                BidPrice1 = BidPrice_HB

                for q in range(0, 3):
                    if q == 0:
                        Bundle = []
                        Symbol2 = Symbol_BN
                        Kommis2 = Kommis_BN
                        AskPrice2 = AskPrice_BN
                        BidPrice2 = BidPrice_BN
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2, 'по цене',
                                                 BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2, 'по цене',
                                                 AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2, 'по цене',
                                                 AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2, 'по цене',
                                                 BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            try:
                                Index1 = Currency_HB.index(Bundle[l][5])
                                Index2 = Currency_BN.index(Bundle[l][5])

                                Index5 = Symbol_HB.index(SymbolLast1[l])
                                Index6 = Symbol_BN.index(SymbolLast2[l])
                                bid1 = askAmm_HB[Index5]
                                bid2 = bidAmm_BN[Index6]

                                for el in ChainAll_BN[Index2]:
                                    if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                        Index3 = ChainAll_HB[Index1].index(el)
                                        Index4 = ChainAll_BN[Index2].index(el)
                                        if DepositStatus_BN[Index2][Index4] == 'True' and WithdrawStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                            Bundle[l].append(ChainAll_BN[Index2][Index4])
                                            Bundle[l].append(ChainAll_HB[Index1][Index3])
                                            Bundle[l].append(bid1)
                                            Bundle[l].append(bid2)
                                            Bundledf.append(Bundle[l])
                            except Exception as e:
                                print(e)

                    if q == 1:
                        Bundle = []
                        Symbol2 = Symbol_GT
                        Kommis2 = Kommis_GT
                        AskPrice2 = AskPrice_GT
                        BidPrice2 = BidPrice_GT
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_HB.index(Bundle[l][5])
                            Index2 = Currency_GT.index(Bundle[l][5])

                            Index5 = Symbol_HB.index(SymbolLast1[l])
                            Index6 = Symbol_GT.index(SymbolLast2[l])
                            bid1 = askAmm_HB[Index5]
                            bid2 = bidAmm_GT[Index6]

                            for el in ChainAll_GT[Index2]:
                                if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_HB[Index1].index(el)
                                    Index4 = ChainAll_GT[Index2].index(el)
                                    if DepositStatus_GT[Index2][Index4] == 'False' and WithdrawStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_GT[Index2][Index4])
                                        Bundle[l].append(ChainAll_HB[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])

                    if q == 2:
                        Bundle = []
                        Symbol2 = Symbol_MX
                        Kommis2 = Kommis_MX
                        AskPrice2 = AskPrice_MX
                        BidPrice2 = BidPrice_MX
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['хуоби', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_HB.index(Bundle[l][5])
                            Index2 = Currency_MX.index(Bundle[l][5])

                            Index5 = Symbol_HB.index(SymbolLast1[l])
                            Index6 = Symbol_MX.index(SymbolLast2[l])
                            bid1 = askAmm_HB[Index5]
                            bid2 = bidAmm_MX[Index6]

                            for el in ChainAll_MX[Index2]:
                                if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_HB[Index1].index(el)
                                    Index4 = ChainAll_MX[Index2].index(el)
                                    if DepositStatus_MX[Index2][Index4] == 'True' and WithdrawStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_MX[Index2][Index4])
                                        Bundle[l].append(ChainAll_HB[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])

            if t == 2:

                Symbol1 = Symbol_GT
                Kommis1 = Kommis_GT
                AskPrice1 = AskPrice_GT
                BidPrice1 = BidPrice_GT

                for q in range(0, 3):
                    if q == 0:
                        Bundle = []
                        Symbol2 = Symbol_BN
                        Kommis2 = Kommis_BN
                        AskPrice2 = AskPrice_BN
                        BidPrice2 = BidPrice_BN
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            try:
                                Index1 = Currency_GT.index(Bundle[l][5])
                                Index2 = Currency_BN.index(Bundle[l][5])

                                Index5 = Symbol_GT.index(SymbolLast1[l])
                                Index6 = Symbol_BN.index(SymbolLast2[l])
                                bid1 = askAmm_GT[Index5]
                                bid2 = bidAmm_BN[Index6]

                                for el in ChainAll_BN[Index2]:
                                    if el in ChainAll_GT[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                        Index3 = ChainAll_GT[Index1].index(el)
                                        Index4 = ChainAll_BN[Index2].index(el)
                                        if DepositStatus_BN[Index2][Index4] == 'True' and WithdrawStatus_GT[Index1][Index3] == 'False' and Bundle[l][5] not in CoinNotInBundle:
                                            Bundle[l].append(ChainAll_BN[Index2][Index4])
                                            Bundle[l].append(ChainAll_GT[Index1][Index3])
                                            Bundle[l].append(bid1)
                                            Bundle[l].append(bid2)
                                            Bundledf.append(Bundle[l])
                            except Exception as e:
                                print(e)

                    if q == 1:
                        Bundle = []
                        Symbol2 = Symbol_HB
                        Kommis2 = Kommis_HB
                        AskPrice2 = AskPrice_HB
                        BidPrice2 = BidPrice_HB
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_HB.index(Bundle[l][5])
                            Index2 = Currency_GT.index(Bundle[l][5])

                            Index5 = Symbol_GT.index(SymbolLast1[l])
                            Index6 = Symbol_HB.index(SymbolLast2[l])
                            bid1 = askAmm_GT[Index5]
                            bid2 = bidAmm_HB[Index6]

                            for el in ChainAll_GT[Index2]:
                                if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_HB[Index1].index(el)
                                    Index4 = ChainAll_GT[Index2].index(el)
                                    if WithdrawStatus_GT[Index2][Index4] == 'False' and DepositStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_GT[Index2][Index4])
                                        Bundle[l].append(ChainAll_HB[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])

                    if q == 2:
                        Bundle = []
                        Symbol2 = Symbol_MX
                        Kommis2 = Kommis_MX
                        AskPrice2 = AskPrice_MX
                        BidPrice2 = BidPrice_MX
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'мекс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['гейт', 'мекс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_MX.index(Bundle[l][5])
                            Index2 = Currency_GT.index(Bundle[l][5])

                            Index5 = Symbol_GT.index(SymbolLast1[l])
                            Index6 = Symbol_MX.index(SymbolLast2[l])
                            bid1 = askAmm_GT[Index5]
                            bid2 = bidAmm_MX[Index6]

                            for el in ChainAll_GT[Index2]:
                                if el in ChainAll_MX[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_MX[Index1].index(el)
                                    Index4 = ChainAll_GT[Index2].index(el)
                                    if WithdrawStatus_GT[Index2][Index4] == 'False' and DepositStatus_MX[Index1][Index3] == 'True' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_GT[Index2][Index4])
                                        Bundle[l].append(ChainAll_MX[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])
            if t == 3:
                Symbol1 = Symbol_MX
                Kommis1 = Kommis_MX
                AskPrice1 = AskPrice_MX
                BidPrice1 = BidPrice_MX

                for q in range(0, 3):
                    if q == 0:
                        Bundle = []
                        Symbol2 = Symbol_BN
                        Kommis2 = Kommis_BN
                        AskPrice2 = AskPrice_BN
                        BidPrice2 = BidPrice_BN
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1


                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'бинанс', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'бинанс', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            try:
                                Index1 = Currency_MX.index(Bundle[l][5])
                                Index2 = Currency_BN.index(Bundle[l][5])

                                Index5 = Symbol_MX.index(SymbolLast1[l])
                                Index6 = Symbol_BN.index(SymbolLast2[l])
                                bid1 = askAmm_MX[Index5]
                                bid2 = bidAmm_BN[Index6]

                                for el in ChainAll_BN[Index2]:
                                    if el in ChainAll_MX[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                        Index3 = ChainAll_MX[Index1].index(el)
                                        Index4 = ChainAll_BN[Index2].index(el)
                                        if DepositStatus_BN[Index2][Index4] == 'True' and WithdrawStatus_MX[Index1][Index3] == 'True' and Bundle[l][5] not in CoinNotInBundle:
                                            Bundle[l].append(ChainAll_BN[Index2][Index4])
                                            Bundle[l].append(ChainAll_MX[Index1][Index3])
                                            Bundle[l].append(bid1)
                                            Bundle[l].append(bid2)
                                            Bundledf.append(Bundle[l])
                            except Exception as e:
                                print(e)

                    if q == 1:
                        Bundle = []
                        Symbol2 = Symbol_HB
                        Kommis2 = Kommis_HB
                        AskPrice2 = AskPrice_HB
                        BidPrice2 = BidPrice_HB
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'хуоби', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'хуоби', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_HB.index(Bundle[l][5])
                            Index2 = Currency_MX.index(Bundle[l][5])

                            Index5 = Symbol_MX.index(SymbolLast1[l])
                            Index6 = Symbol_HB.index(SymbolLast2[l])
                            bid1 = askAmm_MX[Index5]
                            bid2 = bidAmm_HB[Index6]

                            for el in ChainAll_MX[Index2]:
                                if el in ChainAll_HB[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_HB[Index1].index(el)
                                    Index4 = ChainAll_MX[Index2].index(el)
                                    if WithdrawStatus_MX[Index2][Index4] == 'True' and DepositStatus_HB[Index1][Index3] == 'allowed' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_MX[Index2][Index4])
                                        Bundle[l].append(ChainAll_HB[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])

                    if q == 2:
                        Bundle = []
                        Symbol2 = Symbol_GT
                        Kommis2 = Kommis_GT
                        AskPrice2 = AskPrice_GT
                        BidPrice2 = BidPrice_GT
                        SymbolLast1 = []
                        SymbolLast2 = []

                        for i in range(len(Symbol1)):
                            if Symbol1[i][:len(FirstCoin)] == FirstCoin:
                                Coin2 = Symbol1[i][len(FirstCoin):]
                                PriceWithKommis1 = BidPrice1[i] * (1 - Kommis1)
                                CountCoin = CountUSDT * PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'гейт', FirstCoin, 'по цене', BidPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                            if Symbol1[i][(-len(FirstCoin)):] == FirstCoin:
                                Coin2 = Symbol1[i][:-len(FirstCoin)]
                                PriceWithKommis1 = AskPrice1[i] * (1 + Kommis1)
                                CountCoin = CountUSDT / PriceWithKommis1

                                for j in range(len(Symbol2)):
                                    if Symbol2[j][-len(Coin2):] == Coin2:
                                        Coin3 = Symbol2[j][:-len(Coin2)]
                                        PriceWithKommis2 = AskPrice2[j] * (1 + Kommis2)
                                        CountCoin2 = CountCoin / PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', AskPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                                    if Symbol2[j][:len(Coin2)] == Coin2:
                                        Coin3 = Symbol2[j][len(Coin2):]
                                        PriceWithKommis2 = BidPrice2[j] * (1 - Kommis2)
                                        CountCoin2 = CountCoin * PriceWithKommis2

                                        if Coin3 == FirstCoin:
                                            SymbolLast2.append(Symbol2[j])
                                            SymbolLast1.append(Symbol1[i])
                                            Bundle.append(
                                                ['мекс', 'гейт', FirstCoin, 'по цене', AskPrice1[i], Coin2,
                                                 'по цене', BidPrice2[j], Coin3, (CountCoin2 - 1) * 100])

                        for l in range(len(Bundle)):
                            Index1 = Currency_MX.index(Bundle[l][5])
                            Index2 = Currency_GT.index(Bundle[l][5])

                            Index5 = Symbol_MX.index(SymbolLast1[l])
                            Index6 = Symbol_GT.index(SymbolLast2[l])
                            bid1 = askAmm_MX[Index5]
                            bid2 = bidAmm_GT[Index6]

                            for el in ChainAll_GT[Index2]:
                                if el in ChainAll_MX[Index1] and Bundle[l][9] > 0 and Bundle[l][9] < 30:
                                    Index3 = ChainAll_MX[Index1].index(el)
                                    Index4 = ChainAll_GT[Index2].index(el)
                                    if DepositStatus_GT[Index2][Index4] == 'False' and WithdrawStatus_MX[Index1][Index3] == 'True' and Bundle[l][5] not in CoinNotInBundle:
                                        Bundle[l].append(ChainAll_GT[Index2][Index4])
                                        Bundle[l].append(ChainAll_MX[Index1][Index3])
                                        Bundle[l].append(bid1)
                                        Bundle[l].append(bid2)
                                        Bundledf.append(Bundle[l])



        for h in Bundledf:
            if h not in Bundledfsort:
                Bundledfsort.append(h)

        for s in range(len(Bundledfsort)):
            BundleData.append(Bundledfsort[s][0:9])
            Spread.append(Bundledfsort[s][9:])

        for s in range(len(BundleData)):
            FirstEx.append(BundleData[s][0])
            LastEX.append(BundleData[s][1])
            FirstC.append(BundleData[s][2])
            MidC.append(BundleData[s][5])
            LastC.append(BundleData[s][8])
            Price1.append(BundleData[s][4])
            Price2.append(BundleData[s][7])

        df = pd.DataFrame({'FirstEx' : FirstEx,
                           'LastEx' : LastEX,
                           'FirstC' : FirstC,
                           'MidC' : MidC,
                           'LastC' : LastC,
                           'Price1' : Price1,
                           'Price2' : Price2,
                           'Spread': Spread})
        df.to_excel('./Data.xlsx')

        return Bundledfsort 
нужно что бы результат работы первой программы отсылал 
import config
import logging
import sqlite3
from aiogram import Bot, Dispatcher, executor, types
from datetime import datetime

# логирование
logging.basicConfig(level=logging.INFO)

# инициализация
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)

# подключение к базе данных
conn = sqlite3.connect('subscriptions.db')
cursor = conn.cursor()


def is_subscription_active(user_id):
    cursor.execute('SELECT valid_until FROM subscriptions WHERE user_id=?', (user_id,))
    result = cursor.fetchone()
    if result:
        valid_until = datetime.strptime(result[0], '%Y-%m-%d %H:%M:%S.%f')
        return valid_until
    return False


@dp.message_handler(commands=['check'])
async def check(message: types.Message):
    valid_until = is_subscription_active(message.from_user.id)
    if valid_until:
        await bot.send_message(message.chat.id, f'Ваша подписка активна до {valid_until.strftime("%Y-%m-%d")}.')
    else:
        await bot.send_message(message.chat.id, 'Ваша подписка истекла. Пожалуйста, продлите подписку в основном боте.')


if __name__ == "__main__":
    try:
        executor.start_polling(dp, skip_updates=True)
    finally:
        conn.close()
этот бот всем у коо есть подписка