Spaces:
Running
Running
camphong24032002
commited on
Commit
·
4b8fd9c
1
Parent(s):
081dce1
fix: update data
Browse files- routes/data.py +4 -2
- services/indicator.py +12 -7
routes/data.py
CHANGED
@@ -18,7 +18,8 @@ router = APIRouter()
|
|
18 |
status_code=status.HTTP_200_OK
|
19 |
)
|
20 |
async def update_daily_price():
|
21 |
-
|
|
|
22 |
|
23 |
|
24 |
@router.get(
|
@@ -36,7 +37,8 @@ async def update_entire_price():
|
|
36 |
status_code=status.HTTP_200_OK
|
37 |
)
|
38 |
async def update_daily_rsi():
|
39 |
-
|
|
|
40 |
|
41 |
|
42 |
@router.get(
|
|
|
18 |
status_code=status.HTTP_200_OK
|
19 |
)
|
20 |
async def update_daily_price():
|
21 |
+
asyncio.create_task(Indicator.update_daily_price())
|
22 |
+
return {"message": "Updating"}
|
23 |
|
24 |
|
25 |
@router.get(
|
|
|
37 |
status_code=status.HTTP_200_OK
|
38 |
)
|
39 |
async def update_daily_rsi():
|
40 |
+
asyncio.create_task(Indicator.update_daily_rsi())
|
41 |
+
return {"message": "Updating"}
|
42 |
|
43 |
|
44 |
@router.get(
|
services/indicator.py
CHANGED
@@ -83,7 +83,10 @@ class Indicator:
|
|
83 |
collection.find_one(sort=[("_id", DESCENDING)])
|
84 |
ret = None
|
85 |
if newest_record["time"] != last_date:
|
86 |
-
|
|
|
|
|
|
|
87 |
record = {}
|
88 |
record["time"] = last_date
|
89 |
values = []
|
@@ -244,7 +247,7 @@ class Indicator:
|
|
244 |
uri = os.environ.get("MONGODB_URI")
|
245 |
client = MongoClient(uri)
|
246 |
database = client.get_database("data")
|
247 |
-
collection = database.get_collection("
|
248 |
tmp_df = longterm_ohlc_data("FPT",
|
249 |
start_date,
|
250 |
end_date,
|
@@ -258,13 +261,15 @@ class Indicator:
|
|
258 |
newest_record = \
|
259 |
collection.find_one(sort=[("_id", DESCENDING)])
|
260 |
if newest_record["time"] != last_date:
|
261 |
-
lst_symbols = list(newest_record
|
262 |
record = {}
|
263 |
record["time"] = last_date
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
268 |
collection.insert_one(record)
|
269 |
ret = {"message": "Updated data."}
|
270 |
else:
|
|
|
83 |
collection.find_one(sort=[("_id", DESCENDING)])
|
84 |
ret = None
|
85 |
if newest_record["time"] != last_date:
|
86 |
+
rsi_collection = database.get_collection("rsi")
|
87 |
+
tmp_record = \
|
88 |
+
rsi_collection.find_one(sort=[("_id", DESCENDING)])
|
89 |
+
lst_symbols = list(tmp_record.keys())[2:]
|
90 |
record = {}
|
91 |
record["time"] = last_date
|
92 |
values = []
|
|
|
247 |
uri = os.environ.get("MONGODB_URI")
|
248 |
client = MongoClient(uri)
|
249 |
database = client.get_database("data")
|
250 |
+
collection = database.get_collection("rsi")
|
251 |
tmp_df = longterm_ohlc_data("FPT",
|
252 |
start_date,
|
253 |
end_date,
|
|
|
261 |
newest_record = \
|
262 |
collection.find_one(sort=[("_id", DESCENDING)])
|
263 |
if newest_record["time"] != last_date:
|
264 |
+
lst_symbols = list(newest_record.keys())[2:]
|
265 |
record = {}
|
266 |
record["time"] = last_date
|
267 |
+
for batch_idx in range(10):
|
268 |
+
str_symbols = ','.join(
|
269 |
+
lst_symbols[batch_idx*10:(batch_idx+1)*10])
|
270 |
+
data = requests.get('https://apipubaws.tcbs.com.vn/stock-insight/v1/stock/second-tc-price?tickers={}'.format(str_symbols)).json()
|
271 |
+
for i in data["data"]:
|
272 |
+
record[i["t"]] = i["rsi"]
|
273 |
collection.insert_one(record)
|
274 |
ret = {"message": "Updated data."}
|
275 |
else:
|