market monitor with timestamp works

This commit is contained in:
2025-08-02 22:28:44 +02:00
parent 7a8ce7e416
commit 64e94ef61a
2 changed files with 181 additions and 0 deletions

53
app.py Normal file
View File

@ -0,0 +1,53 @@
import time
from datetime import datetime
import threading
from market import market_info_loop, get_latest_price, get_all_latest_prices, get_latest_price_with_timestamp, set_debug
def start_market_data_thread(debug=False):
"""Start market data collection in a separate thread"""
market_thread = threading.Thread(target=market_info_loop, daemon=True)
market_thread.start()
return market_thread
def main():
print("Starting app with market data collection...")
print("-" * 40)
# Start market data collection in background thread (debug=False by default)
start_market_data_thread(debug=True)
# Give some time for initial market data to be collected
print("Waiting for initial market data...")
time.sleep(10)
try:
while True:
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{current_time}] update!")
# Show some sample prices with timestamps
eth_data = get_latest_price_with_timestamp("ETHUSD")
btc_data = get_latest_price_with_timestamp("BTCUSD")
shib_data = get_latest_price_with_timestamp("SHIBUSD")
if eth_data:
print(f"ETH/USD: ${eth_data['price']:.2f} (updated: {eth_data['timestamp_str']})")
if btc_data:
print(f"BTC/USD: ${btc_data['price']:.2f} (updated: {btc_data['timestamp_str']})")
if shib_data:
print(f"SHIB/USD: ${shib_data['price']:.8f} (updated: {shib_data['timestamp_str']})")
# Show total number of markets with prices
all_prices = get_all_latest_prices()
print(f"Total markets tracked: {len(all_prices)}")
# Sleep for 60 seconds (1 minute)
time.sleep(60)
except KeyboardInterrupt:
print("\nApp stopped by user")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()