Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

interactive brokers - Unable to Retrieve Account Summary details from IBKR

This is my code:

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()

The only thing printing is the orderStatus function. I copied the exact code for the account summary from the IBKR github page. What am I doing wrong? I even tried changing the location of the orderStatus, yet it made no difference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add this line in your start method

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...