From 023cc64d20035367f4ea54c5b9d3391480a7277c Mon Sep 17 00:00:00 2001 From: mxwj Date: Fri, 29 Nov 2024 10:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BB=84=E5=90=88=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__pycache__/main.cpython-310.pyc | Bin 3051 -> 3056 bytes src/__pycache__/tortoises.cpython-310.pyc | Bin 2607 -> 2633 bytes src/composite/__init__.py | 0 src/composite/router.py | 17 +++ src/composite/schemas.py | 1 + src/composite/service.py | 10 ++ src/financial_reports/service.py | 1 - src/main.py | 4 +- src/models/user_strategy.py | 16 +++ .../__pycache__/config.cpython-310.pyc | Bin 1442 -> 1442 bytes src/settings/config.py | 104 +++++++++--------- src/tortoises.py | 3 +- 12 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 src/composite/__init__.py create mode 100644 src/composite/router.py create mode 100644 src/composite/schemas.py create mode 100644 src/composite/service.py create mode 100644 src/models/user_strategy.py diff --git a/src/__pycache__/main.cpython-310.pyc b/src/__pycache__/main.cpython-310.pyc index 34a5471c1c99aa5d88568501fcfdec9d88357eb0..2e7bef736132c7ae9857bd1727f0b93803cc2fdd 100644 GIT binary patch delta 861 zcmZut&ubG=5Z<@hCTr6C=#Ncm+FF}vY&L0PwbrV&cqk|$y(kKcuq>I^G-e*KC%-TA*r3*!3L2)f@m#U*A2a%GjbhFYI!4%JgH3@1sZ`uMWXs!@`4yes?p*W zArc)p^2O?TIs`H3D--B%`7k4xBn-gdF=hlbh#zB8kbsS$V^juCLbA)`s#Dbq>@!uX z7iq3Kjb{pmTXN@$OSBJ0P&wMMB0AOT5t-LBF!qMPX&7%xTg12wDM&XZV;0W9S@c&> zaTPMCI0q9=Nk_>wItSSmd7H2(JyE?5I^-aajVD_QZiC$IoNSTL$Y1(mC8xgXxD}6@ z%xQR(am}|o`XpHF@{NA6WUJ%={r0i>b^AI0mp@(JZ> zXb|P>(C}SlI(ieatDuoLRhh;2ek%K9{I5vEOgqLJwh5MJnM>3wEmL-f`vPetg*pCE zN%DojtTu$;sBbsY_)Z`mEg?R-p_i~U{}5QbJ%(I6RASV^mwA@E!qTEjbo{4@kgB!H z5_MNCdl`}IMqUhT zSoa<^EZbvYfd+)orJh%@%Pv;fOO-Nu5BIrhaGX}uIV zj1D64aQtLO_N@d-baWd-7QR4CrKRIp+iT| z+4QlBo9Txx=)RB{gdXUh4ta2K`Q?>P;e7Z!w#Kc$4=8Z<9_IPcyp% zm!O~FT^MMJZtcT882pG}2reIR`$)YHSK#Uar#^rL3^SZzjE6A77^5)eF=ojeT-)N` zBZ^2{bsnxm5@e>DiZ%r{J<59~PuMyBr@iJovSUI|wjhg+Z&fKcLN=2xIKJ#=!SQF8 z3d?J%xS~8!3W^%YWDDz=jlAqvBU-Iie}n6^qE`%4?K&S~N_4VgFA8r%ee4P7KWBdv zrrYOOYzoZrdlFCMUxNN)lsF^BSjFj}4FiK_X}CnJVwuoK_CR0+joJ%=&6)l)!PAwu ztJ5N;g=-bf&~dq;;jPAVMrid4BRXdP2y8q~xD7%@N;HdLOEb6Vm@6}Ss`cMlq*|p! z%$J(+!W9#l+Lw!B~;Nl(QgS0eGHt!)R%fgS5rLo+NIW=XZ%q{T^- zSXRZ*&B(Ho?z&v6Fvuy8& oQugOi?}Wq)$o<7Xf}i(RJaSR|Ed_%}5~P^q529e84+$rK0WmArxBvhE diff --git a/src/__pycache__/tortoises.cpython-310.pyc b/src/__pycache__/tortoises.cpython-310.pyc index 4e903d01ea1511ccf5b43f199073ba6df610bcb7..0946831abd3a7256b419f985c249f7a072ecf6b8 100644 GIT binary patch delta 73 zcmZ24a#DmhpO=@50SLBjbW4A@k@p%iqvGZ#%vH>i62(Qydb#;2sX4`ZrNya5@x>)Y ci6yD&m78PP)fpM{H@9*$GBT=7X6MoX0BGbFQ~&?~ delta 47 zcmX>pvR;HYpO=@50SL-%bkYxO JSONResponse: + """ + 查询已有多因子组合 + """ + + result = await composite_router_query_composite_service(user_id) + + return response_list_response(data=result, message="多因子组合查询成功") \ No newline at end of file diff --git a/src/composite/schemas.py b/src/composite/schemas.py new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/src/composite/schemas.py @@ -0,0 +1 @@ + diff --git a/src/composite/service.py b/src/composite/service.py new file mode 100644 index 0000000..785ef5e --- /dev/null +++ b/src/composite/service.py @@ -0,0 +1,10 @@ + +from src.models.user_strategy import * + +async def composite_router_query_composite_service( + user_id: int +) -> list: + + # 查询所有符合条件的记录并转为字典 + user_strategies = await UserStrategy.filter(user_id=user_id).values() # 转换为字典列表 + return user_strategies \ No newline at end of file diff --git a/src/financial_reports/service.py b/src/financial_reports/service.py index 7c3fee6..42f22cf 100644 --- a/src/financial_reports/service.py +++ b/src/financial_reports/service.py @@ -30,7 +30,6 @@ async def financial_reports_query_service( try: # 判空处理,如果 searchKeyword 没有值,跳过关键词筛选逻辑 if not request.searchKeyword: - # 如果 searchKeyword 为空,跳过关键词筛选逻辑 pass else: # 根据 searchKeyword 的类型选择不同的查询字段 diff --git a/src/main.py b/src/main.py index 3e2fc73..8c9f684 100644 --- a/src/main.py +++ b/src/main.py @@ -23,7 +23,8 @@ from src.models.financial_reports import FinancialReport from src.utils.update_financial_reports_spider import combined_search_and_list from src.financial_reports.router import financial_reports_router from src.utils.generate_pinyin_abbreviation import generate_pinyin_abbreviation - +from src.composite.router import composite_router + from xtquant import xtdata from src.settings.config import app_configs, settings @@ -41,6 +42,7 @@ app.include_router(xtdata_router, prefix="/getwancedata", tags=["数据接口"]) app.include_router(backtest_router, prefix="/backtest", tags=["回测接口"]) app.include_router(combine_router, prefix="/combine", tags=["组合接口"]) app.include_router(financial_reports_router, prefix="/financial-reports", tags=["财报接口"]) +app.include_router(composite_router, prefix="/composite", tags=["vacode组合接口"]) if settings.ENVIRONMENT.is_deployed: sentry_sdk.init( diff --git a/src/models/user_strategy.py b/src/models/user_strategy.py new file mode 100644 index 0000000..5d1b819 --- /dev/null +++ b/src/models/user_strategy.py @@ -0,0 +1,16 @@ +from tortoise import fields +from tortoise.models import Model + +class UserStrategy(Model): + """ + 用户多因子组合表 + """ + id = fields.IntField(pk=True) + create_time = fields.DatetimeField(null=True) + user_id = fields.IntField(null=True) + strategy_request = fields.JSONField(null=False) + strategy_name = fields.CharField(max_length=30, null=True) + deleted_stock = fields.BinaryField(null=True) + + class Meta: + table = "user_strategy" \ No newline at end of file diff --git a/src/settings/__pycache__/config.cpython-310.pyc b/src/settings/__pycache__/config.cpython-310.pyc index 280a2d629b4b7103f31b3d509518dc796b85241c..f155fe80dc3699897b8edd6e8059b4e0d6da542f 100644 GIT binary patch delta 27 hcmZ3)y@;DTpO=@50SMfmxozaOW@dEV?9Lp`1OQZ!1_l5C delta 27 hcmZ3)y@;DTpO=@50SFFOC~V}mW@b#??9Lp`1OQZ?1`GfI diff --git a/src/settings/config.py b/src/settings/config.py index 9e04aec..901200c 100644 --- a/src/settings/config.py +++ b/src/settings/config.py @@ -1,52 +1,52 @@ -from typing import Any - -from pydantic import RedisDsn, model_validator -from pydantic_settings import BaseSettings - -from src.constants import Environment - - -class Config(BaseSettings): - DATABASE_PREFIX: str = "" - DATABASE_URL: str - DATABASE_CREATE_URL: str - REDIS_URL: RedisDsn - - SITE_DOMAIN: str = "myapp.com" - - ENVIRONMENT: Environment = Environment.PRODUCTION - - SENTRY_DSN: str | None = None - - CORS_ORIGINS: list[str] - CORS_ORIGINS_REGEX: str | None = None - CORS_HEADERS: list[str] - - APP_VERSION: str = "1" - APP_ROUTER_PREFIX: str = "/api/v1" - - SHOULD_SEND_SMS: bool = False - - @model_validator(mode="after") - def validate_sentry_non_local(self) -> "Config": - if self.ENVIRONMENT.is_deployed and not self.SENTRY_DSN: - raise ValueError("Sentry is not set") - - return self - - -settings = Config() - -# fastapi/applications.py -app_configs: dict[str, Any] = { - "title": "Wance QMT API", - "root_path": settings.APP_ROUTER_PREFIX, - "docs_url": "/api/docs", -} - -# app_configs['debug'] = True -# if settings.ENVIRONMENT.is_deployed: -# app_configs["root_path"] = f"/v{settings.APP_VERSION}" -# -# if not settings.ENVIRONMENT.is_debug: -# app_configs["openapi_url"] = None # hide docs +from typing import Any + +from pydantic import RedisDsn, model_validator +from pydantic_settings import BaseSettings + +from src.constants import Environment + + +class Config(BaseSettings): + DATABASE_PREFIX: str = "" + DATABASE_URL: str + DATABASE_CREATE_URL: str + REDIS_URL: RedisDsn + + SITE_DOMAIN: str = "myapp.com" + + ENVIRONMENT: Environment = Environment.PRODUCTION + + SENTRY_DSN: str | None = None + + CORS_ORIGINS: list[str] + CORS_ORIGINS_REGEX: str | None = None + CORS_HEADERS: list[str] + + APP_VERSION: str = "1" + APP_ROUTER_PREFIX: str = "/api/v1" + + SHOULD_SEND_SMS: bool = False + + @model_validator(mode="after") + def validate_sentry_non_local(self) -> "Config": + if self.ENVIRONMENT.is_deployed and not self.SENTRY_DSN: + raise ValueError("Sentry is not set") + + return self + + +settings = Config() + +# fastapi/applications.py +app_configs: dict[str, Any] = { + "title": "Wance QMT API", + "root_path": settings.APP_ROUTER_PREFIX, + "docs_url": "/api/docs", +} + +# app_configs['debug'] = True +# if settings.ENVIRONMENT.is_deployed: +# app_configs["root_path"] = f"/v{settings.APP_VERSION}" +# +# if not settings.ENVIRONMENT.is_debug: +# app_configs["openapi_url"] = None # hide docs diff --git a/src/tortoises.py b/src/tortoises.py index 1ec0d14..0d4fb8b 100644 --- a/src/tortoises.py +++ b/src/tortoises.py @@ -72,7 +72,8 @@ models = [ "src.models.stock_hu_shen300", "src.models.stock_zhong_zheng_500", "src.models.stock_guo_zheng_2000", - "src.models.stock_hu_shen_jing_a" + "src.models.stock_hu_shen_jing_a", + "src.models.user_strategy" ]