【问题标题】:Unable to Retrieve Account Summary details from IBKR无法从 IBKR 检索账户摘要详细信息
【发布时间】:2021-04-13 04:19:21
【问题描述】:

这是我的代码:

class TestApp(EWrapper, EClient):

    def __init__(self):
        EClient.__init__(self, self)
        self.nextOrderID = 0  # if this is init code put it in init

    def Error(self, reqID, errorCode, errorString):
        print('Error :', reqID, '', errorCode, '', errorString)

    def contractDetails(self, reqID, contractDetails):
        print('Contract Details :', reqID, '', contractDetails)

    def nextValidId(self, orderId):
        self.nextOrderID = orderId
        self.start()

    def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId,
                    whyHeld, mktCapPrice):
        print('Orderstatus Id. ', orderId, 'Status: ', status, 'Filled: ', 'Remaining: ', remaining,
              'Last Fill Price: ', lastFillPrice)
        if remaining == 0.0:
            self.stop()


    def execDetails(self, reqId, contract, execution):
        print('Exec Details. ', reqId, contract.symbol, contract.secType, contract.currency, execution.execId,
              execution.orderId, execution.shares, execution.lastLiquidity)

    def accountSummary(self, reqId, account, tag, value, currency):
        self.reqAccountSummary(reqId,account, tag, value )
        print('Account Summary. ', reqId, account, tag, value, currency)

    def start(self):
        contract = Contract()
        contract.symbol = 'NFLX'
        contract.secType = 'STK'
        contract.exchange = 'SMART'
        contract.currency = 'USD'

        order = Order()
        order.action = 'BUY'
        order.totalQuantity = 1
        order.orderType = 'MKT'
        #order.lmtPrice = 523.5

        self.placeOrder(self.nextOrderID, contract, order)
        self.nextOrderID += 1  # always increment after use

    def stop(self):
        if self.isConnected():
            print("disconnecting")
            self.disconnect()


def main():
    app = TestApp()
    app.connect('127.0.0.1', 7497, 0)
    
    app.run()
main()

唯一打印的是 orderStatus 函数。我从 IBKR github 页面复制了账户摘要的确切代码。我究竟做错了什么?我什至尝试更改 orderStatus 的位置,但没有任何区别。

【问题讨论】:

标签: interactive-brokers tws ib-api


【解决方案1】:

在你的启动方法中添加这一行

self.reqAccountSummary(9002, "All", "$LEDGER")

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 2012-02-20
    • 2018-05-21
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2011-03-06
    相关资源
    最近更新 更多