kaq-quant-common 0.1.79__tar.gz → 0.1.81__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/PKG-INFO +1 -1
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/helper/order_helper.py +17 -6
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_ddb_pool_stream_read_resources.py +18 -2
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_mysql_resources.py +8 -5
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/dagster_utils.py +1 -1
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/pyproject.toml +1 -1
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/README.md +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/common/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/common/api_interface.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/common/auth.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/api_client_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/api_server_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/instruction_client.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/instruction_server_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/models/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/models/account.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/models/order.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/models/position.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/instruction/models/transfer.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/exchange/models.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/exchange/ws_exchange_client.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/exchange/ws_exchange_server.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/instruction/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/instruction/ws_instruction_client.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/instruction/ws_instruction_server_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/models.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/ws_client_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/ws_server_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/ddb_table_monitor.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/http_monitor.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/modules/limit_order_helper.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/modules/limit_order_symbol_monitor.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/modules/limit_order_symbol_monitor_group.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/monitor_base.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/monitor_group.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/redis_table_monitor.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/ws_wrapper.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/config/config.yaml +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_ddb_stream_init_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_ddb_stream_read_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_ddb_stream_write_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_mysql_init_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_postgresql_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_quant_hive_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/resources/kaq_redis_resources.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/__init__.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/dagster_job_check_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/date_util.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/enums_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/error_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/hash_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/log_time_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/logger_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/mytt_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/signal_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/sqlite_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/uuid_utils.py +0 -0
- {kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/yml_utils.py +0 -0
|
@@ -113,12 +113,16 @@ class OrderHelper:
|
|
|
113
113
|
def process_order(self, order: OrderInfo, get_order_result: Callable):
|
|
114
114
|
# 获取交易所
|
|
115
115
|
exchange = self._server._exchange
|
|
116
|
+
|
|
117
|
+
# 记录时间,统计成交耗时
|
|
118
|
+
start_time = time.time()
|
|
119
|
+
|
|
116
120
|
#
|
|
117
|
-
if not self._do_process_order(exchange, order, get_order_result, True):
|
|
121
|
+
if not self._do_process_order(exchange, order, get_order_result, True, start_time):
|
|
118
122
|
# 马上执行,没有成功,开启线程执行
|
|
119
123
|
thread = threading.Thread(
|
|
120
124
|
target=self._do_process_order,
|
|
121
|
-
args=(exchange, order, get_order_result, False),
|
|
125
|
+
args=(exchange, order, get_order_result, False, start_time),
|
|
122
126
|
)
|
|
123
127
|
thread.name = f"process_order_{order.instruction_id}_{exchange}_{order.symbol}_{order.order_id}"
|
|
124
128
|
thread.daemon = True
|
|
@@ -130,6 +134,7 @@ class OrderHelper:
|
|
|
130
134
|
order: OrderInfo,
|
|
131
135
|
get_order_result: Callable,
|
|
132
136
|
first=True,
|
|
137
|
+
start_time: float = 0,
|
|
133
138
|
):
|
|
134
139
|
# 获取mysql
|
|
135
140
|
mysql = self._server._mysql
|
|
@@ -175,11 +180,11 @@ class OrderHelper:
|
|
|
175
180
|
"""
|
|
176
181
|
execute_ret = mysql.execute_sql(sql, True)
|
|
177
182
|
|
|
178
|
-
# 记录时间,统计成交耗时
|
|
179
|
-
start_time = time.time()
|
|
180
|
-
|
|
181
183
|
# 步骤2.查询订单状态 直到订单成交后
|
|
184
|
+
# 统计查询次数
|
|
185
|
+
query_counter = 0
|
|
182
186
|
while True:
|
|
187
|
+
query_counter += 1
|
|
183
188
|
# 获取订单结果
|
|
184
189
|
order_info = None
|
|
185
190
|
try:
|
|
@@ -195,10 +200,16 @@ class OrderHelper:
|
|
|
195
200
|
# 等待
|
|
196
201
|
time.sleep(1)
|
|
197
202
|
|
|
203
|
+
if not first:
|
|
204
|
+
# 需要加上第一查询
|
|
205
|
+
query_counter += 1
|
|
206
|
+
|
|
198
207
|
# 记录时间,统计成交耗时
|
|
199
208
|
end_time = time.time()
|
|
200
209
|
cost_time = end_time - start_time
|
|
201
|
-
self._logger.info(
|
|
210
|
+
self._logger.info(
|
|
211
|
+
f"{ins_id}_{exchange}_{symbol} step 2. {side_str}订单 {order_id} 成交 耗时 {int(cost_time * 1000)}ms, 查询次数 {query_counter}"
|
|
212
|
+
)
|
|
202
213
|
|
|
203
214
|
# 步骤3.把最终持仓写进去
|
|
204
215
|
# 平均成交价格 转float
|
|
@@ -7,6 +7,7 @@ import pandas as pd
|
|
|
7
7
|
import threading
|
|
8
8
|
from kaq_quant_common.utils.logger_utils import get_logger
|
|
9
9
|
import traceback
|
|
10
|
+
from dolphindb.settings import PROTOCOL_PICKLE
|
|
10
11
|
|
|
11
12
|
mutex = threading.Lock()
|
|
12
13
|
|
|
@@ -14,7 +15,7 @@ class KaqQuantDdbPoolStreamReadRepository:
|
|
|
14
15
|
'''
|
|
15
16
|
连接池方式连接DolphinDB数据库, 支持流数据表读取
|
|
16
17
|
'''
|
|
17
|
-
def __init__(self, host, port, user, passwd, pool_size=1):
|
|
18
|
+
def __init__(self, host, port, user, passwd, pool_size=1, protocal=PROTOCOL_PICKLE):
|
|
18
19
|
self.logger = get_logger(self)
|
|
19
20
|
try:
|
|
20
21
|
mutex.acquire()
|
|
@@ -27,6 +28,7 @@ class KaqQuantDdbPoolStreamReadRepository:
|
|
|
27
28
|
reConnect=True,
|
|
28
29
|
# tryReconnectNums=5, # 若不开启高可用,须与 reconnect 参数搭配使用,对单节点进行有限次重连。若不填写该参数,默认进行无限重连。
|
|
29
30
|
sqlStd=SqlStd.DolphinDB,
|
|
31
|
+
protocol=protocal
|
|
30
32
|
)
|
|
31
33
|
except Exception as e:
|
|
32
34
|
self.logger.error(f'KaqQuantDdbPoolStreamReadRepository.__init__ is occured error: {str(e)} - {str(traceback.format_exc())}')
|
|
@@ -49,7 +51,21 @@ class KaqQuantDdbPoolStreamReadRepository:
|
|
|
49
51
|
big_df.columns = colums
|
|
50
52
|
return big_df, None
|
|
51
53
|
except Exception as e:
|
|
52
|
-
self.logger.error(f'KaqQuantDdbPoolStreamReadRepository.
|
|
54
|
+
self.logger.error(f'KaqQuantDdbPoolStreamReadRepository.query is occured error: {str(e)} - {str(traceback.format_exc())}')
|
|
55
|
+
return pd.DataFrame()
|
|
56
|
+
|
|
57
|
+
async def fetch(self, query: str) -> pd.DataFrame:
|
|
58
|
+
'''
|
|
59
|
+
从流数据表中获取数据
|
|
60
|
+
'''
|
|
61
|
+
try:
|
|
62
|
+
data = await self.pool.run(query, pickleTableToList=False, clearMemory=True)
|
|
63
|
+
if data is None:
|
|
64
|
+
return pd.DataFrame()
|
|
65
|
+
big_df = pd.DataFrame(data)
|
|
66
|
+
return big_df
|
|
67
|
+
except Exception as e:
|
|
68
|
+
self.logger.error(f'KaqQuantDdbPoolStreamReadRepository.fetch is occured error: {str(e)} - {str(traceback.format_exc())}')
|
|
53
69
|
return pd.DataFrame()
|
|
54
70
|
|
|
55
71
|
|
|
@@ -44,19 +44,23 @@ class KaqQuantMysqlRepository:
|
|
|
44
44
|
-- SET autocommit = 0;
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
def __init__(self, host, port, user, passwd, database, charset="utf8mb4"):
|
|
47
|
+
def __init__(self, host, port, user, passwd, database, charset="utf8mb4", pool_size=3):
|
|
48
48
|
self.logger = get_logger(self)
|
|
49
49
|
# 创建写入引擎数据库连接池
|
|
50
50
|
self.conn_engine = create_engine(
|
|
51
51
|
f"mysql+mysqldb://{user}:{passwd}@{host}:{port}/{database}?charset={charset}",
|
|
52
52
|
# 连接池大小
|
|
53
|
-
pool_size=
|
|
53
|
+
pool_size=pool_size,
|
|
54
54
|
# 超出连接池后,允许的最大扩展数
|
|
55
55
|
max_overflow=5,
|
|
56
56
|
# 池中没有线程最多等待的时间(秒)
|
|
57
57
|
pool_timeout=60,
|
|
58
58
|
# 多久之后,连接自动断开,-1 表示不自动断开(秒)
|
|
59
|
-
pool_recycle=
|
|
59
|
+
pool_recycle=650,
|
|
60
|
+
# 启用连接前检查
|
|
61
|
+
pool_pre_ping=True,
|
|
62
|
+
echo=False, # 关闭 SQL 语句日志
|
|
63
|
+
echo_pool=False, # 关闭连接池日志
|
|
60
64
|
)
|
|
61
65
|
# 会话工厂
|
|
62
66
|
self.session_maker = sessionmaker(bind=self.conn_engine, autoflush=False)
|
|
@@ -257,7 +261,6 @@ class KaqQuantMysqlRepository:
|
|
|
257
261
|
mutex.acquire(True)
|
|
258
262
|
if df is None or df.empty:
|
|
259
263
|
return
|
|
260
|
-
df = df.map(lambda x: None if pd.isna(x) else x)
|
|
261
264
|
if "id" not in df:
|
|
262
265
|
df = append_id(df)
|
|
263
266
|
# pandas写法
|
|
@@ -278,7 +281,7 @@ class KaqQuantMysqlRepository:
|
|
|
278
281
|
df_part = df.iloc[i * mysql_max_allowed_packet : (i + 1) * mysql_max_allowed_packet]
|
|
279
282
|
|
|
280
283
|
# 拼接插入的sql语句
|
|
281
|
-
value_list = ["(" + ", ".join(["'" + str(_r) + "'" if _r
|
|
284
|
+
value_list = ["(" + ", ".join(["'" + str(_r) + "'" if str(_r) != 'NaT' and str(_r) != 'nan' else "NULL" for _r in row.values]) + ")" for index, row in df_part.iterrows()]
|
|
282
285
|
value_list_str = ", ".join(value_list)
|
|
283
286
|
query = f"INSERT INTO {table_name} ({columns}) VALUES {value_list_str} ON DUPLICATE KEY UPDATE {update_columns_str} ;"
|
|
284
287
|
|
|
@@ -14,6 +14,6 @@ def check_dagster_job_running(context: RunStatusSensorContext, job_name: str):
|
|
|
14
14
|
DagsterRunStatus.STARTING,
|
|
15
15
|
DagsterRunStatus.STARTED,
|
|
16
16
|
]:
|
|
17
|
-
context.log.info(f"Job {job_name} is already running")
|
|
17
|
+
# context.log.info(f"Job {job_name} is already running")
|
|
18
18
|
return False
|
|
19
19
|
return True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/common/api_interface.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/api_client_base.py
RENAMED
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/rest/api_server_base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/exchange/models.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/instruction/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/ws_client_base.py
RENAMED
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/api/ws/ws_server_base.py
RENAMED
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/ddb_table_monitor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/monitor_group.py
RENAMED
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/common/redis_table_monitor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kaq_quant_common-0.1.79 → kaq_quant_common-0.1.81}/kaq_quant_common/utils/log_time_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|