Files
hedge/app.py
2025-08-03 20:44:53 +02:00

55 lines
2.1 KiB
Python

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
def start_market_data_thread(debug=False):
"""Start market data collection in a separate thread"""
market_thread = threading.Thread(target=lambda: market_info_loop(debug), 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()
# Give some time for initial market data to be collected
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")
sol_data = get_latest_price_with_timestamp("SOLUSD")
# 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 sol_data:
print(f"SOL/USD: ${sol_data['price']:.2f} (updated: {sol_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()