Spaces:
Running
Running
camphong24032002
commited on
Commit
·
0f1a597
1
Parent(s):
4b8fd9c
fix: new approach to update
Browse files- services/indicator.py +30 -21
services/indicator.py
CHANGED
@@ -7,8 +7,8 @@ from pymongo import MongoClient, ASCENDING, DESCENDING
|
|
7 |
from utils.config import DATE_FORMAT, VN100_URL
|
8 |
from .utils import Utility
|
9 |
import os
|
10 |
-
|
11 |
-
|
12 |
|
13 |
PREFIX = "https://www.hsx.vn/Modules/Chart/StaticChart/"
|
14 |
TIME = {"1m": 2, "3m": 3, "6m": 4, "1y": 5, "2y": 6, "5y": 7}
|
@@ -53,7 +53,8 @@ class Indicator:
|
|
53 |
def update_daily_price() -> dict:
|
54 |
global updating_price
|
55 |
if updating_price:
|
56 |
-
|
|
|
57 |
updating_price = True
|
58 |
datetime_now = datetime.utcnow()
|
59 |
hour = datetime_now.hour
|
@@ -76,7 +77,8 @@ class Indicator:
|
|
76 |
"stock").reset_index(drop=True)
|
77 |
if tmp_df.shape[0] == 0:
|
78 |
updating_price = False
|
79 |
-
|
|
|
80 |
tmp_df = tmp_df.iloc[-1]
|
81 |
last_date = str(tmp_df["time"])
|
82 |
newest_record = \
|
@@ -107,14 +109,14 @@ class Indicator:
|
|
107 |
values.append(df.to_dict())
|
108 |
record["value"] = values
|
109 |
collection.insert_one(record)
|
110 |
-
ret =
|
111 |
else:
|
112 |
-
ret =
|
113 |
updating_price = False
|
114 |
-
|
115 |
except Exception as e:
|
116 |
updating_price = False
|
117 |
-
|
118 |
|
119 |
@staticmethod
|
120 |
def update_entire_price() -> None:
|
@@ -228,10 +230,12 @@ class Indicator:
|
|
228 |
)
|
229 |
|
230 |
@staticmethod
|
231 |
-
def update_daily_rsi() -> None:
|
232 |
global updating_rsi
|
233 |
if updating_rsi:
|
234 |
-
|
|
|
|
|
235 |
updating_rsi = True
|
236 |
datetime_now = datetime.utcnow()
|
237 |
hour = datetime_now.hour
|
@@ -255,7 +259,9 @@ class Indicator:
|
|
255 |
"stock").reset_index(drop=True)
|
256 |
if tmp_df.shape[0] == 0:
|
257 |
updating_rsi = False
|
258 |
-
|
|
|
|
|
259 |
tmp_df = tmp_df.iloc[-1]
|
260 |
last_date = str(tmp_df["time"])
|
261 |
newest_record = \
|
@@ -271,16 +277,16 @@ class Indicator:
|
|
271 |
for i in data["data"]:
|
272 |
record[i["t"]] = i["rsi"]
|
273 |
collection.insert_one(record)
|
274 |
-
ret =
|
275 |
else:
|
276 |
-
ret =
|
277 |
else:
|
278 |
-
ret =
|
279 |
updating_rsi = False
|
280 |
-
|
281 |
except Exception as e:
|
282 |
updating_rsi = False
|
283 |
-
|
284 |
|
285 |
@staticmethod
|
286 |
def update_entire_rsi() -> None:
|
@@ -380,7 +386,8 @@ class Indicator:
|
|
380 |
async def update_entire_macd() -> None:
|
381 |
global updating_macd
|
382 |
if updating_macd:
|
383 |
-
|
|
|
384 |
updating_macd = True
|
385 |
datetime_now = datetime.utcnow()
|
386 |
hour = datetime_now.hour
|
@@ -390,12 +397,14 @@ class Indicator:
|
|
390 |
lst_symbols = symbol_dict["symbols"]
|
391 |
if weekday < 5 and hour < 12:
|
392 |
updating_macd = False
|
393 |
-
|
|
|
394 |
get_time = True
|
395 |
lst_values = {}
|
396 |
if len(lst_symbols) != 100:
|
397 |
updating_macd = False
|
398 |
-
|
|
|
399 |
cnt = 0
|
400 |
for symbol in lst_symbols:
|
401 |
cnt += 1
|
@@ -420,10 +429,10 @@ class Indicator:
|
|
420 |
collection.drop()
|
421 |
collection.insert_many(records)
|
422 |
updating_macd = False
|
423 |
-
|
424 |
except Exception as e:
|
425 |
updating_macd = False
|
426 |
-
|
427 |
|
428 |
@staticmethod
|
429 |
def get_macd(
|
|
|
7 |
from utils.config import DATE_FORMAT, VN100_URL
|
8 |
from .utils import Utility
|
9 |
import os
|
10 |
+
from dotenv import load_dotenv
|
11 |
+
load_dotenv()
|
12 |
|
13 |
PREFIX = "https://www.hsx.vn/Modules/Chart/StaticChart/"
|
14 |
TIME = {"1m": 2, "3m": 3, "6m": 4, "1y": 5, "2y": 6, "5y": 7}
|
|
|
53 |
def update_daily_price() -> dict:
|
54 |
global updating_price
|
55 |
if updating_price:
|
56 |
+
print("The data has been updating.")
|
57 |
+
return
|
58 |
updating_price = True
|
59 |
datetime_now = datetime.utcnow()
|
60 |
hour = datetime_now.hour
|
|
|
77 |
"stock").reset_index(drop=True)
|
78 |
if tmp_df.shape[0] == 0:
|
79 |
updating_price = False
|
80 |
+
print("There is no data to updated")
|
81 |
+
return
|
82 |
tmp_df = tmp_df.iloc[-1]
|
83 |
last_date = str(tmp_df["time"])
|
84 |
newest_record = \
|
|
|
109 |
values.append(df.to_dict())
|
110 |
record["value"] = values
|
111 |
collection.insert_one(record)
|
112 |
+
ret = "Updated data."
|
113 |
else:
|
114 |
+
ret = "The data is up to date."
|
115 |
updating_price = False
|
116 |
+
print(ret)
|
117 |
except Exception as e:
|
118 |
updating_price = False
|
119 |
+
print(f"Caught error {e}.")
|
120 |
|
121 |
@staticmethod
|
122 |
def update_entire_price() -> None:
|
|
|
230 |
)
|
231 |
|
232 |
@staticmethod
|
233 |
+
async def update_daily_rsi() -> None:
|
234 |
global updating_rsi
|
235 |
if updating_rsi:
|
236 |
+
print("The data has been updating.")
|
237 |
+
return
|
238 |
+
# return {"message": "The data has been updating."}
|
239 |
updating_rsi = True
|
240 |
datetime_now = datetime.utcnow()
|
241 |
hour = datetime_now.hour
|
|
|
259 |
"stock").reset_index(drop=True)
|
260 |
if tmp_df.shape[0] == 0:
|
261 |
updating_rsi = False
|
262 |
+
print("The market is in trading.")
|
263 |
+
return
|
264 |
+
# return {"message": "The market is in trading."}
|
265 |
tmp_df = tmp_df.iloc[-1]
|
266 |
last_date = str(tmp_df["time"])
|
267 |
newest_record = \
|
|
|
277 |
for i in data["data"]:
|
278 |
record[i["t"]] = i["rsi"]
|
279 |
collection.insert_one(record)
|
280 |
+
ret = "Updated data."
|
281 |
else:
|
282 |
+
ret = "The data is up to date."
|
283 |
else:
|
284 |
+
ret = "The market is in trading."
|
285 |
updating_rsi = False
|
286 |
+
print(ret)
|
287 |
except Exception as e:
|
288 |
updating_rsi = False
|
289 |
+
print(f"Caught error {e}.")
|
290 |
|
291 |
@staticmethod
|
292 |
def update_entire_rsi() -> None:
|
|
|
386 |
async def update_entire_macd() -> None:
|
387 |
global updating_macd
|
388 |
if updating_macd:
|
389 |
+
print("The data has been updating.")
|
390 |
+
return
|
391 |
updating_macd = True
|
392 |
datetime_now = datetime.utcnow()
|
393 |
hour = datetime_now.hour
|
|
|
397 |
lst_symbols = symbol_dict["symbols"]
|
398 |
if weekday < 5 and hour < 12:
|
399 |
updating_macd = False
|
400 |
+
print("The market is in trading.")
|
401 |
+
return
|
402 |
get_time = True
|
403 |
lst_values = {}
|
404 |
if len(lst_symbols) != 100:
|
405 |
updating_macd = False
|
406 |
+
print("Not enough 100 symbols.")
|
407 |
+
return
|
408 |
cnt = 0
|
409 |
for symbol in lst_symbols:
|
410 |
cnt += 1
|
|
|
429 |
collection.drop()
|
430 |
collection.insert_many(records)
|
431 |
updating_macd = False
|
432 |
+
print("Updated data.")
|
433 |
except Exception as e:
|
434 |
updating_macd = False
|
435 |
+
print(f"Caught error {e}.")
|
436 |
|
437 |
@staticmethod
|
438 |
def get_macd(
|