How to trigger a function when a new minute bar comes in.

Discussion in 'Automated Trading' started by Warren, Feb 23, 2023.

  1. Warren

    Warren

    Hi,

    As I am using ibapi in Python to retrieve minute data, I need some mechanism to trigger the data processing function when a new minute bar matured.

    While ib_insync offers this function by the eventkit( onBarUpdate += some_function), it does not seem to incorporate extra variables, for example, if you want to process some historic data when there are not enough bars.

    This must be a newbie question. But I have no idea at this moment how to implement it?
     
  2. 2rosy

    2rosy

    Code:
    def your_function():
        magic()
    
    onBarUpdate += your_function
    the += adds your function as a listener to the onBarUpdate event
     
  3. Warren

    Warren

    Yes, I know this trick as it appears in the example codes. The problem now is, your_function() defined this way, can not take extra variables such as historic data.
     
  4. 2rosy

    2rosy

    The function needs to get historic data