Nuggets Quantification—Python SDK Documentation—4. Data Structure

Table of contents

Python SDK Documentation

4. Data structure

  4.1 Data class

    Tick ​​- the Tick object

    quote quote - (dict type)

    Bar - a Bar object

    L2Order - Level2 order by order

    L2Transaction - Level2 tick-by-tick

  4.2 Transaction class

    Account - the account object

    Order - the delegate object

    ExecRpt - return object

    Cash - the money object

    Position - position object

    Indicator — Performance indicator object


Python SDK Documentation

4. Data structure

4.1 Data class
Tick ​​- the Tick object

Market snapshot data

parameter name type illustrate
symbol str target code
open float Daily opening price
high float Daily highest price
low float Daily lowest price
price float Latest price
with_volume long The latest total trading volume, cumulative value (daily trading volume)
cum_amount float The latest total turnover, cumulative value (daily turnover)
cum_position int Contract position (only applicable to futures), cumulative value (the value of stock is 0)
trade_type int Transaction type (applicable to futures only) 1: 'double open', 2: 'double close', 3: 'long open', 4: 'short open', 5: 'short close', 6: 'long close', 7 : 'multiple change', 8: 'empty change'
last_volume int Latest Instantaneous Trading Volume
last_amount float The latest instantaneous turnover (ZCE last_amount is 0)
created_at datetime.datetime creation time
quotes [] (list of dict) Stocks provide 5 levels of buying and selling data, list[0]~list[4] correspond to buying and selling levels 1 to 5, and futures provide buying and selling 1 level data, list[0] means buying and selling one level; level2 market corresponds to list[0 ]~list[9] buy and sell one to ten stalls, note : there may be missing quotes for buy or sell stalls, for example, there is no bid quote at the time of limit-down (bid_p and bid_v are 0), and there is no quote for sell at the time of daily limit (ask_p and ask_v is 0); The quotation structure of each file quoteis as follows:

quotes quote - (dict type)
parameter name type illustrate
bid_p float purchase price
bid_v int Buy volume
ask_p float selling price
ask_v int Sales volume
bid_q dict The entrusted purchase queue includes (total_orders (int) the total number of entrusted orders, queue_volumes (list) entrusted volume queue), only supported by level2 market
ask_q dict The entrusted sales queue includes (total_orders (int) the total number of orders, queue_volumes (list) the order volume queue), only supported by level2 market

Note : 1. Tick is the transaction data in batches. The stock frequency is 3s, the futures is 0.5s, and the index is 5s. It includes call auction data. The number of call auctions in the morning stock market is the tick data from 09:15:00-09:25:00 2 , When the limit is up, there is no selling price and selling volume, ask_p and ask_v are filled with 0, when the limit is down, there is no buying price and buying volume, bid_p and bid_v are filled with 0 3, queue_volumes entrusted volume queue, only the first optimal file can be obtained The first 50 commissions (inactive targets may be less than 50)

Bar - a Bar object

Bar data refers to the market data of various frequencies

parameter name type illustrate
symbol str target code
frequency str Frequency, supports 'tick', '60s', '300s', '900s', etc., the default is '1d', see stock market data and futures market data for details ,  frequency supported by real-time market
open float opening price
close float Closing price
high float highest price
low float lowest price
amount float turnover
volume long turnover
position long Open interest (futures only)
bob datetime.datetime bar start time
he datetime.datetime bar end time

Note:  if the target is not active, no bar will be generated if there is no trading volume

L2Order - Level2 order by order
parameter name type illustrate
symbol str target code
side str Entrusting direction Shenzhen: '1' buy, '2' sell, 'F' borrow, 'G' lend, Shanghai: 'B' buy, 'S' sell
price float commission price
volume int Order amount
order_type str Order type Shenzhen: '1' market price, '2' limit price, 'U' best, Shanghai: 'A' to add an order, 'D' to delete an order
order_index int Principal ID
created_at datetime.datetime creation time
L2Transaction - Level2 tick-by-tick
parameter name type illustrate
symbol str target code
side str Entrusted direction Shanghai stock market: B - external order, active buy, S - internal order, active sell, N - call auction, no such field in Shenzhen market
price float final price
volume int turnover
exec_type str Transaction type Shenzhen: '4' cancels order, 'F' closes, no such field in Shanghai
exec_index int transaction number
ask_order_index int Bid order number
bid_order_index int Call order number
created_at datetime.datetime creation time

4.2 Transaction class
Account - the account object
Attributes type illustrate
id str Account id, which is used to specify the trading account in real trading
cash dict Funding Dictionary
positions(symbol='', side=None) list 持仓情况 列表, 默认全部持仓, 可根据单一 symbol(类型 str), [side](/sdk/python/枚举常量.html#PositionSide - 持仓方向 "PositionSide - 持仓方向") 参数可缩小查询范围
position(symbol, side) dict 持仓情况 查询指定单一 symbol(类型 str)及持仓方向的持仓情况
status dict 交易账户状态 查询交易账户连接状态
Order - 委托对象
属性 类型 说明
strategy_id str 策略 ID
account_id str 账号 ID
account_name str 账户登录名
cl_ord_id str 委托客户端 ID,下单生成,固定不变(掘金维护,下单唯一标识)
order_id str 委托柜台 ID(系统字段,下单不会立刻生成,委托报到柜台才会生成)
ex_ord_id str 委托交易所 ID(系统字段,下单不会立刻生成,委托报到柜台才会生成)
algo_order_id str 算法单 ID
symbol str 标的代码
status int 委托状态 取值参考 OrderStatus
side int 买卖方向 取值参考 OrderSide
position_effect int 开平标志 取值参考 PositionEffect
position_side int 持仓方向 取值参考 PositionSide
order_type int 委托类型 取值参考 OrderType
order_duration int 委托时间属性 取值参考 OrderDuration
order_qualifier int 委托成交属性 取值参考 OrderQualifier
order_business int 委托业务属性 取值参考 OrderBusiness
ord_rej_reason int 委托拒绝原因 取值参考 OrderRejegectReason
ord_rej_reason_detail str 委托拒绝原因描述
position_src int 头寸来源(系统字段)
volume int 委托量
price float 委托价格
value int 委托额
percent float 委托百分比
target_volume int 委托目标量
target_value int 委托目标额
target_percent float 委托目标百分比
filled_volume int 已成量 (一笔委托对应多笔成交为累计值)
filled_vwap float 已成均价,公式为(price*(1+backtest_slippage_ratio)) (仅股票实盘支持,期货实盘不支持)
filled_amount float 已成金额,公式为(filled_volume*filled_vwap) (仅股票实盘支持,期货实盘不支持)
filled_commission float 已成手续费,(实盘不支持)
created_at datetime.datetime 委托创建时间
updated_at datetime.datetime 委托更新时间
ExecRpt - 回报对象
属性 类型 说明
strategy_id str 策略 ID
account_id str 账号 ID
account_name str 账户登录名
cl_ord_id str 委托客户端 ID
order_id str 柜台委托 ID
exec_id str 交易所成交 ID
symbol str 委托标的
side int 买卖方向 取值参考 OrderSide
position_effect int 开平标志 取值参考 PositionEffect
order_business int 委托业务属性 OrderBusiness
order_style int 委托风格 OrderStyle
ord_rej_reason int 委托拒绝原因 取值参考 OrderRejectReason
ord_rej_reason_detail str 委托拒绝原因描述
exec_type int 执行回报类型 取值参考 ExecType
price float 成交价格
volume int 成交量
amount float 成交金额
cost float 成交成本金额(仅期货实盘支持,股票实盘不支持)
created_at datetime.datetime 回报创建时间
Cash - 资金对象
属性 类型 说明
account_id str 账号 ID
account_name str 账户登录名
currency int 币种
nav float 总资产
fpnl float 浮动盈亏
frozen float 持仓占用资金 (仅期货实盘支持,股票实盘不支持)
order_frozen float 冻结资金
available float 可用资金
market_value float 市值
balance float 资金余额
created_at datetime.datetime 资金初始时间
updated_at datetime.datetime 资金变更时间
Position - 持仓对象
属性 类型 说明
account_id str 账号 ID
account_name str 账户登录名
symbol str 标的代码
side int 持仓方向 取值参考 PositionSide
volume int 总持仓量; 如果要得到昨持仓量,公式为 (volume - volume_today)
volume_today int 今日买入量
market_value float 持仓市值
vwap float 持仓均价 new_vwap=((position.vwap * position.volume)+(trade.volume*trade.price))/(position.volume+trade.volume) (实盘时,期货跨天持仓,会自动变成昨结价,仿真是开仓均价)
vwap_open float 开仓均价(期货适用,实盘适用)
vwap_diluted float 摊薄成本(股票适用,实盘适用)
amount float 持仓额 (volume*vwap*multiplier)
price float 当前行情价格(回测时值为 0)
fpnl float 持仓浮动盈亏 ((price - vwap) * volume * multiplier) (基于效率的考虑,回测模式 fpnl 只有仓位变化时或者一天更新一次,仿真模式 3s 更新一次, 回测的 price 为当天的收盘价) (根据持仓均价计算)
fpnl_open float 浮动盈亏(期货适用, 根据开仓均价计算)
cost float 持仓成本 (vwap * volume * multiplier * margin_ratio)
order_frozen int 挂单冻结仓位
order_frozen_today int 挂单冻结今仓仓位(仅上期所和上海能源交易所标的支持)
available int 非挂单冻结仓位 ,公式为(volume - order_frozen); 如果要得到可平昨仓位,公式为 (available - available_today)
available_today int 非挂单冻结今仓位,公式为 (volume_today - order_frozen_today)(仅上期所和上海能源交易所标的支持)
available_now int 当前可用仓位
credit_position_sellable_volume int 可卖担保品数
created_at datetime.datetime 建仓时间 (实盘不支持)
updated_at datetime.datetime 仓位变更时间 (实盘不支持)

Indicator - 绩效指标对象
属性 类型 说明
account_id str 账号 ID
pnl_ratio float 累计收益率 (pnl/cum_inout)
pnl_ratio_annual float 年化收益率 (pnl_ratio/自然天数*365)
sharp_ratio float 夏普比率 ([E(Rp)-Rf]/δp*sqrt(250),E(Rp) = mean(pnl_ratio),Rf = 0,δp = std(pnl_ratio) )
max_drawdown float 最大回撤 max_drawdown=max(Di-Dj)/Di;D 为某一天的净值(j>i)
risk_ratio float 风险比率 (持仓市值/nav)
calmar_ratio float 卡玛比率 年化收益率/最大回撤
open_count int 开仓次数
close_count int 平仓次数
win_count int 盈利次数(平仓价格大于持仓均价 vwap 的次数)
lose_count int Number of losses (the number of times the closing price is less than or equal to the average position price vwap)
win_ratio float 胜率 (win_count / (win_count + lose_count))
created_at datetime.datetime Indicator Creation Time
updated_at datetime.datetime Indicator change time

Guess you like

Origin blog.csdn.net/weixin_42219751/article/details/131783331