339 浏览
0

3个问题

1、这边应该不是报错吧,

2、返回的数据都是字典数据吗,

3、只是字典内没有数据,是才报错吗

# 这是文档内容

# 正确运行的————————–

因为我试了下,我没有任何填写,打印的是为空的{}。

已回答的问题

为什么不是返回的0呢?

还是因为我从来没有持仓,所有返回的是空值,也就没有对象一说了?

0

{‘SHFE.rb2201’: <tqsdk.objs.Position object at 0x00000278722CCBB0>, D({‘exchange_id’: ‘SHFE’, ‘instrument_id’: ‘rb2201’, ‘pos_long_his’: 0, ‘pos_long_today’: 0, ‘pos_short_his’: 0, ‘pos_short_today’: 0, ‘volume_long_today’: 0, ‘volume_long_his’: 0, ‘volume_long’: 0, ‘volume_long_frozen_today’: 0, ‘volume_long_frozen_his’: 0, ‘volume_long_frozen’: 0, ‘volume_short_today’: 0, ‘volume_short_his’: 0, ‘volume_short’: 0, ‘volume_short_frozen_today’: 0, ‘volume_short_frozen_his’: 0, ‘volume_short_frozen’: 0, ‘open_price_long’: nan, ‘open_price_short’: nan, ‘open_cost_long’: nan, ‘open_cost_short’: nan, ‘position_price_long’: nan, ‘position_price_short’: nan, ‘position_cost_long’: nan, ‘position_cost_short’: nan, ‘float_profit_long’: nan, ‘float_profit_short’: nan, ‘float_profit’: nan, ‘position_profit_long’: nan, ‘position_profit_short’: nan, ‘position_profit’: nan, ‘margin_long’: nan, ‘margin_short’: nan, ‘margin’: nan, ‘market_value_long’: nan, ‘market_value_short’: nan, ‘market_value’: nan, ‘pos’: 0, ‘pos_long’: 0, ‘pos_short’: 0}), ‘SHFE.fu2201’: <tqsdk.objs.Position object at 0x00000278722A0820>, D({‘exchange_id’: ‘SHFE’, ‘instrument_id’: ‘fu2201’, ‘pos_long_his’: 0, ‘pos_long_today’: 0, ‘pos_short_his’: 0, ‘pos_short_today’: 0, ‘volume_long_today’: 0, ‘volume_long_his’: 0, ‘volume_long’: 0, ‘volume_long_frozen_today’: 0, ‘volume_long_frozen_his’: 0, ‘volume_long_frozen’: 0, ‘volume_short_today’: 0, ‘volume_short_his’: 0, ‘volume_short’: 0, ‘volume_short_frozen_today’: 0, ‘volume_short_frozen_his’: 0, ‘volume_short_frozen’: 0, ‘open_price_long’: nan, ‘open_price_short’: nan, ‘open_cost_long’: nan, ‘open_cost_short’: nan, ‘position_price_long’: nan, ‘position_price_short’: nan, ‘position_cost_long’: nan, ‘position_cost_short’: nan, ‘float_profit_long’: nan, ‘float_profit_short’: nan, ‘float_profit’: nan, ‘position_profit_long’: nan, ‘position_profit_short’: nan, ‘position_profit’: nan, ‘margin_long’: nan, ‘margin_short’: nan, ‘margin’: nan, ‘market_value_long’: nan, ‘market_value_short’: nan, ‘market_value’: nan, ‘pos’: 0, ‘pos_long’: 0, ‘pos_short’: 0})}
合约: SHFE.rb2201 pos_long: 0 pos_short: 0
合约: SHFE.fu2201 pos_long: 0 pos_short: 0

已回答的问题
0

正确写法:

for k,v in position.items():

print(v.pos_long)

不过即使这样,也不一定会打印0,

如果当天没有持仓、平仓,则position为空,不打印任何信息。

已回答的问题
0

entity类似字典的用法,你直接这么取肯定取不了,没有key值叫这个。第一张图他报错的error明确已经写了错误和错误类型

已回答的问题