Alvin3y1 commited on
Commit
c044198
·
verified ·
1 Parent(s): 04e02fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -5,6 +5,7 @@ import time
5
  import bisect
6
  import math
7
  import statistics
 
8
  from datetime import datetime
9
  from aiohttp import web
10
  import websockets
@@ -559,6 +560,31 @@ HTML_PAGE = f"""
559
 
560
  async def kraken_worker():
561
  global market_state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  while True:
563
  try:
564
  async with websockets.connect("wss://ws.kraken.com/v2") as ws:
 
5
  import bisect
6
  import math
7
  import statistics
8
+ import aiohttp
9
  from datetime import datetime
10
  from aiohttp import web
11
  import websockets
 
560
 
561
  async def kraken_worker():
562
  global market_state
563
+
564
+ try:
565
+ async with aiohttp.ClientSession() as session:
566
+ url = "https://api.kraken.com/0/public/OHLC?pair=XBTUSD&interval=1"
567
+ async with session.get(url) as response:
568
+ if response.status == 200:
569
+ data = await response.json()
570
+ if 'result' in data:
571
+ for key in data['result']:
572
+ if key != 'last':
573
+ raw_candles = data['result'][key]
574
+ market_state['ohlc_history'] = [
575
+ {
576
+ 'time': int(c[0]),
577
+ 'open': float(c[1]),
578
+ 'high': float(c[2]),
579
+ 'low': float(c[3]),
580
+ 'close': float(c[4])
581
+ }
582
+ for c in raw_candles[-120:]
583
+ ]
584
+ break
585
+ except Exception as e:
586
+ logging.error(f"History fetch failed: {e}")
587
+
588
  while True:
589
  try:
590
  async with websockets.connect("wss://ws.kraken.com/v2") as ws: