안녕하세요!
현재 파이썬으로 텔레그램을 이용한 코인 알람봇을 만들고 있습니다. 완전 초보자라서 구글에 하나하나 찾아가면서 만들고 있는데요. 아래와 같이 대화봇을 만들고 명령어를 보내면 while문을 안돌고 같은 값만 뱉어내는 오류가 있습니다 .
코드의 어떤 부분이 잘못된걸까요??
updater.start_polling()
updater.idle()
이 구문을 제가 정확하게 이해하지 못해서 나오는 오류인거 같은데 해결을 못하겠습니다. 아래 코드 참고하셔서 도움 주시면 감사하겠습니다!
"""
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 = '제 텔레그램 토큰입니다 ㅎㅎ'
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()