Skip to content

Commit

Permalink
Add build_default_query_stock_quote_setting to init tag system script
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Aug 20, 2024
1 parent 7e9bad6 commit b4da641
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 40 deletions.
17 changes: 9 additions & 8 deletions README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ zvt
- 初始化tag系统

运行以下脚本:
运行以下脚本:

https://github.com/zvtvz/zvt/blob/master/src/zvt/tasks/init_tag_system.py
https://github.com/zvtvz/zvt/blob/master/src/zvt/tasks/stock_pool_runner.py
Expand Down Expand Up @@ -87,16 +87,17 @@ open [http://127.0.0.1:8090/docs](http://127.0.0.1:8090/docs)

前端代码: https://github.com/zvtvz/zvt_ui

https://github.com/zvtvz/zvt_ui/blob/main/src/services/index.ts
设置 {your server IP}
修改前端环境文件:
https://github.com/zvtvz/zvt_ui/blob/main/.env

```typescript
const instance = createInstance<keyof typeof apis>({
domain: 'http://{your server IP}:8090',
apis,
});
设置 {your server IP}, 即zvt_server服务的地址

```text
NEXT_PUBLIC_SERVER = {your server IP}
```

然后参考前端的readme启动前端服务

打开 [http://127.0.0.1:3000/trade](http://127.0.0.1:3000/trade)

<p align="center"><img src='https://raw.githubusercontent.com/zvtvz/zvt/master/docs/imgs/big-picture.jpg'/></p>
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ open [http://127.0.0.1:8050/](http://127.0.0.1:8050/)
- Init tag system

run following scripts:
run following scripts:

https://github.com/zvtvz/zvt/blob/master/src/zvt/tasks/init_tag_system.py
https://github.com/zvtvz/zvt/blob/master/src/zvt/tasks/stock_pool_runner.py
https://github.com/zvtvz/zvt/blob/master/src/zvt/tasks/qmt_data_runner.py
Expand All @@ -75,14 +76,17 @@ open [http://127.0.0.1:8090/docs](http://127.0.0.1:8090/docs)

Front end source code: https://github.com/zvtvz/zvt_ui

Set {your server IP} in https://github.com/zvtvz/zvt_ui/blob/main/src/services/index.ts
```typescript
const instance = createInstance<keyof typeof apis>({
domain: 'http://{your server IP}:8090',
apis,
});
Change the env file:
https://github.com/zvtvz/zvt_ui/blob/main/.env

Set {your server IP} to zvt_server IP

```text
NEXT_PUBLIC_SERVER = {your server IP}
```

Then refer to the frontend's README to start the frontend service.

open [http://127.0.0.1:3000/trade](http://127.0.0.1:3000/trade)

<p align="center"><img src='https://raw.githubusercontent.com/zvtvz/zvt/master/docs/imgs/big-picture.jpg'/></p>
Expand Down
14 changes: 5 additions & 9 deletions src/zvt/factors/top_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,11 @@ def update_vol_up():
print(f"finish {target_date}")


def compute_top_stocks(provider="em", target_date=None):
if target_date:
start = target_date
else:
latest = TopStocks.query_data(limit=1, order=TopStocks.timestamp.desc(), return_type="domain")
if latest:
start = date_time_by_interval(to_time_str(latest[0].timestamp, fmt=TIME_FORMAT_DAY))
else:
start = "2018-01-01"
def compute_top_stocks(provider="em", start="2024-01-01"):
latest = TopStocks.query_data(limit=1, order=TopStocks.timestamp.desc(), return_type="domain")
if latest:
start = date_time_by_interval(to_time_str(latest[0].timestamp, fmt=TIME_FORMAT_DAY))

trade_days = get_trade_dates(start=start, end=today())

for target_date in trade_days:
Expand Down
8 changes: 6 additions & 2 deletions src/zvt/recorders/em/em_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,14 @@ def get_tradable_list(
return pd.concat(dfs)


def get_block_stocks(block_id, name=""):
def get_block_stocks(block_id, name="", session=None):
entity_type, exchange, code = decode_entity_id(block_id)
category_stocks_url = f"http://48.push2.eastmoney.com/api/qt/clist/get?cb=jQuery11240710111145777397_{now_timestamp() - 1}&pn=1&pz=1000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=4668014655929990|0|1|0|web&fid=f3&fs=b:{code}+f:!50&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152,f45&_={now_timestamp()}"
resp = requests.get(category_stocks_url, headers=DEFAULT_HEADER)
if session:
resp = session.get(category_stocks_url, headers=DEFAULT_HEADER)
else:
resp = requests.get(category_stocks_url, headers=DEFAULT_HEADER)

data = json_callback_param(resp.text)["data"]
the_list = []
if data:
Expand Down
2 changes: 2 additions & 0 deletions src/zvt/tasks/init_tag_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from zvt.domain import Block, BlockStock, Stock
from zvt.tag.tag_service import build_default_main_tag, build_default_sub_tags
from zvt.tag.tag_utils import build_initial_stock_pool_info, build_initial_main_tag_info, build_initial_sub_tag_info
from zvt.trading.trading_service import build_default_query_stock_quote_setting

if __name__ == "__main__":
# init tag info
build_initial_stock_pool_info()
build_initial_main_tag_info()
build_initial_sub_tag_info()
build_default_query_stock_quote_setting()

Stock.record_data(provider="em")
Block.record_data(provider="em", sleeping_time=0)
Expand Down
8 changes: 2 additions & 6 deletions src/zvt/tasks/stock_pool_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from apscheduler.schedulers.background import BackgroundScheduler

from zvt import zvt_config
from zvt.api.kdata import get_latest_kdata_date
from zvt.api.selector import get_entity_ids_by_filter
from zvt.contract import AdjustType
from zvt.domain import (
Stock,
Stock1dHfqKdata,
Expand Down Expand Up @@ -118,14 +116,12 @@ def record_data_and_build_stock_pools():
# 获取 涨停 指数 板块(概念) 个股行情数据
record_stock_data()

target_date = get_latest_kdata_date(provider="em", entity_type="stock", adjust_type=AdjustType.hfq)

# 计算短期/中期最强 放量突破年线半年线个股
compute_top_stocks(target_date=target_date)
compute_top_stocks()
# 放入股票池
build_system_stock_pools()
for stock_pool_name in ["main_line", "vol_up", "大局"]:
build_stock_pool_tag_stats(stock_pool_name=stock_pool_name, target_date=target_date, force_rebuild_latest=True)
build_stock_pool_tag_stats(stock_pool_name=stock_pool_name, force_rebuild_latest=True)


if __name__ == "__main__":
Expand Down
23 changes: 15 additions & 8 deletions src/zvt/trading/trading_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,23 @@ def build_query_stock_quote_setting(build_query_stock_quote_setting_model: Build
the_id = "admin_setting"
datas = QueryStockQuoteSetting.query_data(ids=[the_id], session=session, return_type="domain")
if datas:
stock_pool_info = datas[0]
query_setting = datas[0]
else:
stock_pool_info = QueryStockQuoteSetting(entity_id="admin", id=the_id)
stock_pool_info.timestamp = current_date()
stock_pool_info.stock_pool_name = build_query_stock_quote_setting_model.stock_pool_name
stock_pool_info.main_tags = build_query_stock_quote_setting_model.main_tags
session.add(stock_pool_info)
query_setting = QueryStockQuoteSetting(entity_id="admin", id=the_id)
query_setting.timestamp = current_date()
query_setting.stock_pool_name = build_query_stock_quote_setting_model.stock_pool_name
query_setting.main_tags = build_query_stock_quote_setting_model.main_tags
session.add(query_setting)
session.commit()
session.refresh(stock_pool_info)
return stock_pool_info
session.refresh(query_setting)
return query_setting


def build_default_query_stock_quote_setting():
datas = QueryStockQuoteSetting.query_data(ids=["admin_setting"], return_type="domain")
if datas:
return
build_query_stock_quote_setting(BuildQueryStockQuoteSettingModel(stock_pool_name="all"))


if __name__ == "__main__":
Expand Down

0 comments on commit b4da641

Please sign in to comment.