Python - Telegram conversation robot While non-working error question.

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

Hello!

Currently, we are making a coin alarm bot using Telegram with Python. I'm a total beginner, so I'm looking for it on Google. If you create a conversation bot and send a command as shown below, there is an error that only spits out the same value without turning around the while statement.

What part of the code is wrong?

    updater.start_polling()
    updater.idle()

I think it's an error that comes out because I don't understand this phrase correctly, but I can't Please refer to the code below and help us!

"""
Created on Tue May 25 23:17:44 2021

@author: aabomb45
"""

import pyupbit
import ccxt
import urllib.request 
import urllib.parse as parse
from bs4 import BeautifulSoup
from telegram.ext import Updater, MessageHandler, Filters, CommandHandler  # import modules


while True:
    ## ## KRW-USD ##
    url = "https://finance.naver.com/marketindex/"

    html = urllib.request.urlopen(url).read()
    soup = BeautifulSoup(html,'html.parser')

    value = soup.select("span.value")
    value_str = value[0].string[0:5]
    KRW_USD =float(value_str.replace(',',''))


    ## ## Upbit Key ##
    access_key = ""
    secret_key = ""


    ## ## Binance Key ##
    binance = ccxt.binance({
        'apiKey': '',
        'secret': '',
    })


    ## ## KimChi Calc ##
    up_btc = pyupbit.get_current_price("KRW-BTC")

    bi_ticker = binance.fetch_ticker("BTC/USDT")
    bi_btc = bi_ticker['close']

    KimChi =  (up_btc / (bi_btc * KRW_USD)) * 100 - 100
    #print(KimChi)


    ## ## Profit Calc ##
    upbit = pyupbit.Upbit(access_key, secret_key)
    up_avg_buy_price = float(upbit.get_balances()[1]['avg_buy_price'])
    up_avg_buy_balance = float(upbit.get_balances()[1]['balance'])
    up_profit = (up_btc - up_avg_buy_price) * up_avg_buy_balance
    #print(up_profit)


    balance = binance.fetch_balance(params={"type": "future"})

    for i in range(len(balance['info']['positions'])):
        if balance['info']['positions'][i]['symbol'] == "BTCUSDT":
            bi_avg_buy_price = float(balance['info']['positions'][i]['entryPrice'])

    bi_profit = (bi_avg_buy_price - bi_btc) * up_avg_buy_balance
    #print(bi_profit)

    profit = up_profit + (bi_profit * KRW_USD * (1 + KimChi * 0.01))
    #print(profit)

    ## ## Telegram ##

    My_token = 'My Telegram token (Laughing)

    print('start telegram chat bot')



    # # order function
    def order_command(update, context) :
        update.message.reply_text(KimChi)
        update.message.reply_text(profit)

    updater = Updater(my_token, use_context=True)

    order_handler = CommandHandler('order', order_command)
    updater.dispatcher.add_handler(order_handler)
    updater.start_polling()
    updater.idle()

python telegram

2022-09-20 16:03

1 Answers

There is an error in spitting out the same value without circulating the while statement.

not only spit out the same values around the door while > > while and same value not only make it out the door.

There is an error. >> Code works fine, but what is the error?

I think you want me to send you the inquired data when the command is entered while looking up the data, but if I were you, I would write a code that looks up the data and a code that works when I receive the command.


2022-09-20 16:03

If you have any answers or tips


© 2022 pinfo. All rights reserved.