我想要得到单个职位的平均成本。
我正在使用IB-insync API和reqPositions()。输出结果为:
[Position(account='DU1675421', contract=Stock(conId=29622888, symbol='HEIA', exchange='AEB', currency='EUR', localSymbol='HEIA', tradingClass='HEIA'), position=100.0, avgCost=90.97088),
Position(account='DU1675421', contract=Future(conId=176791153, symbol='N225M', lastTradeDateOrContractMonth='20191212', multiplier='100', currency='JPY', localSymbol='164120019', tradingClass='NK225M'), position=1.0, avgCost=2284540.0)]我想要1个职位的平均成本。我该怎么做呢?
b = ib.reqPositions()
while ib.sleep(0.5):
plb = b
print (plb)b.avgCost()不起作用。
发布于 2019-10-30 00:53:25
看起来像是reqPositions返回了一个命名元组列表。
要访问命名元组中的元素,需要遍历列表,例如
for position in b:
print(position.avgCost)https://stackoverflow.com/questions/58588921
复制相似问题