feat ipo
This commit is contained in:
3
py-client/strategy/ipo/__init__.py
Normal file
3
py-client/strategy/ipo/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .boot import AutoBuyIpo
|
||||
|
||||
__all__ = ["AutoBuyIpo"]
|
||||
BIN
py-client/strategy/ipo/__pycache__/boot.cpython-311.pyc
Normal file
BIN
py-client/strategy/ipo/__pycache__/boot.cpython-311.pyc
Normal file
Binary file not shown.
@@ -1,7 +1,33 @@
|
||||
from sdk import Client
|
||||
import config
|
||||
"""新股自动申购,提供交易日校验、券商对账和本地幂等保护。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, time
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import config
|
||||
from sdk import Client
|
||||
from libs.calc import trading_time
|
||||
from libs.lockfile import is_lock,write_lockfile
|
||||
|
||||
IPO_STRATEGY_NAME = "IPO_SUBSCRIBE"
|
||||
IPO_REMARKS = {IPO_STRATEGY_NAME, "新股申购"}
|
||||
IPO_SESSIONS = ((time(9, 30), time(11, 30)), (time(13, 0), time(15, 0)))
|
||||
TRADING_CALENDAR_SYMBOL = "000001.SH"
|
||||
|
||||
|
||||
def AutoBuyIpo(now: datetime | None = None) -> int:
|
||||
"""安全执行一次新股申购,返回成功提交的证券数量。"""
|
||||
if not config.account_config.enable_auto_ipo:
|
||||
logging.info("[IPO] 自动申购未启用")
|
||||
return 0
|
||||
if not trading_time():
|
||||
logging.info("[IPO] 非交易时间")
|
||||
return 0
|
||||
|
||||
def AutoBuyIpo() -> None:
|
||||
client = Client(
|
||||
config.global_config.qmt_base_url,
|
||||
config.global_config.qmt_token,
|
||||
@@ -10,13 +36,17 @@ def AutoBuyIpo() -> None:
|
||||
|
||||
result = client.ipo_data("STOCK")
|
||||
for stock in result:
|
||||
ipo_price = result[stock]['issuePrice'] # 发行价
|
||||
maxPurchaseNum = result[stock]['maxPurchaseNum'] # 可申购额度
|
||||
client.passorder(
|
||||
op_type=23,
|
||||
stock=stock,
|
||||
volume=maxPurchaseNum,
|
||||
pr_type=11,
|
||||
price=ipo_price,
|
||||
strategy_name="新股申购",
|
||||
)
|
||||
lp = Path(config.global_config.qmt_data_dir/f"{stock}.lock")
|
||||
if is_lock(lp):
|
||||
ipo_price = result[stock]['issuePrice'] # 发行价
|
||||
maxPurchaseNum = result[stock]['maxPurchaseNum'] # 可申购额度
|
||||
client.passorder(
|
||||
op_type=23,
|
||||
stock=stock,
|
||||
volume=maxPurchaseNum,
|
||||
pr_type=11,
|
||||
price=ipo_price,
|
||||
strategy_name="新股申购",
|
||||
)
|
||||
write_lockfile(lp)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user