Skip to content

PTrade get_snapshot 行情快照

手册全文:PTrade API

get_snapshot

python
get_snapshot(security)
使用场景

该函数仅在交易模块可用

接口说明

该接口用于获取实时行情快照。

注意事项:

证监会行业、聚源行业、概念板块、地域板块所对应标的的行情数据为非标准的交易所下发数据,是由数据源自行按照成分股分类规则进行计算的,存在与三方数据源不一致的情况。如用户需要在策略中使用,应自行评估该数据的合理性

参数

security: 单只股票代码或者多只股票代码组成的列表,必填字段(list[str]/str);

返回

正常返回一个dict类型数据,包含每只股票代码的行情快照信息,其中key为股票代码,value为对应的快照信息。异常返回空dict,如{}(dict[str:dict[...]])

快照包含以下信息:

  • amount:持仓量(str:int)(期货字段,股票返回0);
  • bid_grp:委买档位(第一档包含委托队列(仅L2支持))(str:dict[int:list[float,int,int,{int:int,...}],int:list[float,int,int]...]);
  • business_amount:总成交量(str:int);
  • business_amount_in:内盘成交量(str:int);
  • business_amount_out:外盘成交量(str:int);
  • business_balance:总成交额(str:float);
  • business_count:成交笔数(str:int)
  • circulation_amount:流通股本(str:int);
  • current_amount:最近成交量(现手)(str:int);
  • down_px:跌停价格(str:float);
  • end_trade_date:最后交易日(str:str)
  • entrust_diff:委差(str:float);
  • entrust_rate:委比(str:float);
  • high_px:最高价(str:float);
  • hsTimeStamp:时间戳(str:float);
  • last_px:最新成交价(str:float);
  • low_px:最低价(str:float);
  • offer_grp:委卖档位(第一档包含委托队列(仅L2支持))(str:dict[int:list[float,int,int,{int:int,...}],int:list[float,int,int]...]);
  • open_px:今开盘价(str:float);
  • pb_rate:市净率(str:float);
  • pe_rate:动态市盈率(str:float);
  • preclose_px:昨收价(str:float);
  • prev_settlement:昨结算(str:float)(期货字段,股票返回0.0);
  • px_change_rate:涨跌幅(str:float);
  • settlement:结算价(str:float)(期货字段,股票返回0.0)
  • start_trade_date:首个交易日(str:float)
  • tick_size:最小报价单位(str:float)
  • total_bid_turnover:委买金额(str:int);
  • total_bidqty:委买量(str:int);
  • total_offer_turnover:委卖金额(str:int)
  • total_offerqty:委卖量(str:int);
  • trade_mins:交易分钟数(str:int)
  • trade_status:交易状态(str:str);
  • turnover_ratio:换手率(str:int);
  • up_px:涨停价格(str:float);
  • vol_ratio:量比(str:float);
  • wavg_px:加权平均价(str:float);
  • iopv:基金份额参考净值(str:float);

字段备注:

  • bid_grp -- 委买档位,{'bid_grp': {1: [价格, 委托量,委托笔数,委托对列{}], 2: [价格, 委托量,委托笔数], 3: [价格, 委托量,委托笔数], 4: [价格, 委托量,委托笔数], 5: [价格, 委托量,委托笔数]}} ;
  • offer_grp -- 委卖档位,{'offer_grp': {1: [价格, 委托量,委托笔数,委托对列{}], 2: [价格, 委托量,委托笔数], 3: [价格, 委托量,委托笔数], 4: [价格, 委托量,委托笔数], 5: [价格, 委托量,委托笔数]}} ;
  • total_bid_turnover/total_offer_turnover,委买金额/委卖金额主推数据(tick数据中)不支持(值为0),仅在线请求中支持;

返回如下:

python
{'600570.SS': {'offer_grp': {1: [44.47, 3300, 0, {}], 2: [44.48, 2800, 0], 3: [44.49, 3900, 0], 4: [44.5, 17300, 0], 5: [44.51, 1600, 0]}, 'open_px': 44.91, 'pe_rate': 4294573.83, 'pb_rate': 11.42, 'entrust_diff': -100.0, 'entrust_rate': -0.2092, 'total_bidqty': 18900, 'preclose_px': 45.2, 'total_offer_turnover': 0, 'business_amount_out': 2600706, 'px_change_rate': -1.62, 'turnover_ratio': 0.0042, 'total_bid_turnover': 0, 'vol_ratio': 1.12, 'hsTimeStamp': 20220622102358580, 'amount': 0, 'prev_settlement': 0.0, 'circulation_amount': 1461560480, 'low_px': 44.31, 'down_px': 40.68, 'bid_grp': {1: [44.45, 600, 0, {}], 2: [44.44, 600, 0], 3: [44.43, 8300, 0], 4: [44.42, 9200, 0], 5: [44.41, 200, 0]}, 'business_balance': 274847503.0, 'business_amount': 6161800, 'business_amount_in': 3561094, 'last_px': 44.47, 'total_offerqty': 28900, 'up_px': 49.72, 'wavg_px': 44.6, 'high_px': 45.05, 'trade_status': 'TRADE', 'iopv': '0.0'}}
示例
python
def initialize(context):
    g.security = '600570.SS'
    set_universe(g.security)

def handle_data(context, data):
    # 行情快照
    snapshot = get_snapshot(g.security)
    log.info(snapshot)

实盘大约 3 秒才换一帧,中间变化看逐笔,见 get_snapshot 大约 3 秒一帧

开通 / 代写:关注公众号 Kimi量化