可转债基础信息怎么取
这是工程记录。只谈列表和字段。不写双低、不写轮动阈值、不写买卖条件。不构成投资建议,不代操盘。
对照
| PTrade | QMT | |
|---|---|---|
| 列表 | get_cb_list() | 板块 get_stock_list_in_sector,或自己维护代码表 |
| 基础字段 | get_cb_info()(要券商权限) | get_instrument_detail / 财务字段,能拿到什么先打印 |
| 快照 | get_snapshot | get_full_tick |
| 价格小数 | 3 位 | 3 位 |
| 数量 | 张,常见 10 张一手 | 张,passorder 的量按张 |
代码特征:沪市常见 11 / 113 开头 + .SS 或 .SH;深市常见 123 / 127 / 128 + .SZ。以列表接口为准,不要靠前缀猜完。
PTrade:列表 + 基础表 + 快照
python
def initialize(context):
g.cb_codes = []
run_daily(context, load_cb, time='09:25')
def before_trading_start(context, data):
g.cb_codes = []
def load_cb(context):
codes = get_cb_list() or []
snap = get_snapshot(codes) or {}
tradeable = []
for c in codes:
st = (snap.get(c) or {}).get('trade_status')
if st in (None, 'HALT', 'SUSP', 'STOPT', 'DELISTED'):
continue
tradeable.append(c)
g.cb_codes = tradeable
log.info('cb list %s tradeable %s', len(codes), len(tradeable))
info = get_cb_info()
if info is None or getattr(info, 'empty', True):
log.info('get_cb_info 空:无权限或通道不支持')
return
cols = list(info.columns)
log.info('cb_info cols %s rows %s', cols, len(info))
# 常见列:bond_code bond_name stock_code convert_price convert_value premium_rate
log.info(info.head())get_cb_list 同一分钟多次调用会走缓存。get_cb_info 没权限就是空 DataFrame。
QMT:板块 + 详情 + tick
python
#coding:gbk
def init(C):
C.printed = False
def handlebar(C):
if not C.is_last_bar() or C.printed:
return
names = ['沪市可转债', '深市可转债']
bag = []
fn = getattr(C, 'get_stock_list_in_sector', None)
for n in names:
try:
bag.extend(fn(n) or [])
except Exception as e:
print('sector', n, e)
print('sector size', len(bag), bag[:8])
sample = bag[:3] if bag else ['113050.SH']
for code in sample:
try:
det = C.get_instrument_detail(code)
print(code, 'detail', det)
except Exception as e:
print(code, 'detail fail', e)
tick = C.get_full_tick(sample) or {}
for code, t in tick.items():
print(code, 'last', (t or {}).get('lastPrice'), 'bid', (t or {}).get('bidPrice'))
C.printed = True板块名字以你客户端「品种 / 板块」里的为准,没有这两个名字就换。财务/转股价不是每家都有,空就空,不要当成双低数据源。
坑
- 转债限价三位,按股票两位取整,柜台拒。
- T+0 和股票不是同一套可卖字段,对账看张数。
- QMT 没有和 PTrade 完全同名的
get_cb_info,不要硬拷。 - 停牌、待退市会出现在全市场列表里,先看
trade_status/ 停牌标记。 - 这里只打印字段。怎么排序、买多少,不要写进公共片段。
完整讨论和附件在 知识星球 Kimi量化研究所。
