title: Interactive brokers TWS API Python Get Account Balance
body: <p>I am trying to get account balance and store it as a varible.
  The accountSummary value has the balance in it.
  I am using print to verify the var bal has the data stored in it.
  Print(bal) will display the information in the terminal but won't print it to file balance.txt.
  If the orderid example from the earlier executed code is working correctly why not the Balance?</p>
  <pre><code>from ibapi import wrapper
  from ibapi.client import EClient
  from ibapi.utils import iswrapper #just for decorator
  from ibapi.common import *
  import math
  import os.path
  from os import path
  
  class TestApp(wrapper.EWrapper, EClient):
      posns = []
      fname = 'fname.txt'
      def __init__(self):
          wrapper.EWrapper.__init__(self)
          EClient.__init__(self, wrapper=self)
  
      @iswrapper
      def nextValidId(self, orderId:int):
          print(&quot;setting nextValidOrderId: %d&quot;, orderId)
          self.nextValidOrderId = orderId
          file = open(&quot;orders.txt&quot;,&quot;w&quot;)
          file.write(str(orderId))
          file.close()
          # here is where you start using api
          self.reqAccountSummary(9002, &quot;All&quot;, &quot;$LEDGER&quot;)
  
    
      @iswrapper
      def accountSummary(self, reqId:int, account:str, tag:str, value:str, currency:str):
          bal=(value)
      
          file = open(&quot;Balance.txt&quot;,&quot;w&quot;)
          file.write(bal)
          file.close()
     
  
     
  
      @iswrapper
      def accountSummaryEnd(self, reqId:int):
          
          # now we can disconnect
          self.disconnect()
     
  def main():
      app = TestApp()
      app.connect(&quot;127.0.0.1&quot;, 7497, clientId=123)
      app.run()
  
    
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>