Dmtlant commited on
Commit
4615036
·
verified ·
1 Parent(s): ebf0608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -14,6 +14,8 @@ data = {crypto: {'prices': [], 'times': []} for crypto in cryptos}
14
 
15
  # Инициализация Streamlit
16
  st.title('Crypto Advisor')
 
 
17
  charts = {crypto: st.empty() for crypto in cryptos}
18
  advice_boxes = {crypto: st.empty() for crypto in cryptos}
19
 
@@ -58,33 +60,27 @@ def update_chart(symbol):
58
  # Функция для выдачи советов
59
  def give_advice(symbol, price):
60
  if len(data[symbol]['prices']) < 2:
61
- advice_boxes[symbol].text(f'{symbol}: Not enough data yet.')
62
- return
63
-
64
- last_price = data[symbol]['prices'][-2]
65
- current_price = price
66
-
67
- if current_price > last_price:
68
- advice = f'{symbol}: Price is increasing. Consider buying.'
69
- elif current_price < last_price:
70
- advice = f'{symbol}: Price is decreasing. Consider selling.'
71
  else:
72
- advice = f'{symbol}: Price is stable. Hold for now.'
 
 
 
 
 
 
 
 
73
 
74
  advice_boxes[symbol].text(advice)
75
 
76
  # Функция для запуска асинхронного цикла
77
- def run_event_loop():
78
- loop = asyncio.new_event_loop()
79
- asyncio.set_event_loop(loop)
80
- loop.run_until_complete(get_crypto_data())
81
-
82
- # Запуск приложения
83
- if __name__ == '__main__':
84
  st.write('Connecting to Binance...')
85
  st.write('Please wait for the data to start streaming.')
 
 
86
 
87
- # Запуск асинхронного цикла в отдельном потоке
88
- import threading
89
- thread = threading.Thread(target=run_event_loop)
90
- thread.start()
 
14
 
15
  # Инициализация Streamlit
16
  st.title('Crypto Advisor')
17
+
18
+ # Создание пустых мест для графиков и советов
19
  charts = {crypto: st.empty() for crypto in cryptos}
20
  advice_boxes = {crypto: st.empty() for crypto in cryptos}
21
 
 
60
  # Функция для выдачи советов
61
  def give_advice(symbol, price):
62
  if len(data[symbol]['prices']) < 2:
63
+ advice = f'{symbol}: Not enough data yet.'
 
 
 
 
 
 
 
 
 
64
  else:
65
+ last_price = data[symbol]['prices'][-2]
66
+ current_price = price
67
+
68
+ if current_price > last_price:
69
+ advice = f'{symbol}: Price is increasing. Consider buying.'
70
+ elif current_price < last_price:
71
+ advice = f'{symbol}: Price is decreasing. Consider selling.'
72
+ else:
73
+ advice = f'{symbol}: Price is stable. Hold for now.'
74
 
75
  advice_boxes[symbol].text(advice)
76
 
77
  # Функция для запуска асинхронного цикла
78
+ async def main():
 
 
 
 
 
 
79
  st.write('Connecting to Binance...')
80
  st.write('Please wait for the data to start streaming.')
81
+ task = asyncio.create_task(get_crypto_data())
82
+ await task
83
 
84
+ # Запуск приложения
85
+ if __name__ == '__main__':
86
+ asyncio.run(main())