为什么我不能使用(IBKR 的交易平台)ib-api positions 函数打印持有的股票数量? (部分解决)
Why can't I print the quantity of stock held using (IBKR's TWS) ib-api positions function? (partly solved)
我正在尝试使用持有的特定股票的数量作为变量。
我的相关代码是:
def position(self, account, contract, position, avgCost):
super().position(account, contract, position, avgCost)
print(contract, position)
# self.quantity_held = position
# if contract == 'applestock_contract':
# self.quantity_held = position
if contract == app.applestock_contract:
self.applestock_quantity_held = position # this was previously just "position", no "app."
# if contract == 'app.applestock_contract':
# self.quantity_held = position
我已经评论了我尝试过的其他代码。
当我尝试打印 applestock_contract 的值时,结果为 0(但这是不正确的)。
一种方法是根据合约的特征来定义合约
例如
if contract.symbol == 'APPL':
self.applestock_quantity_held = position
我正在尝试使用持有的特定股票的数量作为变量。
我的相关代码是:
def position(self, account, contract, position, avgCost):
super().position(account, contract, position, avgCost)
print(contract, position)
# self.quantity_held = position
# if contract == 'applestock_contract':
# self.quantity_held = position
if contract == app.applestock_contract:
self.applestock_quantity_held = position # this was previously just "position", no "app."
# if contract == 'app.applestock_contract':
# self.quantity_held = position
我已经评论了我尝试过的其他代码。
当我尝试打印 applestock_contract 的值时,结果为 0(但这是不正确的)。
一种方法是根据合约的特征来定义合约 例如
if contract.symbol == 'APPL':
self.applestock_quantity_held = position