0

我正在尝试使用持有的特定股票的数量作为变量。

我的相关代码是:

    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(但这是不正确的)。

4

1 回答 1

0

一种方法是通过合同的特征来定义合同,例如

if contract.symbol == 'APPL':
    self.applestock_quantity_held = position
于 2022-02-24T01:15:12.370 回答