Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions _doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

所有关于本项目的显著变更都将记录在本文件中。

## [ To Do List ]

- LimitSeller 逻辑优化

## [ In Progress ]

### 添加
- 临跌停卖点模块,用以预防跌停被锁死的极端风险
- 竞价结束callback接口

### 修改
- 部分文案优化
- Subscriber代码拆分重构

### 删除
- 旧版schedule移除

## [ 4.2.0 ] 2025-11-18

Expand Down
35 changes: 35 additions & 0 deletions delegate/base_delegate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import threading

from abc import ABC, abstractmethod
from tools.utils_cache import InfoItem, load_json, save_json


DEFAULT_STRATEGY_NAME = '空白策略'
Expand Down Expand Up @@ -83,3 +86,35 @@ def is_position_holding(position: any) -> bool:
@abstractmethod
def get_holding_position_count(self, positions: list, only_stock: bool = False) -> int:
return 0

@abstractmethod
def shutdown(self) -> None:
pass


# -----------------------
# 持仓自动发现
# -----------------------
def update_position_held(lock: threading.Lock, delegate: BaseDelegate, path: str):
with lock:
positions = delegate.check_positions()
held_info = load_json(path)

# 添加未被缓存记录的持仓:默认当日买入
for position in positions:
if position.can_use_volume > 0:
if position.stock_code not in held_info.keys():
held_info[position.stock_code] = {InfoItem.DayCount: 0}

# 删除已清仓的held_info记录
if positions is not None and len(positions) > 0:
position_codes = [position.stock_code for position in positions]
print('[当前持仓]', position_codes)
holding_codes = list(held_info.keys())
for code in holding_codes:
if len(code) > 0 and code[0] != '_' and (code not in position_codes):
del held_info[code]
else:
print('[当前空仓]')

save_json(path, held_info)
Loading
Loading