how to change string in list for loop in python

hi i am new to learning python now i am trying a code i tried many way but i couldnot solve it here is my code this code only gets BTCUSDT VALUES but i would like to get more coin list from string list it is always prints last value on string list how could i print one by one

for example like this

VETUSDT ——————START—————–

last var: 0.07643779778265652 last pmax 0.07576949200637356

IOSTUSDT ——————START—————–

last var: 0.020887977208516414 last pmax 0.02071535207020709

TRXUSDT ——————START—————–

last var: 0.0613029012374088 last pmax 0.06095001184562004

if __name__ == '__main__':
# python binance client objemizi olusturuyoruz.
client = Client(config.API_KEY, config.API_SECRET)

coinlist = ['ETHUSDT', 'XLMUSDT', 'DOGEUSDT', 'XRPUSDT','BTCUSDT']
for x in coinlist:
     pair = x



# ikilimizi seciyoruz

# istediğimiz mum sayısını belirliyoruz
limit = 500

# zaman araligi, 5 dakikalik grafige bakiyorum
interval = '5m'

# ortalama tipi olarak VAR seciyorum.
ortalama_tipi = 'VAR'

# ortalama tipi: EMA almak icin asagidaki commenti kaldirip, yukarıdaki var satırını
# commente alin
# ortalama_tipi = 'EMA'

while 1:
    # binance'in limitlerine takilmamak icin, biraz bekliyoruz. 10 saniye kadar.
    time.sleep(10)

    try:
        klines = client.get_klines(symbol=pair, interval=interval, limit=limit)
    except Exception as exp:
        # baglanti hatasi olursa, biraz bekleyip, tekrar yeni client olusturuyor,
        # donguye kaldigim yerden devam ediyorum
        msg = f'exception in get_klines {str(exp)}'
        print(msg, flush=True)
        time.sleep(10)
        client = Client(config.API_KEY, config.API_SECRET)
        continue

    open_time = [int(entry[0]) for entry in klines]
    open_klines = [float(entry[1]) for entry in klines]
    high = [float(entry[2]) for entry in klines]
    low = [float(entry[3]) for entry in klines]
    close = [float(entry[4]) for entry in klines]

    close_array1 = np.asarray(close)
    close_array = close_array1[:-1]

    high_array1 = np.asarray(high)
    high_array = high_array1[:-1]

    low_array1 = np.asarray(low)
    low_array = low_array1[:-1]

    open_array1 = np.asarray(open_klines)
    open_array = open_array1[:-1]

    if ortalama_tipi == 'VAR':

        # Vidya (VAR) hesaplamasini yapiyorum
        var_arr = generateVar(high_array, low_array, moving_average_length=10)

        # Profit maximizer (pmax) hesaplamak icin, bir onceki satirda hesaplamis oldugum
        # var arrayini parametre olarak gonderiyorum
        pmax = generatePMax(var_arr, close_array, high_array, low_array, 10, 3)

        last_var = var_arr[-1]
        previous_var = var_arr[-2]

        last_pmax = pmax[-1]
        previous_pmax = pmax[-2]
        print(pair, '---START')
        print('last var:', last_var, 'last pmax', last_pmax, flush=True)

        if (last_var > last_pmax and previous_var < previous_pmax):
            msg = f'buy signal for {pair}'
            print(msg, flush=True)

        if last_var < last_pmax and previous_var > previous_pmax:
            msg = f'sell signal for {pair}'
            print(msg, flush=True)


    elif ortalama_tipi == 'EMA':

        # EMA (EMA) hesaplamasini yapiyorum
        ema_arr = generateEma(high_array, low_array, moving_average_length=10)

        # Profit maximizer (pmax) hesaplamak icin, bir onceki satirda hesaplamis oldugum
        # var arrayini parametre olarak gonderiyorum
        pmax = generatePMax(ema_arr, close_array, high_array, low_array, 10, 3)

        last_ema = ema_arr[-1]
        previous_ema = ema_arr[-2]

        last_pmax = pmax[-1]
        previous_pmax = pmax[-2]

        print('last ema:', last_ema, 'last pmax', last_pmax, flush=True)

        if (last_ema > last_pmax and previous_ema < previous_pmax):
            msg = f'buy signal for {pair}'
            print(msg, flush=True)

        if last_ema < last_pmax and previous_ema > previous_pmax:
            msg = f'sell signal for {pair}'
            print(msg, flush=True)

1 answer

  • answered 2021-09-11 18:16 mobius-crypt

    if __name__ == '__main__':
    # python binance client objemizi olusturuyoruz.
    client = Client(config.API_KEY, config.API_SECRET)
    
    coinlist = ['ETHUSDT', 'XLMUSDT', 'DOGEUSDT', 'XRPUSDT','BTCUSDT']
    for x in coinlist:
         pair = x
        #  HERE IS YOUR SOLUTION THE PROBLEM WAS INDENTATION YOU NEED TO RUN THE SAME CODE FOR EACH PAIR
        # ikilimizi seciyoruz
        
        # istediğimiz mum sayısını belirliyoruz
        limit = 500
        
        # zaman araligi, 5 dakikalik grafige bakiyorum
        interval = '5m'
        
        # ortalama tipi olarak VAR seciyorum.
        ortalama_tipi = 'VAR'
        
        # ortalama tipi: EMA almak icin asagidaki commenti kaldirip, yukarıdaki var satırını
        # commente alin
        # ortalama_tipi = 'EMA'
        
        while 1:
            # binance'in limitlerine takilmamak icin, biraz bekliyoruz. 10 saniye kadar.
            time.sleep(10)
        
            try:
                klines = client.get_klines(symbol=pair, interval=interval, limit=limit)
            except Exception as exp:
                # baglanti hatasi olursa, biraz bekleyip, tekrar yeni client olusturuyor,
                # donguye kaldigim yerden devam ediyorum
                msg = f'exception in get_klines {str(exp)}'
                print(msg, flush=True)
                time.sleep(10)
                client = Client(config.API_KEY, config.API_SECRET)
                continue
        
            open_time = [int(entry[0]) for entry in klines]
            open_klines = [float(entry[1]) for entry in klines]
            high = [float(entry[2]) for entry in klines]
            low = [float(entry[3]) for entry in klines]
            close = [float(entry[4]) for entry in klines]
        
            close_array1 = np.asarray(close)
            close_array = close_array1[:-1]
        
            high_array1 = np.asarray(high)
            high_array = high_array1[:-1]
        
            low_array1 = np.asarray(low)
            low_array = low_array1[:-1]
        
            open_array1 = np.asarray(open_klines)
            open_array = open_array1[:-1]
        
            if ortalama_tipi == 'VAR':
        
                # Vidya (VAR) hesaplamasini yapiyorum
                var_arr = generateVar(high_array, low_array, moving_average_length=10)
        
                # Profit maximizer (pmax) hesaplamak icin, bir onceki satirda hesaplamis oldugum
                # var arrayini parametre olarak gonderiyorum
                pmax = generatePMax(var_arr, close_array, high_array, low_array, 10, 3)
        
                last_var = var_arr[-1]
                previous_var = var_arr[-2]
        
                last_pmax = pmax[-1]
                previous_pmax = pmax[-2]
                print(pair, '---START')
                print('last var:', last_var, 'last pmax', last_pmax, flush=True)
        
                if (last_var > last_pmax and previous_var < previous_pmax):
                    msg = f'buy signal for {pair}'
                    print(msg, flush=True)
        
                if last_var < last_pmax and previous_var > previous_pmax:
                    msg = f'sell signal for {pair}'
                    print(msg, flush=True)
        
        
            elif ortalama_tipi == 'EMA':
        
                # EMA (EMA) hesaplamasini yapiyorum
                ema_arr = generateEma(high_array, low_array, moving_average_length=10)
        
                # Profit maximizer (pmax) hesaplamak icin, bir onceki satirda hesaplamis oldugum
                # var arrayini parametre olarak gonderiyorum
                pmax = generatePMax(ema_arr, close_array, high_array, low_array, 10, 3)
        
                last_ema = ema_arr[-1]
                previous_ema = ema_arr[-2]
        
                last_pmax = pmax[-1]
                previous_pmax = pmax[-2]
        
                print('last ema:', last_ema, 'last pmax', last_pmax, flush=True)
        
                if (last_ema > last_pmax and previous_ema < previous_pmax):
                    msg = f'buy signal for {pair}'
                    print(msg, flush=True)
        
                if last_ema < last_pmax and previous_ema > previous_pmax:
                    msg = f'sell signal for {pair}'
                    print(msg, flush=True)
    

    as indicated in the fix above the problem was indentation

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum