From 33693adb665fee6bb2df7a2c0b63965da3772598 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Wed, 16 Sep 2026 23:16:32 +0800 Subject: [PATCH] fix ipo bug --- py-client/strategy/ipo/boot.py | 4 ++++ py-client/tests/test_ipo.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/py-client/strategy/ipo/boot.py b/py-client/strategy/ipo/boot.py index da00e48..1dabbb7 100644 --- a/py-client/strategy/ipo/boot.py +++ b/py-client/strategy/ipo/boot.py @@ -102,6 +102,10 @@ def AutoBuyIpo() -> int: orders = client.orders() # 查询失败时不提交,不能将未知当作无委托。 for item in candidates: try: + stock = item.get('stock') if isinstance(item, dict) else None + if isinstance(stock, str) and re.fullmatch(r'[0-9]{6}\.BJ', stock.strip()): + logging.info('[IPO] %s 已跳过:北交所不在申购范围内', stock.strip()) + continue stock, price, volume = _candidate(item) submitted += _subscribe(client, orders, account, now.strftime('%Y%m%d'), stock, price, volume) diff --git a/py-client/tests/test_ipo.py b/py-client/tests/test_ipo.py index d079d1d..23902f6 100644 --- a/py-client/tests/test_ipo.py +++ b/py-client/tests/test_ipo.py @@ -187,6 +187,17 @@ class IPOTests(unittest.TestCase): self.assertEqual(client.submitted[0]['price'], 12.5) self.assertEqual([r['status'] for r in self.records()], ['pending']) + def test_beijing_candidate_is_excluded_without_error(self): + client = IPOResponseClient({ + '920202.BJ': {'issuePrice': 7.55, 'maxPurchaseNum': 1190000}, + '301716.SZ': {'issuePrice': 10, 'maxPurchaseNum': 3500}, + }) + with patch.object(boot, 'Client', return_value=client), self.assertLogs(level='INFO') as logs: + self.assertEqual(boot.AutoBuyIpo(), 1) + self.assertTrue(all(record.levelno == 20 for record in logs.records)) + self.assertEqual([order['stock'] for order in client.submitted], ['301716.SZ']) + self.assertEqual([record['stock'] for record in self.records()], ['301716.SZ']) + def test_supported_codes_and_numeric_strings(self): for stock in ['600001.SH', '688001.SH', '689001.SH', '000001.SZ', '001001.SZ', '002001.SZ', '003001.SZ', '300001.SZ', '301001.SZ']: