3个问题
1、这边应该不是报错吧,
2、返回的数据都是字典数据吗,
3、只是字典内没有数据,是才报错吗
# 这是文档内容
# 正确运行的————————–
因为我试了下,我没有任何填写,打印的是为空的{}。
还是因为我从来没有持仓,所有返回的是空值,也就没有对象一说了?
{‘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
正确写法:
for k,v in position.items():
print(v.pos_long)
不过即使这样,也不一定会打印0,
如果当天没有持仓、平仓,则position为空,不打印任何信息。
为什么不是返回的0呢?