主题
业务公共接口
账户类接口
get_user_name
中文名
获取登录终端的资金账号
接口说明
该接口用于获取登录终端的账号
接口定义
python
get_user_name(login_account=True)使用场景
❌研究 ✅回测 ✅交易
注意事项
- 回测中无论是否传入login_account参数均返回登录终端的资金账号。
- 交易中login_account参数不传或传入True时返回登录终端的资金账号。
- 交易中login_account参数传入False时返回当前策略绑定账号,如两融交易返回对应信用账号。
参数
login_account
- 类型:
bool - 默认:
True
True-返回登录终端的资金账号,False-返回当前策略绑定资金账号(如两融交易返回对应信用账号),选填字段
返回
str|None:
成功时,返回登录终端的资金账号/当前策略绑定账号
失败时,返回None
示例
python
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
g.current_id = get_user_name(False)
def before_trading_start(context, data):
g.flag = False
def handle_data(context, data):
# 账号为234567890且当日未委托过,担保品买卖100股
if g.current_id == "234567890" and not g.flag:
margin_trade(g.security, 100)
g.flag = Truefund_transfer
中文名
资金调拨
接口说明
用于UF20柜台与极速柜台、UF20柜台与极速柜台双中心资金调拨
接口定义
python
fund_transfer(trans_direction, occur_balance, exchange_type="1")使用场景
❌研究 ❌回测 ✅交易
注意事项
如要使用该函数,需咨询券商当前柜台是否支持。
当前仅支持UF20柜台与ATP柜台、UF20柜台与ATP柜台双中心资金调拨。
如果是UF20与ATP柜台,exchange_type可不传。
如果是UF20与ATP柜台双中心,exchange_type为必传字段。
参数
trans_direction
- 类型:
str
调拨方向,0-转入极速、1-转出极速, 必填参数
occur_balance
- 类型:
float
发生金额(单位:元,最小精度:0.01元),必填参数
exchange_type
- 类型:
str - 默认:
1
交易类别,1-上海,2-深圳,选填参数,选填参数
返回
bool:
成功调拨返回True
失败调拨返回False
示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def before_trading_start(context, data):
# 转出深A极速柜台100000元
fund_transfer('1', 100000, exchange_type='2')
def handle_data(context, data):
passmarket_fund_transfer
中文名
市场间资金调拨
接口说明
用于极速柜台双中心之间资金调拨
接口定义
python
market_fund_transfer(exchange_type, occur_balance)使用场景
❌研究 ❌回测 ✅交易
注意事项
如要使用该函数,需咨询券商当前柜台是否支持。
当前仅支持ATP柜台双中心之间资金调拨。
参数
exchange_type
- 类型:
str
交易类别,1-上海,2-深圳,必填参数
occur_balance
- 类型:
float
发生金额(单位:元,最小精度:0.01元),必填参数
返回
bool:
成功调拨返回True
失败调拨返回False
示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def before_trading_start(context, data):
# 转入沪A极速柜台100000元
market_fund_transfer('1', 100000)
def handle_data(context, data):
pass交易类接口
order_tick
中文名
tick行情触发买卖
接口说明
该接口用于在tick_data模块中进行买卖股票下单,可设定价格档位进行委托
接口定义
python
order_tick(sid, amount, priceGear='1', limit_price=None)使用场景
❌研究 ❌回测 ✅交易
注意事项
- 该函数只能在tick_data模块中使用。
参数
sid
- 类型:
str
股票代码,必填参数
amount
- 类型:
int
交易数量,正数表示买入,负数表示卖出,必填参数
priceGear
- 类型:
str - 默认:
1
盘口档位,level1:1~5买档/-1~-5卖档,level2:1~10买档/-1~-10卖档,选填参数
limit_price
- 类型:
float - 默认:
None
买卖限价,当输入参数中也包含priceGear时,下单价格以limit_price为主,选填参数
返回
str:
- 返回一个委托流水编号
示例
python
import ast
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
def tick_data(context,data):
security = g.security
current_price = ast.literal_eval(data[security]['tick']['bid_grp'][0])[1][0]
if current_price > 56 and current_price < 57:
# 以买一档下单
order_tick(g.security, -100, "1")
# 以卖二档下单
order_tick(g.security, 100, "-2")
# 以指定价格下单
order_tick(g.security, 100, limit_price=56.5)
def handle_data(context, data):
passcancel_order
中文名
撤单
接口说明
该接口用于取消订单,根据Order对象或order_id取消订单
接口定义
python
cancel_order(order_param)使用场景
❌研究 ✅回测 ✅交易
参数
order_param
- 类型:
Order/str
Order对象或者order_id,必填字段
返回
None
示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def handle_data(context, data):
_id = order(g.security, 100)
cancel_order(_id)
log.info(get_order(_id))cancel_order_ex
中文名
撤单
接口说明
该接口用于取消订单,根据get_all_orders返回列表中的单个字典取消订单。
接口定义
python
cancel_order_ex(order_param)使用场景
❌研究 ❌回测 ✅交易
注意事项
该函数仅可撤get_all_orders函数返回的可撤状态订单。
账户多个交易运行时调用该函数会撤销其他交易产生的订单,可能对其他正在运行的交易策略产生影响。
参数
order_param
类型:
dictget_all_orders函数返回列表的单个字典,必填字段
返回
None
示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
g.count = 0
def handle_data(context, data):
if g.count == 0:
log.info("当日全部订单为:%s" % get_all_orders())
# 遍历账户当日全部订单,对已报、部成状态订单进行撤单操作
for _order in get_all_orders():
if _order['status'] in ['2', '7']:
cancel_order_ex(_order)
if g.count == 1:
# 查看撤单是否成功
log.info("当日全部订单为:%s" % get_all_orders())
g.count += 1debt_to_stock_order
中文名
债转股委托
接口说明
该接口用于可转债转股操作。
接口定义
python
debt_to_stock_order(security, amount)使用场景
❌研究 ❌回测 ✅交易
注意事项
该函数仅可撤get_all_orders函数返回的可撤状态订单。
账户多个交易运行时调用该函数会撤销其他交易产生的订单,可能对其他正在运行的交易策略产生影响。
参数
security
类型:
str可转债代码,必填字段
amount
类型:
int委托数量,必填字段
返回
str|None:
- 创建订单成功,则返回订单编号。对应
Order对象中的id - 创建订单失败,返回
None
示例
python
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
def before_trading_start(context, data):
g.count = 0
def handle_data(context, data):
if g.count == 0:
# 对持仓内的国贸转债进行转股操作
debt_to_stock_order("110033.XSHG", -1000)
g.count += 1
# 查看委托状态
log.info(get_orders())
g.count += 1查询类接口
get_order
中文名
获取指定订单
接口说明
该接口用于获取指定编号订单。
接口定义
python
get_order(order_id)使用场景
❌研究 ✅回测 ✅交易
参数
order_id
类型:
str订单编号,必填字段
返回
list[Order]:
- 返回一个list,该list中只包含一个Order对象,如:
python
[<Order {'id': '52e6a3f8a2b7468e92258c52dfcb6d42', 'dt': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'priceGear': 0, 'limit': 34.1, 'symbol': '600570.XSHG', 'amount': 1000, 'created': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'filled': 0, 'status': '2', 'entrust_no': '3596', 'cancel_entrust_no': None}>]示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def handle_data(context, data):
order_id = order(g.security, 100)
current_order = get_order(order_id)
log.info(current_order)get_open_orders
中文名
获取未完成订单
接口说明
该接口用于获取当天所有未完成的订单,或按条件获取指定未完成的订单。
接口定义
python
get_open_orders(security=None)使用场景
❌研究 ✅回测 ✅交易
注意事项
该接口仅支持获取本策略内的订单
未完成的状态(status(str))包括以下类型:
- '0' -- "未报"
- '1' -- "待报"
- '2' -- "已报"
- '3' -- "已报待撤"
- '4' -- "部成待撤"
- '7' -- "部成"
参数
security
类型:
str默认:
None标的代码,如'600570.XSHG',选填字段,不传时默认为获取所有未成交订单
返回
list[Order,...]:
- 返回一个list,该list中包含多个Order对象,如:
python
[<Order {'id': '52e6a3f8a2b7468e92258c52dfcb6d42', 'dt': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'priceGear': 0, 'limit': 34.1, 'symbol': '600570.XSHG', 'amount': 1000, 'created': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'filled': 0, 'status': '2', 'entrust_no': '3596', 'cancel_entrust_no': None}>]示例
python
def initialize(context):
g.security = ['600570.XSHG', '000001.XSHE']
set_universe(g.security)
def handle_data(context, data):
for _sec in g.security:
_id = order(_sec, 100, limit_price = 30)
# 当运行周期为分钟则可获取本周期及之前所有未完成的订单
dict_list = get_open_orders()
log.info(dict_list)
# 当运行周期为天,可在after_trading_end中调用此函数获取当天未完成的订单
def after_trading_end(context, data):
dict_list = get_open_orders()
log.info(dict_list)get_orders
中文名
获取全部订单
接口说明
该接口用于获取策略内所有订单,或按条件获取指定订单。
接口定义
python
get_orders(security=None)使用场景
❌研究 ✅回测 ✅交易
参数
security
类型:
str默认:
None标的代码,如'600570.XSHG',选填字段,不传时默认为获取所有订单
返回
list[Order,...]:
- 返回一个list,该list中包含多个Order对象,如:
python
[<Order {'id': '52e6a3f8a2b7468e92258c52dfcb6d42', 'dt': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'priceGear': 0, 'limit': 34.1, 'symbol': '600570.XSHG', 'amount': 1000, 'created': datetime.datetime(2025, 2, 21, 11, 25, 1, 229575), 'filled': 0, 'status': '2', 'entrust_no': '3596', 'cancel_entrust_no': None}>]示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def handle_data(context, data):
order(g.security, 100)
order(g.security, 200)
current_order = get_orders(g.security)
log.info(current_order)get_all_orders
中文名
获取账户当日全部订单
接口说明
该接口用于获取账户当日所有订单(包含非本交易的订单记录),或按条件获取指定代码的订单。
接口定义
python
get_all_orders(security=None)使用场景
❌研究 ❌回测 ✅交易
注意事项
- 该函数返回账户当日在柜台的全部委托记录,不能查询策略中待报、未报状态的委托。
- 该函数返回的可撤委托仅可通过cancel_order_ex函数进行撤单,且非本交易的委托进行撤单仅可通过本函数查询委托状态更新。
- 股票、两融、港股通业务返回的amount字段区分正负值,卖出为负数;期货业务返回的amount字段不区分正负值,均为正数。
参数
security
类型:
str默认:
None标的代码,如'600570.XSHG',选填字段,不传时默认为获取所有订单
返回
list[Order,...]:
返回一个list,该list中包含多条订单记录
股票、两融、港股通返回如下:
python
[{'symbol': , 'entrust_no': , 'amount': , 'entrust_bs': , 'price': , 'status': , 'filled_amount': , 'entrust_time': }, ...]- 期货返回如下:
python
[{'symbol': , 'entrust_no': , 'amount': , 'entrust_bs': , 'price': , 'status': , 'filled_amount': , 'entrust_time': , 'futures_direction': }, ...]字段含义如下:
symbol: 标的代码(str)
entrust_no: 委托编号(str)
amount: 委托数量(int)
entrust_bs: 委托方向(int);
price: 委托价格(float)
status: 委托状态(str);
filled_amount: 成交数量(int)
entrust_time: 委托时间(str)
futures_direction: 期货开平仓类型,期货专用(str)
示例
python
def initialize(context):
g.security = '600570.XSHG'
set_universe(g.security)
def handle_data(context, data):
# 获取账户当日委托600570代码的全部订单
log.info('当日委托600570代码的全部订单:%s' % get_all_orders(g.security))
# 获取账户当日全部订单
log.info('当日全部订单:%s' % get_all_orders())get_trades
中文名
获取当日成交订单
接口说明
该接口用于获取策略内当日已成交订单详情。
接口定义
python
get_trades()使用场景
❌研究 ✅回测 ✅交易
注意事项
- 为减小对柜台压力,该函数在股票/港股通交易模块中同一分钟内多次调用返回当前分钟首次查询的缓存数据。
- 该接口会返回当日截止到当前时间段内的成交数据。
- 一个订单编号会对应一笔或多笔成交记录。
- 不同品种返回字段不同。
- 股票标的代码尾缀为四位,上证为XSHG,深圳为XSHE,如需对应到代码请做代码尾缀兼容。
- 获取国债逆回购成交详情时,成交价格字段实际为回购利率。
返回
dict{str: list[list[], list[], ...]:
- 返回一个订单编号的一笔或多笔成交,其中:
python
# 股票、港股通返回字段格式(dict格式)
{
'订单编号': [
[
成交编号,
委托编号,
标的代码,
买卖类型,
成交数量,
成交价格,
成交金额,
成交时间
]
]
}
# 期货返回字段格式(dict格式)
{
'订单编号': [
[
成交编号,
委托编号,
标的代码,
买卖类型,
开平仓类型,
成交数量,
成交价格,
成交金额,
成交时间
]
]
}
- 成交编号:str类型
- 委托编号:str类型
- 标的代码:str类型
- 买卖类型:str类型
- 开平仓类型:开仓、平仓、平今仓,仅支持衍生品业务,str类型
- 成交数量:float类型
- 成交价格:float类型
- 成交金额:float类型
- 成交时间:YYYY-mm-dd HH:MM:SS格式,str类型python
# 实际返回示例(dict格式)
{
'ba6a80d9746347a99c050b29069807c7': [
[
'5001', # 成交编号
'700001', # 委托编号
'600570.XSHG', # 标的代码
'买', # 买卖类型
100000.0, # 成交数量
86.60, # 成交价格
8660000.0, # 成交金额
'2021-08-15 09:32:00' # 成交时间
]
]
}示例
python
def initialize(context):
# 初始化策略
g.security = "600570.XSHG"
set_universe(g.security)
def before_trading_start(context, data):
g.count = 0
def handle_data(context, data):
if g.count == 0:
# 按照回购利率1.76委托国债逆回购
order("204001.XSHG", -1000, 1.76)
g.count += 1
log.info(get_trades())get_position
中文名
获取单只标的持仓信息
接口说明
该接口用于获取某个标的持仓信息详情。
接口定义
python
get_position(security)使用场景
❌研究 ✅回测 ✅交易
参数
security
类型:
str标的代码,如'600570.SS',必填字段
支持品种:
- 股票
- ETF
- LOF
- 期货
- 港股通
返回
Position:
- 返回一个Position对象,如:
python
<Position {
'business_type': 'stock',
'short_amount': 0,
'contract_multiplier': 1,
'short_pnl': 0,
'delivery_date': None,
'today_short_amount': 0,
'last_sale_price': 118.7,
'sid': '600570.SS',
'enable_amount': 100,
'margin_rate': 1,
'amount': 200,
'long_amount': 0,
'short_cost_basis': 0,
'today_long_amount': 0,
'cost_basis': 117.9,
'long_pnl': 0,
'long_cost_basis': 0
}>示例
python
def initialize(context):
g.security = '600570.SS'
set_universe(g.security)
def handle_data(context, data):
position = get_position(g.security)
log.info(position)get_positions
中文名
持仓查询
接口说明
获取多个标的的持仓信息详情,支持按标的代码查询或获取全部持仓信息。
接口定义
python
get_positions(security=None)使用场景
❌研究 ✅回测 ✅交易
注意事项
四位尾缀或者两位尾缀代码皆可作为键取到返回的数据字典值,如'600570.XSHG'或者'600570.SS'。
参数
security
类型:
list[str]/str默认:
None标的代码,可以是一个列表,选填字段,不传时默认为获取所有持仓
支持品种:
- 股票
- ETF
- LOF
- 期货
- 港股通
返回
dict[str:Position]:
- 返回一个数据字典,键为标的代码,值为Position对象,如:
python
{
'600570.SS': <Position {
'business_type': 'stock',
'short_amount': 0,
'contract_multiplier': 1,
'short_pnl': 0,
'delivery_date': None,
'today_short_amount': 0,
'last_sale_price': 118.7,
'sid': '600570.SS',
'enable_amount': 100,
'margin_rate': 1,
'amount': 200,
'long_amount': 0,
'short_cost_basis': 0,
'today_long_amount': 0,
'cost_basis': 117.9,
'long_pnl': 0,
'long_cost_basis': 0
}>
}示例
python
def initialize(context):
g.security = ['600570.SS','600000.SS']
set_universe(g.security)
def handle_data(context, data):
log.info(get_positions('600570.SS'))
log.info(get_positions(g.security))
log.info(get_positions())get_all_positions
中文名
获取全部持仓信息
接口说明
获取当前账户的持仓信息详情,包括股票、融资融券、期货、港股通等所有持仓信息。
接口定义
python
get_all_positions()使用场景
❌研究 ❌回测 ✅交易
注意事项
- 因不同柜台返回的字段存在差异,当该接口返回的字段不在返回字段描述中时请咨询券商人员。
- 不同柜台返回的字段值类型不一致,比如不同柜台返回的enable_amount类型有可能为str/float/int,需要策略中对此做兼容。
- 该接口返回当前账户所有的持仓信息,包含国债逆回购产生的新标准券、打新中签尚未上市等量化不支持标的的持仓。
- 为减小对柜台压力,该函数返回的是缓存的账户定时同步持仓查询数据。
返回
list[dict[],...]:
- 返回一个列表,包含不同标的字典类型的持仓信息。不同交易类型返回不同字段的持仓信息,如:
md
[
{
'position_str': '0111900000000001926516100010000000000A027483621600010',
'fund_account': '19265161',
'exchange_type': '1',
'stock_account': 'A027483621',
'stock_code': '600010',
'stock_name': '包钢股份',
'stock_type': '0',
'current_amount': 8300.0,
'enable_amount': 0.0,
'last_price': 1.86,
'cost_price': 1.862,
'keep_cost_price': 1.862,
'income_balance': -18.22,
'hand_flag': '0',
'market_value': 15438.0,
'av_buy_price': 0.0,
'av_income_balance': 0.0,
'client_id': '19265161',
'cost_balance': 15443.25,
'hold_amount': 0.0,
'uncome_buy_amount': 0.0,
'uncome_sell_amount': 0.0,
'entrust_sell_amount': 0.0,
'real_buy_amount': 8300.0,
'real_sell_amount': 0.0,
'asset_price': 1.86,
'delist_flag': '0',
'delist_date': 0,
'par_value': 1.0,
'income_balance_nofare': -5.25,
'frozen_amount': 0.0,
'profit_ratio': -0.11,
'sub_stock_type': '!',
'stbtrans_type': ' ',
'stb_layer_flag': ' ',
'av_cost_price': 1.861,
'income_flag': ' ',
'real_sell_balance': 0.0,
'real_buy_balance': 15443.25,
'sum_buy_amount': 0.0,
'sum_buy_balance': 0.0,
'sum_sell_amount': 0.0,
'sum_sell_balance': 0.0,
'correct_amount': 0.0,
'stbtrans_flag': ' ',
'stock_name_long': '包钢股份',
'pre_dr_price': 1.86,
'close_price': 1.86,
'hold_cost_price': 1.861,
'comb_hold_flag': '0',
'store_unit': 1
}
]- 股票
md
exchange_type 交易类别
stock_code 证券代码
stock_name 证券名称
stock_type 证券类别
hold_amount 持有数量
current_amount 当前数量
enable_amount 可用数量
real_buy_amount 回报买入数量
real_sell_amount 回报卖出数量
uncome_buy_amount 未回买入数量
uncome_sell_amount 未回卖出数量
entrust_sell_amount 委托卖出数量
last_price 最新价
cost_price 成本价
keep_cost_price 保本价
income_balance 盈亏金额
market_value 证券市值
av_buy_price 买入均价
av_income_balance 实现盈亏
cost_balance 持仓成本
delist_flag 退市标志
delist_date 退市日期
income_balance_nofare 无费用盈亏
frozen_amount 冻结数量
profit_ratio 盈亏比例(%)
asset_price 市值价
av_cost_price 摊薄成本价- 港股通
md
exchange_type 交易类别
stock_code 证券代码
stock_name 证券名称
stock_type 证券类别
hold_amount 持有数量
current_amount 当前数量
enable_amount 可用数量
real_buy_amount 回报买入数量
real_sell_amount 回报卖出数量
uncome_buy_amount 未回买入数量
uncome_sell_amount 未回卖出数量
entrust_sell_amount 委托卖出数量
last_price 最新价
cost_price 成本价
keep_cost_price 保本价
income_balance 盈亏金额
market_value 证券市值
av_buy_price 买入均价
av_income_balance 实现盈亏
cost_balance 持仓成本
delist_flag 退市标志
delist_date 退市日期
par_value 面值
frozen_amount 冻结数量
profit_ratio 盈亏比例(%)- 融资融券
md
exchange_type 交易类别
stock_code 证券代码
stock_name 证券名称
current_amount 当前数量
hold_amount 持有数量
enable_amount 可用数量
last_price 最新价
cost_price 成本价
income_balance 盈亏金额
income_balance_nofare 无费用盈亏
market_value 证券市值
av_buy_price 买入均价
av_income_balance 实现盈亏
cost_balance 持仓成本
uncome_buy_amount 未回买入数量
uncome_sell_amount 未回卖出数量
entrust_sell_amount 委托卖出数量
real_buy_amount 回报买入数量
real_sell_amount 回报卖出数量
asset_price 市值价
assure_ratio 担保折算率
profit_ratio 盈亏比例(%)
sum_buy_amount 累计买入数量
sum_buy_balance 累计买入金额
sum_sell_amount 累计卖出数量
sum_sell_balance 累计卖出金额
real_buy_balance 回报买入金额
real_sell_balance 回报卖出金额
av_cost_price 摊薄成本价- 期货
md
futu_exch_type 交易类别
futu_code 合约代码
entrust_bs 委托方向
begin_amount 期初数量
enable_amount 可用数量
real_enable_amount 当日开仓可用数量
hold_income_float 持仓浮动盈亏
hold_income 期货盯市盈亏
hold_margin 持仓保证金
average_price 平均价
average_hold_price 持仓均价
tas_average_hold_price TAS持仓均价
futu_last_price 最新价格
hedge_type 投机/套保类型
real_amount 成交数量
real_open_balance 回报开仓金额
old_open_balance 老仓持仓成交额
real_current_amount 今总持仓
old_current_amount 老仓持仓数量
tas_current_amount TAS持仓数量
combinable_amount 可组合持仓数量- 其中,delist_date:默认为0。
示例
python
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
def before_trading_start(context, data):
g.flag = False
def handle_data(context, data):
if not g.flag:
# 打印当前账户全部持仓
log.info(get_all_positions())
g.flag = Trueget_deliver
中文名
获取历史交割单信息
接口说明
该接口用来获取账户历史交割单信息。
接口定义
python
get_deliver(start_date, end_date)使用场景
❌研究 ❌回测 ✅交易
注意事项
- 仅支持查询上一个交易日(包含)之前的交割单信息。
- 因不同柜台返回的字段存在差异,因此接口返回的为柜台原数据,使用时请根据实际柜台信息做字段解析。
- 该接口仅支持查询普通股票账户(非两融)。
- 对接ATP柜台不支持该函数。
参数
start_date
类型:
str开始日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
end_date
类型:
str结束日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
返回
list[dict,...]:
- 返回一个list类型对象,包含一个或N个dict,每个dict为一条交割单信息,其中包含柜台返回的字段信息,失败则返回空list[],如:
md
[
{
'entrust_way': '7',
'exchange_fare': 0.04,
'post_balance': 3539128.83,
'stock_account': '0010110920',
'exchange_farex': 0.0,
'fare0': 0.5,
'report_milltime': 110400187,
'business_balance': 2987.0,
'exchange_fare5': 0.0,
'fare_remark': '内部:.5( | ,费用类别:9999)',
'client_id': '10110920',
'uncome_flag': '0',
'exchange_fare0': 0.03,
'exchange_fare2': 0.0,
'fare1': 0.0,
'init_date': 20210811,
'stock_code': '162605',
'occur_amount': 1000.0,
'report_time': 110400,
'entrust_bs': '1',
'seat_no': '123456',
'business_id': '0110351000000242',
'business_amount': 1000.0,
'business_time': 110351,
'fund_account': '10110920',
'begin_issueno': ' ',
'post_amount': 1000.0,
'correct_amount': 0.0,
'money_type': '0',
'client_name': '客户10110920',
'business_type': '0',
'business_flag': 4002,
'clear_balance': -2987.5,
'exchange_fare1': 0.0,
'date_back': 20210811,
'branch_no': 1011,
'serial_no': 153,
'occur_balance': -2987.5,
'stock_name': '景顺鼎益',
'curr_time': 173028,
'exchange_fare4': 0.0,
'brokerage': 0.0,
'business_name': '证券买入',
'order_id': 'F04Z',
'business_times': 1,
'entrust_date': 20210811,
'remark': '证券买入;uft节点:31;',
'exchange_fare6': 0.0,
'standard_fare0': 0.5,
'exchange_fare3': 0.01,
'farex': 0.0,
'clear_fare0': 0.46,
'entrust_no': '38',
'profit': 0.0,
'exchange_type': '2',
'fare2': 0.0,
'business_no': 181,
'stock_type': 'L',
'fare3': 0.0,
'business_status': '0',
'business_price': 2.987,
'position_str': '020210811010110000000153',
'stock_name_long': '景顺鼎益LOF',
'report_no': '38',
'correct_balance': 0.0,
'exchange_rate': 0.0
}
]示例
python
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
def before_trading_start(context, data):
h = get_deliver('20210101', '20211117')
log.info(h)
def handle_data(context, data):
passget_fundjour
中文名
获取历史资金流水信息
接口说明
该接口用来获取账户历史资金流水信息。
接口定义
python
get_fundjour(start_date, end_date)使用场景
❌研究 ❌回测 ✅交易
注意事项
- 仅支持查询上一个交易日(包含)之前的资金流水信息。
- 因不同柜台返回的字段存在差异,因此接口返回的为柜台原数据,使用时请根据实际柜台信息做字段解析。
- 该接口仅支持查询普通股票账户(非两融)。
- 对接jz_ufx、ATP、云订柜台不支持该函数。
参数
start_date
类型:
str开始日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
end_date
类型:
str结束日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
返回
list[dict,...]:
- 返回一个list类型对象,包含一个或N个dict,每个dict为一条资金流水,其中包含柜台返回的字段信息,失败则返回空list[],如:
md
[
{
'post_balance': 3260341.36,
'init_date': 20210104,
'asset_prop': '0',
'serial_no': 1,
'business_flag': 4002,
'occur_balance': -10598.21,
'exchange_type': '0',
'stock_name': ' ',
'business_date': 20210104,
'business_price': 0.0,
'bank_no': '0',
'occur_amount': 0.0,
'remark': '证券买入,恒生电子,100股,价格105.93',
'stock_account': ' ',
'money_type': '0',
'fund_account': '10110920',
'position_str': '20210104010110000000001',
'bank_name': '内部银行',
'business_name': '证券买入',
'stock_code': ' ',
'curr_date': 20210104,
'entrust_bs': ' ',
'business_time': 171730
}
]示例
python
def initialize(context):
g.security = "600570.XSHG"
set_universe(g.security)
def before_trading_start(context, data):
h = get_fundjour('20210101', '20211117')
log.info(h)
def handle_data(context, data):
passget_lucky_info
中文名
获取历史中签信息
接口说明
该接口用于获取指定时间范围内的中签信息。
接口定义
python
get_lucky_info(start_date, end_date)使用场景
❌研究 ❌回测 ✅交易
注意事项
- 为减小对柜台压力,该函数在股票交易模块中同一分钟内多次调用返回当前分钟首次查询的缓存数据。
- 对接jz_ufx柜台不支持该函数。
参数
start_date
类型:
str开始日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
end_date
类型:
str结束日期,输入形式仅支持"YYYYmmdd",如'20170620',必填字段
返回
list[dict,...]:
- 正常返回一个列表套字典数据,异常或无中签信息时返回一个空列表,正常数据如:
md
[
{
'stock_code': 证券代码(str),
'occur_amount': 发生数量(float),
'business_price': 成交价格(float),
'stock_name': 证券名称(str),
'init_date': 交易日期(int)
},
...
]
[
{
'stock_code': '371002.XZ',
'occur_amount': 10.0,
'business_price': 100.0,
'stock_name': '崧盛发债',
'init_date': 20220928
},
...
]示例
python
def initialize(context):
# 初始化策略
g.security = "600570.SS"
set_universe(g.security)
def before_trading_start(context, data):
pre_date = str(get_trading_day(-1)).replace("-", "")
current_date = context.blotter.current_dt.strftime("%Y%m%d")
# 获取上一交易日至今天中签信息
lucky_info = get_lucky_info(pre_date, current_date)
log.info(lucky_info)
def handle_data(context, data):
pass说明
接口支持的业务范围以及支持在引擎的哪些流程函数中调用,详见 接口列表