假设我的IB账户中只有一个职位 要检索它,我运行以下:
from time import sleep
from ib.opt import Connection, message, ibConnection
from ib.ext.Contract import Contract
def acc_update(msg):
global acc, expiry, exch, pExch, secType, symbol
acc = msg.account
exch = msg.contract.m_exchange
pExch = msg.contract.m_primaryExch
secType = msg.contract.m_secType
expiry = msg.contract.m_expiry
symbol = msg.contract.m_symbol
return acc, expiry, exch, pExch, secType, symbol
tws = ibConnection(port= 7497)
tws.register(acc_update, message.position)
tws.connect()
tws.reqPositions()
sleep(0.5)
tws.disconnect()
print( [symbol, acc, expiry, exch, pExch, secType])
这给了我: