I want to return several return values and call them and use them, but there is an error. TypeError: 'Tuple' object is not callable

Asked 2 years ago, Updated 2 years ago, 97 views

I'd like to call the return value of the five ticker and use it TypeError: 'Tuple' object is not callable error. (ticker_head = ticker_head() on the last line.

No matter how much I search Google, I don't know why. I'd appreciate your help, masters.

def ticker_head():
   # ticker (KRW) lookup
    tickers = pyupbit.get_tickers(fiat="KRW")
    # ticker lookup and dataframe generation
    df = pd.DataFrame(columns=['ticker', 'rate', 'CRNT_price'])
    for ticker in tickers:
        # 5-hour moving average check
        ma5h = get_ma5h(ticker)
        # Current price inquiry
        current_price = pyupbit.get_current_price(ticker)
        # Calculation of the rate of change in the current price compared to the 5-hour moving average line
        rate = round((current_price/ma5h-1)*100, 2)
        # Create dateframe
        df = pd.concat([df, pd.DataFrame([[ticker, rate, current_price]], columns=[
            'ticker', 'rate', 'CRNT_price'])], ignore_index=True)

    # Rate of fluctuation, delete KRW-BTC index
    udf = df.sort_values(by=['rate', 'ticker'], ascending=False)
    filtered_udf = udf[~udf['ticker'].isin(['KRW-BTC'])]

    # Top 5 ticker outputs
    udf_head = filtered_udf.head()
    # Reset Index
    udf_head_rst_idx = udf_head.reset_index(drop=False)
    print(udf_head_rst_idx)

    # # print(udf_rev_head_rst_idx)
    ticker_1 = udf_head_rst_idx.loc[0][1]
    ticker_2 = udf_head_rst_idx.loc[1][1]
    ticker_3 = udf_head_rst_idx.loc[2][1]
    ticker_4 = udf_head_rst_idx.loc[3][1]
    ticker_5 = udf_head_rst_idx.loc[4][1]

    # # print(ticker_1, ticker_2, ticker_3, ticker_4, ticker_5)
    # Excel output (full ticker)
    udf.to_excel(excel_writer='under_sort_rate.xlsx')
    return ticker_1, ticker_2, ticker_3, ticker_4, ticker_5


# Defining an index for 1 hour repetition
interval_df = pyupbit.get_ohlcv("KRW-BTC", interval="minute60", count=1)

# Current time
now = datetime.datetime.now()
while True:

    # a one-hour repetition
    for h_period in interval_df.index:
        start_time = h_period
        end_time = h_period + datetime.timedelta(hours=1)
        # Top 5 ticker lookups
        ticker_head = ticker_head()

parameter function return tuple

2022-09-19 23:32

1 Answers

Entering the for statement, ticker_head is a function at first. So the phrase ticker_head() works.

However, once the syntax ticker_head = ticker_head() is performed, ticker_head becomes the first tuple returned from the ticker_head function. The variables get contaminated.

So when you run the second loop in the for statement, the phrase ticker_head() commands you to perform the "tuple" ticker_head as a function

is an error.


2022-09-19 23:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.