From 2f6668c2674aa41bc8cc54152f68e8c169420a3e Mon Sep 17 00:00:00 2001 From: foolcage <5533061@qq.com> Date: Tue, 11 Jun 2024 23:14:31 +0800 Subject: [PATCH] Fix Out of range float values are not JSON compliant issue --- requirements.txt | 3 ++- src/zvt/informer/inform_utils.py | 28 +++++++++++++++------------- src/zvt/server.py | 3 ++- src/zvt/trading/trading_service.py | 8 ++++---- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/requirements.txt b/requirements.txt index f47fdef4..b0158435 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,5 @@ scikit-learn==1.2.1 fastapi==0.110.0 fastapi-pagination==0.12.23 apscheduler==3.10.4 -eastmoneypy==0.1.7 \ No newline at end of file +eastmoneypy==0.1.7 +orjson==3.10.3 \ No newline at end of file diff --git a/src/zvt/informer/inform_utils.py b/src/zvt/informer/inform_utils.py index a4fe4565..a99f0459 100644 --- a/src/zvt/informer/inform_utils.py +++ b/src/zvt/informer/inform_utils.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- import eastmoneypy +import requests from zvt import zvt_config from zvt.contract.api import get_entities from zvt.informer import EmailInformer -import requests - def inform_email(entity_ids, entity_type, target_date, title, provider): msg = "no targets" @@ -22,19 +21,22 @@ def inform_email(entity_ids, entity_type, target_date, title, provider): def add_to_eastmoney(codes, group, entity_type="stock", over_write=True): with requests.Session() as session: - codes = list(set(codes)) - if over_write: - try: - eastmoneypy.del_group(group_name=group, session=session) - except: - pass - try: - eastmoneypy.create_group(group_name=group, session=session) - except: - pass - group_id = eastmoneypy.get_group_id(group, session=session) + need_create_group = False + + if not group_id: + need_create_group = True + + if group_id and over_write: + eastmoneypy.del_group(group_name=group, session=session) + need_create_group = True + + if need_create_group: + result = eastmoneypy.create_group(group_name=group, session=session) + group_id = result["gid"] + + codes = list(set(codes)) for code in codes: eastmoneypy.add_to_group(code=code, entity_type=entity_type, group_id=group_id, session=session) diff --git a/src/zvt/server.py b/src/zvt/server.py index 287c9d8e..40140a37 100644 --- a/src/zvt/server.py +++ b/src/zvt/server.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import uvicorn from fastapi import FastAPI +from fastapi.responses import ORJSONResponse from fastapi_pagination import add_pagination from zvt.rest.data import data_router @@ -11,7 +12,7 @@ from zvt.sched.sched import zvt_scheduler -app = FastAPI() +app = FastAPI(default_response_class=ORJSONResponse) origins = ["*"] diff --git a/src/zvt/trading/trading_service.py b/src/zvt/trading/trading_service.py index 7be167c5..cff41bdf 100644 --- a/src/zvt/trading/trading_service.py +++ b/src/zvt/trading/trading_service.py @@ -146,12 +146,10 @@ def query_stock_quotes(query_stock_quote_model: QueryStockQuoteModel): order = eval(f"StockQuote.{query_stock_quote_model.order_by_field}.{query_stock_quote_model.order_by_type.value}()") - quotes = StockQuote.query_data( - order=order, entity_ids=entity_ids, limit=query_stock_quote_model.limit, return_type="dict" + df = StockQuote.query_data( + order=order, entity_ids=entity_ids, limit=query_stock_quote_model.limit, return_type="df" ) - df = pd.DataFrame.from_records(data=quotes) - def set_tags(quote): entity_id = quote["entity_id"] main_tag = entity_tags_map.get(entity_id, {}).get("main_tag", None) @@ -167,6 +165,8 @@ def set_tags(quote): limit_up_count = df["is_limit_up"].sum() limit_down_count = df["is_limit_down"].sum() + quotes = df.to_dict(orient="records") + result = { "up_count": up_count, "down_count": down_count,