db2_hj3415 0.1.8__tar.gz → 0.1.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/PKG-INFO +1 -1
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/_ops.py +21 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/c108.py +2 -2
- db2_hj3415-0.1.10/db2_hj3415/nfs/dart.py +101 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/models.py +4 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/pyproject.toml +1 -1
- db2_hj3415-0.1.8/db2_hj3415/nfs/dart.py +0 -27
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/README.md +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/cli/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/cli/db.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/common/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/common/connection.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/common/db_ops.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/common/utils.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/_ops.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/aud.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/chf.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/gbond3y.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/gold.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/kosdaq.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/kospi.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/silver.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/sp500.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/usdidx.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/usdkrw.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/mi/wti.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/_c10346.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/c101.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/c103.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/c104.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/nfs/c106.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/__init__.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/_ops.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/blue.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/growth.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/mil.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/models.py +0 -0
- {db2_hj3415-0.1.8 → db2_hj3415-0.1.10}/db2_hj3415/valuation/red.py +0 -0
@@ -1,5 +1,8 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
1
3
|
from motor.motor_asyncio import AsyncIOMotorClient
|
2
4
|
from db2_hj3415.nfs import DB_NAME, connection
|
5
|
+
from db2_hj3415.nfs.models import CodeName
|
3
6
|
|
4
7
|
|
5
8
|
async def get_all_codes(client: AsyncIOMotorClient) -> list[str]:
|
@@ -47,6 +50,24 @@ def get_all_codes_sync() -> list[str]:
|
|
47
50
|
connection.close_mongo_client_sync()
|
48
51
|
|
49
52
|
|
53
|
+
async def get_all_codes_names(client: AsyncIOMotorClient, sort_by:Literal['종목명', '코드']='종목명') -> list[CodeName]:
|
54
|
+
collection = client[DB_NAME]['c101']
|
55
|
+
cursor = collection.find({}, {"코드": 1, "종목명": 1, "_id": 0}).sort(sort_by, 1)
|
56
|
+
result = []
|
57
|
+
async for doc in cursor:
|
58
|
+
result.append(CodeName(**doc))
|
59
|
+
return result
|
60
|
+
|
61
|
+
|
62
|
+
def get_all_codes_names_sync(sort_by:Literal['종목명', '코드']='종목명') -> list[CodeName] | None:
|
63
|
+
client = connection.get_mongo_client_sync()
|
64
|
+
try:
|
65
|
+
collection = client[DB_NAME]['c101']
|
66
|
+
cursor = collection.find({}, {"코드": 1, "종목명": 1, "_id": 0}).sort(sort_by, 1)
|
67
|
+
return [CodeName(**doc) for doc in cursor]
|
68
|
+
finally:
|
69
|
+
connection.close_mongo_client_sync()
|
70
|
+
|
50
71
|
async def delete_code_from_all_collections(code: str, client: AsyncIOMotorClient) -> dict[str, int]:
|
51
72
|
db = client[DB_NAME]
|
52
73
|
|
@@ -75,14 +75,14 @@ async def save_many(many_data: dict[str, pd.DataFrame], client: AsyncIOMotorClie
|
|
75
75
|
return total_result
|
76
76
|
|
77
77
|
|
78
|
-
async def get_latest(code: str, client: AsyncIOMotorClient, days:int =
|
78
|
+
async def get_latest(code: str, client: AsyncIOMotorClient, days:int = 60) -> list[C108]:
|
79
79
|
"""
|
80
80
|
최근 N일 이내의 C108 리포트 도큐먼트를 조회합니다.
|
81
81
|
|
82
82
|
Args:
|
83
83
|
code (str): 종목 코드 (예: "005930").
|
84
84
|
client (AsyncIOMotorClient): 비동기 MongoDB 클라이언트.
|
85
|
-
days (int, optional): 현재 시점에서 며칠 전까지의 데이터를 조회할지 설정합니다. 기본값은
|
85
|
+
days (int, optional): 현재 시점에서 며칠 전까지의 데이터를 조회할지 설정합니다. 기본값은 60일.
|
86
86
|
|
87
87
|
Returns:
|
88
88
|
list[C108]: 조건에 해당하는 C108 도큐먼트 리스트. 일치하는 문서가 없을 경우 빈 리스트를 반환합니다.
|
@@ -0,0 +1,101 @@
|
|
1
|
+
from motor.motor_asyncio import AsyncIOMotorClient
|
2
|
+
from pymongo import InsertOne, DESCENDING
|
3
|
+
from db2_hj3415.nfs import Dart, DB_NAME, get_collection
|
4
|
+
from datetime import datetime, timezone, timedelta
|
5
|
+
|
6
|
+
COL_NAME = "dart"
|
7
|
+
|
8
|
+
async def save_many(many_data: list[Dart], client: AsyncIOMotorClient) -> dict:
|
9
|
+
if not many_data:
|
10
|
+
return {"inserted_count": 0, "skipped": 0}
|
11
|
+
|
12
|
+
collection = get_collection(client, DB_NAME, COL_NAME)
|
13
|
+
|
14
|
+
# unique index 보장용 (이미 설정되었는지 확인)
|
15
|
+
await collection.create_index("rcept_no", unique=True)
|
16
|
+
|
17
|
+
ops = []
|
18
|
+
skipped = 0
|
19
|
+
|
20
|
+
for item in many_data:
|
21
|
+
doc = item.model_dump(mode="json", exclude={"id"}) # _id는 제외
|
22
|
+
ops.append(InsertOne(doc))
|
23
|
+
|
24
|
+
try:
|
25
|
+
result = await collection.bulk_write(ops, ordered=False)
|
26
|
+
return {"inserted_count": result.inserted_count, "skipped": skipped}
|
27
|
+
except Exception as e:
|
28
|
+
return {"error": str(e)}
|
29
|
+
|
30
|
+
|
31
|
+
async def get_data_last_n_days(code: str, client: AsyncIOMotorClient, days:int = 30) -> list[Dart]:
|
32
|
+
"""
|
33
|
+
지정한 종목 코드(code)에 대해 최근 N일(days) 동안의 DART 데이터를 비동기로 조회합니다.
|
34
|
+
|
35
|
+
MongoDB 컬렉션에서 날짜 기준으로 N일 이전(cutoff) 이후의 문서들을 조회하며,
|
36
|
+
결과는 최신 날짜순(DESCENDING)으로 정렬됩니다.
|
37
|
+
|
38
|
+
Parameters:
|
39
|
+
code (str): 조회할 종목 코드 (예: '005930').
|
40
|
+
client (AsyncIOMotorClient): 비동기 MongoDB 클라이언트.
|
41
|
+
days (int, optional): 며칠 전까지의 데이터를 가져올지 설정 (기본값: 30일).
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
list[Dart]: Dart Pydantic 모델의 리스트. 데이터가 없으면 빈 리스트 반환.
|
45
|
+
"""
|
46
|
+
collection = get_collection(client, DB_NAME, COL_NAME)
|
47
|
+
now = datetime.now(timezone.utc)
|
48
|
+
cutoff = now - timedelta(days=days)
|
49
|
+
|
50
|
+
cursor = collection.find(
|
51
|
+
{
|
52
|
+
"코드": code,
|
53
|
+
"날짜": {"$gte": cutoff}
|
54
|
+
}
|
55
|
+
).sort("날짜", DESCENDING)
|
56
|
+
|
57
|
+
docs = await cursor.to_list(length=None)
|
58
|
+
if not docs:
|
59
|
+
return []
|
60
|
+
else:
|
61
|
+
darts = []
|
62
|
+
for doc in docs:
|
63
|
+
doc["_id"] = str(doc["_id"])
|
64
|
+
darts.append(Dart(**doc))
|
65
|
+
return darts
|
66
|
+
|
67
|
+
|
68
|
+
async def get_data_today(client: AsyncIOMotorClient) -> list[Dart]:
|
69
|
+
"""
|
70
|
+
오늘 날짜의 DART 데이터를 비동기로 조회합니다.
|
71
|
+
|
72
|
+
MongoDB 컬렉션에서 오늘 날짜에 해당하는 모든 종목의 문서를 조회하며,
|
73
|
+
결과는 '날짜' 필드를 기준으로 내림차순 정렬됩니다.
|
74
|
+
|
75
|
+
Parameters:
|
76
|
+
client (AsyncIOMotorClient): 비동기 MongoDB 클라이언트.
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
List[Dart]: Dart Pydantic 모델의 리스트. 없으면 빈 리스트.
|
80
|
+
"""
|
81
|
+
collection = get_collection(client, DB_NAME, COL_NAME)
|
82
|
+
|
83
|
+
# 오늘 00:00 ~ 내일 00:00 사이의 UTC 기준
|
84
|
+
now = datetime.now(timezone.utc)
|
85
|
+
start_of_day = datetime(now.year, now.month, now.day, tzinfo=timezone.utc)
|
86
|
+
start_of_next_day = start_of_day + timedelta(days=1)
|
87
|
+
|
88
|
+
cursor = collection.find(
|
89
|
+
{
|
90
|
+
"날짜": {
|
91
|
+
"$gte": start_of_day,
|
92
|
+
"$lt": start_of_next_day
|
93
|
+
}
|
94
|
+
}
|
95
|
+
).sort("날짜", DESCENDING)
|
96
|
+
|
97
|
+
docs = await cursor.to_list(length=None)
|
98
|
+
if not docs:
|
99
|
+
return []
|
100
|
+
|
101
|
+
return [Dart(**{**doc, "_id": str(doc["_id"])}) for doc in docs]
|
@@ -1,6 +1,10 @@
|
|
1
1
|
from pydantic import BaseModel, Field, field_serializer, ConfigDict, field_validator
|
2
2
|
from datetime import datetime
|
3
3
|
|
4
|
+
class CodeName(BaseModel):
|
5
|
+
코드: str
|
6
|
+
종목명: str | None
|
7
|
+
|
4
8
|
class C101(BaseModel):
|
5
9
|
id: str | None = Field(default=None, alias="_id")
|
6
10
|
코드: str
|
@@ -1,27 +0,0 @@
|
|
1
|
-
from motor.motor_asyncio import AsyncIOMotorClient
|
2
|
-
from pymongo import InsertOne
|
3
|
-
from db2_hj3415.nfs import Dart, DB_NAME, get_collection
|
4
|
-
|
5
|
-
COL_NAME = "dart"
|
6
|
-
|
7
|
-
async def save_many(many_data: list[Dart], client: AsyncIOMotorClient) -> dict:
|
8
|
-
if not many_data:
|
9
|
-
return {"inserted_count": 0, "skipped": 0}
|
10
|
-
|
11
|
-
collection = get_collection(client, DB_NAME, COL_NAME)
|
12
|
-
|
13
|
-
# unique index 보장용 (이미 설정되었는지 확인)
|
14
|
-
await collection.create_index("rcept_no", unique=True)
|
15
|
-
|
16
|
-
ops = []
|
17
|
-
skipped = 0
|
18
|
-
|
19
|
-
for item in many_data:
|
20
|
-
doc = item.model_dump(mode="json", exclude={"id"}) # _id는 제외
|
21
|
-
ops.append(InsertOne(doc))
|
22
|
-
|
23
|
-
try:
|
24
|
-
result = await collection.bulk_write(ops, ordered=False)
|
25
|
-
return {"inserted_count": result.inserted_count, "skipped": skipped}
|
26
|
-
except Exception as e:
|
27
|
-
return {"error": str(e)}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|