Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,15 +9,15 @@ from quotexpy.utils.candles_period import CandlesPeriod
|
|
9 |
from quotexpy.utils.account_type import AccountType
|
10 |
|
11 |
state = []
|
12 |
-
|
13 |
-
# Initialize once, so you can see connection errors immediately
|
14 |
client = Quotex(email="", password="", headless=True)
|
15 |
|
16 |
def background_worker(pair: str, timeframe: str):
|
17 |
try:
|
18 |
-
client.connect()
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
period_map = {
|
23 |
"5s": CandlesPeriod.SEC_5,
|
@@ -26,42 +26,45 @@ def background_worker(pair: str, timeframe: str):
|
|
26 |
"5m": CandlesPeriod.FIVE_MINUTES,
|
27 |
}
|
28 |
period = period_map.get(timeframe)
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
while True:
|
36 |
candles = client.get_realtime_candles(pair)
|
37 |
-
|
38 |
-
print(f"[Worker] raw candles payload: {candles!r}")
|
39 |
|
40 |
if candles:
|
41 |
-
#
|
42 |
-
# Take the latest candle
|
43 |
latest_ts = max(candles.keys())
|
44 |
c = candles[latest_ts]
|
45 |
symbol = "↑" if c["close"] > c["open"] else "↓"
|
46 |
-
ts =
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
50 |
entry = f"{ts} {symbol}"
|
51 |
state.append(entry)
|
52 |
if len(state) > 100:
|
53 |
state.pop(0)
|
54 |
-
print(f"[
|
55 |
else:
|
56 |
-
print("[
|
|
|
|
|
57 |
|
58 |
-
time.sleep(1) # throttle loop to 1 s
|
59 |
except Exception as e:
|
60 |
-
|
61 |
-
print(f"[Worker] ERROR: {e}", flush=True)
|
62 |
|
63 |
def start(pair, timeframe):
|
64 |
-
# clear previous state so you know fresh data is coming
|
65 |
state.clear()
|
66 |
threading.Thread(
|
67 |
target=background_worker,
|
|
|
9 |
from quotexpy.utils.account_type import AccountType
|
10 |
|
11 |
state = []
|
12 |
+
# Fill in your demo (or real) credentials here; without these you’ll often get no data.
|
|
|
13 |
client = Quotex(email="", password="", headless=True)
|
14 |
|
15 |
def background_worker(pair: str, timeframe: str):
|
16 |
try:
|
17 |
+
ok = client.connect()
|
18 |
+
print(f"[Debug] connect() returned: {ok}", flush=True)
|
19 |
+
ok = client.change_account(AccountType.PRACTICE)
|
20 |
+
print(f"[Debug] change_account() returned: {ok}", flush=True)
|
21 |
|
22 |
period_map = {
|
23 |
"5s": CandlesPeriod.SEC_5,
|
|
|
26 |
"5m": CandlesPeriod.FIVE_MINUTES,
|
27 |
}
|
28 |
period = period_map.get(timeframe)
|
29 |
+
print(f"[Debug] using period enum: {period}", flush=True)
|
30 |
+
|
31 |
+
# Ask for 10 candles in the buffer
|
32 |
+
list_size = 10
|
33 |
+
client.start_candles_stream(pair, list_size, period)
|
34 |
+
print(f"[Debug] started stream: pair={pair}, size={list_size}", flush=True)
|
35 |
|
36 |
+
# give it a moment to fill up
|
37 |
+
time.sleep(2)
|
38 |
|
39 |
while True:
|
40 |
candles = client.get_realtime_candles(pair)
|
41 |
+
print(f"[Debug] raw candles payload: {candles}", flush=True)
|
|
|
42 |
|
43 |
if candles:
|
44 |
+
# pick the newest timestamp key
|
|
|
45 |
latest_ts = max(candles.keys())
|
46 |
c = candles[latest_ts]
|
47 |
symbol = "↑" if c["close"] > c["open"] else "↓"
|
48 |
+
ts = (
|
49 |
+
datetime.utcfromtimestamp(latest_ts / 1000)
|
50 |
+
.replace(tzinfo=pytz.UTC)
|
51 |
+
.astimezone(pytz.timezone("Asia/Karachi"))
|
52 |
+
.strftime("%H:%M:%S")
|
53 |
+
)
|
54 |
entry = f"{ts} {symbol}"
|
55 |
state.append(entry)
|
56 |
if len(state) > 100:
|
57 |
state.pop(0)
|
58 |
+
print(f"[Debug] appended: {entry}", flush=True)
|
59 |
else:
|
60 |
+
print("[Debug] no candles received yet", flush=True)
|
61 |
+
|
62 |
+
time.sleep(1)
|
63 |
|
|
|
64 |
except Exception as e:
|
65 |
+
print(f"[Error] {e}", flush=True)
|
|
|
66 |
|
67 |
def start(pair, timeframe):
|
|
|
68 |
state.clear()
|
69 |
threading.Thread(
|
70 |
target=background_worker,
|