order - 按股数下单
1、代码
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock')
log.set_level('order','warning')
order_value("601318.XSHG",10000)
def handle_data(context, data):
print(context.portfolio.positions)
2、输出
available_cash: 可用资金, 可用来购买证券的资金
代码
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock') def handle_data(context, data):
print(context.portfolio.available_cash)
输出
total_amount: 总仓位, 但不包括挂单冻结仓位
1、代码
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock')
log.set_level('order','warning')
order_value("601318.XSHG",10000)
def handle_data(context, data):
print(context.portfolio.positions['601318.XSHG'].total_amount)
2、输出
today_amount: 今天开的仓位
1、代码
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock')
log.set_level('order','warning')
order_value("601318.XSHG",10000)
def handle_data(context, data):
print(context.portfolio.positions['601318.XSHG'].today_amount)
2、输出
closeable_amount: 可卖出的仓位 / 场外基金持有份额
1、代码
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock')
log.set_level('order','warning')
order_value("601318.XSHG",10000)
def handle_data(context, data):
print(context.portfolio.positions['601318.XSHG'].closeable_amount)
2、输出
打印数据
# 导入函数库
import jqdata #初始化函数,设定基准等等
def initialize(context):
set_benchmark('000300.XSHG')
g.security = get_index_stocks('000300.XSHG')
set_option('use_real_price',True)
set_order_cost(OrderCost(open_tax=0, close_tax=0.001, open_commission=0.0003, close_commission=0.0003,close_today_commission=0, min_commission=5),type='stock')
log.set_level('order','warning') def handle_data(context, data):
df = attribute_history('601318.XSHG', 5)
print(df)
输出