Skip to content

Commit

Permalink
0.9.56 没有品种交易,直接return
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Jul 15, 2024
1 parent d32128e commit c43cf52
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions czsc/connectors/tq_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ def adjust_portfolio(api: TqApi, portfolio, account=None, **kwargs):
target_pos.set_target_volume(int(lots))
symbol_infos[symbol] = {"quote": quote, "target_pos": target_pos, "lots": lots}

if not symbol_infos:
logger.warning(f"没有需要调仓的品种,跳过调仓")
return api
else:
logger.info(f"开始调仓:{[x for x in symbol_infos.keys()]}")

while True:
api.wait_update()

Expand Down Expand Up @@ -439,6 +445,10 @@ def adjust_portfolio(api: TqApi, portfolio, account=None, **kwargs):

if (datetime.now() - start_time).seconds > timeout:
logger.error(f"调仓超时,已运行 {timeout} 秒")
for symbol, info in symbol_infos.items():
target_pos: TargetPosTask = info["target_pos"]
target_pos.cancel()
logger.info(f"取消调仓:{symbol}")
break

return api

0 comments on commit c43cf52

Please sign in to comment.