I'm currently porting over my algorithm from Quantopian and having some trouble. I use a framework for trading multiple algorithms on the same account simultaniously, using classes for each algo and some execution/decision classes tying them all together. Currently my algorithm is >1500 lines of code and seeing as how QC has a nice file system I figured I could move some of my utility funcions or even the algorithm classes over into separate files. I currently have 6 algorithm classes, each one is generating a buys/sells on different ETF's using price history data. Then there are some classes that make a decision on all those buy/sell signals, combining them into one portfolio. Then I have utility funcions such as a stop loss that also need price history data. It would be very inefficient/confusing to have them all running in OnData() all the time.

Here is my current understanding, maybe you can help with the gaps:

Quantopian: (this might not be ideal but it's how the framework that I'm using is set up, I didn't write it originally, still learning)

execution_manager = ExecutionHandler_Market()
def handle_data(context, data):
    target = desired_allocation
    execution_manager.execute_orders(context, data, target)
def utility(context, data):
    #do some stuff with data
#Define the Execution Handler module type.
class ExecutionHandler(object):
    def execute_orders(self, context, data, target_portfolio):
        raise NotImplementedError()
#ExecutionHandler_Market is an ExecutionHandler object that makes market orders
class ExecutionHandler_Market(ExecutionHandler):
    def execute_orders(self, context, data, target_portfolio):
        utility(context, data):
        #do some other stuff with data

QC:

?

I understand the general part of how to get functions/classes working across multiple files but I don't understand how to get account/stock/hisotry data into those files. They all need to access variables in Main.py, portfolio objects such as account cash value, holdings, price data, etc.

I've tried looking for examples of what I need but most algorithms on QC do all the data handling in OnData() and only put minor extranious functions in other files.