'IBAPI runs only once, have to restart the kernel for it to run again

im having an issue where I can run this code successfully once, but then when i want to run it again i have to completely restart the kernel for it to work again. can someone help?

the error i get at the second attempt to run is "ERROR 1 504 Not connected"

class IBApi (EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self,self)
   
class Bot:
    ib = None
    def __init__(self):
        self.ib = IBApi() #creating an IBAPI client
        self.ib.connect("127.0.0.1",7496,1)
        ib_thread = threading.Thread(target=self.run_loop,daemon=True) #daemon means program will shut down immediately when program exits 
        ib_thread.start()
        time.sleep(1) 
        
        symbol = input("Please input the symbol you want to trade: ")
                
        # Create IB contract object
        contract = Contract()
        contract.symbol = symbol.upper()
        contract.secType = "STK"
        contract.exchange = "SMART"
        contract.currency = "USD"
       
                    
        #Create order object
        order = Order()
        order.orderType = "MKT" #LMT, etc. 
        order.action = "BUY" #SELL, etc.
        quantity = 1
        order.totalQuantity = quantity
        
        #Create Contract object
        contract = Contract()
        contract.symbol = symbol.upper()
        contract.secType = "STK"
        contract.exchange = "SMART"
        contract.primaryExchange = "ISLAND" #prioritizing the NASDAQ - avoids your order not getting submitted
        contract.currency = "USD"

        self.ib.placeOrder(1,contract, order)
        
     # run method - should be last    
    def run_loop(self):
        self.ib.run()
    def on_bar_update(self, reqID, time, open_ ,high , low, close, volume, wap, count):
        print(reqID)

#Start bot

bot = Bot()


Solution 1:[1]

Here is how you can achieve it. Run the snippet below and enjoy :)

main > section {
  overflow-x: hidden;
  width: 400px;
  height: 100px;
  border: 1px solid #afafaf;
  border-radius: 5px;
}

.table_container { 
  overflow-x: scroll;
  background: forestgreen;
  color: #fff;
  width: auto;
  height: inherit;
  white-space: nowrap;
  padding: 20px;
}
<main>
  <section>
    <div class="table_container" >
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas nibh ante vel dui. Sed in tellus interdum eros vulputate placerat sed non enim. Pellentesque eget justo porttitor urna dictum fermentum.
    </div>
  </section>
</main>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduard