Skip to content

Commit

Permalink
Fix Out of range float values are not JSON compliant issue
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Jun 11, 2024
1 parent 226e797 commit 2f6668c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
eastmoneypy==0.1.7
orjson==3.10.3
28 changes: 15 additions & 13 deletions src/zvt/informer/inform_utils.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion src/zvt/server.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +12,7 @@

from zvt.sched.sched import zvt_scheduler

app = FastAPI()
app = FastAPI(default_response_class=ORJSONResponse)

origins = ["*"]

Expand Down
8 changes: 4 additions & 4 deletions src/zvt/trading/trading_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 2f6668c

Please sign in to comment.