Skip to content

Commit

Permalink
qmt trading
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed May 16, 2024
1 parent e3a0712 commit 950d95a
Show file tree
Hide file tree
Showing 46 changed files with 1,252 additions and 1,410 deletions.
2 changes: 1 addition & 1 deletion api-tests/get_stock_pools.http
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET http://127.0.0.1:8090/api/work/get_stock_pools?stock_pool_name=vol_up
GET http://127.0.0.1:8090/api/work/get_stock_pools?stock_pool_name=main_line
accept: application/json


Expand Down
612 changes: 0 additions & 612 deletions api-tests/tag/build_stock_tags.http

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions api-tests/tag/query_simple_stock_tags.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Content-Type: application/json

{
"entity_ids": [
"stock_sz_002085"
"stock_sz_002085",
"stock_sz_000099",
"stock_sz_002130"
]
}
}
4 changes: 3 additions & 1 deletion api-tests/tag/query_stock_tags.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Content-Type: application/json

{
"entity_ids": [
"stock_sz_002085"
"stock_sz_000099",
"stock_sz_002085",
"stock_sz_001696"
]
}
20 changes: 12 additions & 8 deletions api-tests/tag/set_stock_tags.http
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ accept: application/json
Content-Type: application/json

{
"entity_id": "stock_sz_301091",
"name": "深城交",
"main_tag": "低空经济",
"main_tag_reason": "2024年3月8日回复称,目前公司已与另外一家深圳研究咨询机构组成的联合体正式承接了深圳低空智能融合基础设施建设项目一期项目,该项目主要围绕深圳市低空经济发展,建设可覆盖全市范围的智能融合系统的软件平台(包括低空操作管理系统和低空管理服务系统),建设配套的管服中心、数据中心及无人机测试场,接入典型的城市场景,并进行软件平台的验证。",
"sub_tag": "低空经济",
"sub_tag_reason": "2024年3月8日回复称,目前公司已与另外一家深圳研究咨询机构组成的联合体正式承接了深圳低空智能融合基础设施建设项目一期项目,该项目主要围绕深圳市低空经济发展,建设可覆盖全市范围的智能融合系统的软件平台(包括低空操作管理系统和低空管理服务系统),建设配套的管服中心、数据中心及无人机测试场,接入典型的城市场景,并进行软件平台的验证。",
"active_hidden_tags": null
}
"entity_id": "stock_sz_001366",
"name": "播恩集团",
"main_tag": "医药",
"main_tag_reason": "合成生物概念",
"main_tags": {
"农业": "来自行业:农牧饲渔"
},
"sub_tag": "生物医药",
"sub_tag_reason": "合成生物概念",
"sub_tags": null,
"active_hidden_tags": null
}
9 changes: 9 additions & 0 deletions api-tests/trading/query_stock_quotes.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST http://127.0.0.1:8090/api/trading/query_stock_quotes
accept: application/json
Content-Type: application/json

{
"tag": "材料",
"limit": 500,
"order_by_field": "change_pct"
}
34 changes: 18 additions & 16 deletions examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,41 @@

import eastmoneypy
import pandas as pd

import requests
from zvt.domain import StockNews, Stock, LimitUpInfo
from zvt.utils import date_time_by_interval, today

logger = logging.getLogger(__name__)


def add_to_eastmoney(codes, group, entity_type="stock", over_write=True):
codes = list(set(codes))
if over_write:
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.del_group(group_name=group)
eastmoneypy.create_group(group_name=group, session=session)
except:
pass
try:
eastmoneypy.create_group(group_name=group)
except:
pass

group_id = eastmoneypy.get_group_id(group)
group_id = eastmoneypy.get_group_id(group, session=session)

for code in codes:
time.sleep(1)
eastmoneypy.add_to_group(code=code, entity_type=entity_type, group_id=group_id)
for code in codes:
eastmoneypy.add_to_group(code=code, entity_type=entity_type, group_id=group_id, session=session)


def clean_groups(keep=None):
if keep is None:
keep = ["自选股", "练气", "重要板块", "主线"]
groups = eastmoneypy.get_groups()
groups_to_clean = [group["gid"] for group in groups if group["gname"] not in keep]
for gid in groups_to_clean:
eastmoneypy.del_group(group_id=gid)

with requests.Session() as session:
groups = eastmoneypy.get_groups(session=session)
groups_to_clean = [group["gid"] for group in groups if group["gname"] not in keep]
for gid in groups_to_clean:
eastmoneypy.del_group(group_id=gid, session=session)


def get_hot_words_config():
Expand Down
File renamed without changes.
22 changes: 0 additions & 22 deletions scripts/qmt_runner.py

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/report_stock.py

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/report_stockhk.py

This file was deleted.

7 changes: 7 additions & 0 deletions src/fill_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
from zvt.autocode import gen_exports

if __name__ == "__main__":
gen_exports(dir_path="./zvt_vip/dataset")
gen_exports(dir_path="./zvt_vip/recorders")
gen_exports(dir_path="./zvt_vip/tag")
13 changes: 9 additions & 4 deletions src/zvt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@ def old_db_to_provider_dir(data_path):
import zvt.recorders as zvt_recorders
import zvt.factors as zvt_factors

# try:
# import zvt.recorders.qmt.quotes.qmt_kdata_recorder as qmt_kdata_recorde
# except Exception as e:
# logger.warning("QMT need run in Windows!", e)
import platform

if platform.system() == "Windows":
try:
import zvt.recorders.qmt.quotes.qmt_kdata_recorder as qmt_kdata_recorde
except Exception as e:
logger.error("QMT not work", e)
else:
logger.warning("QMT need run in Windows!")


__all__ = ["zvt_env", "zvt_config", "init_log", "init_env", "init_config", "__version__"]
26 changes: 26 additions & 0 deletions src/zvt/broker/qmt/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from typing import Optional

from zvt import zvt_env
from zvt.broker.qmt.qmt_account import QmtStockAccount


class QmtContext(object):
def __init__(self):
self.qmt_account: Optional[QmtStockAccount] = None


qmt_context = QmtContext()


def init_qmt_account(qmt_mini_data_path=None, qmt_account_id=None):
if not qmt_mini_data_path:
qmt_mini_data_path = zvt_env["qmt_mini_data_path"]
if not qmt_account_id:
qmt_account_id = zvt_env["qmt_account_id"]
qmt_context.qmt_account = QmtStockAccount(
path=qmt_mini_data_path, account_id=qmt_account_id, trader_name="zvt", session_id=None
)


init_qmt_account()
15 changes: 15 additions & 0 deletions src/zvt/broker/qmt/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
class TraderError(Exception):
"""Base class for exceptions in this module."""

pass


class QmtError(TraderError):
def __init__(self, message="qmt error"):
self.message = message


class PositionOverflowError(TraderError):
def __init__(self, message="超出仓位限制"):
self.message = message
Loading

0 comments on commit 950d95a

Please sign in to comment.