Back to Community
Noobie Question ! Difference between handle_data and rebalance ?

I have been working on developing my first few algos, and reading through many examples for reference. I have read the API references, but am having trouble understanding the difference in use between handle_data and rebalance. They seem to both provide the same function (ability to order, record ) ?? or am I missing something? Would really appreciate any insight ! Cheers.

4 responses

Handle_data runs every minute. Rebalance (or whatever you call it) runs as often as you schedule it to run in Initialize.

Note that handle_data should not be used unless a set of code needs to run every minute.

First off, welcome!

The handle_data is a "built-in" method.

There are three "built-in" methods which get executed automagically.

  • initialize executed exactly once when the algorithm starts
  • before_trading_start executed before the
    market opens each day the market is open
  • handle_data executed
    every minute during trading hours

These method names are fixed. Any other methods such as 'rebalance' are completely user defined and not called automatically by the system. They must therefore be called in one of the three methods above OR scheduled to run at specific times using the 'schedule' function.

Rad ! Thanks y'all.