Cannot access moonshot strategies from satellite



Trying to create satellite script that will, among other things, import a moonshot strategy from codeload and call its methods. The line:

  from moonshot import Moonshot

which is at the beginning of basically every strategy triggers error “No module named ‘‘moonshot’’”. BTW no logs are created so it took me time to realize where the error is, as there is a name confusion with quantrocket.moonshot and codeload.moonshot.
The same code from Jupyter works.

Tried adding

-e git://github.com/quantrocket-llc/moonshot#egg=moonshot

to quantrocket.satellite.pip.txt - got requirement already satisfied.

The idea is to create a script that will run strategies with little bit more control than just ‘quantrocket moonshot trade’ command. Is this something not allowed in the quantrocket system?



Try this:

pip install quantrocket-moonshot


Same - requirement already satisfied.
I narrowed it a bit. If I have test.py file in codeload with the code:

import moonshot
from quantrocket.flightlog import FlightlogHandler
print("Test passed")

def test():
    logger = logging.getLogger("test1")
    handler = FlightlogHandler()
    logger.info("Test passed")

If I do:

quantrocket satellite exec 'python /codeload/test.py'

it works. But if I call:

quantrocket satellite exec codeload.test.test

I get “No module named ‘moonshot’” error. So I will probably stick to calling python directly in this case.


Actually running it with ‘python’ won’t help.
My problem was my script was in the /codeload/ root and lovely python import system. Just as experiment navigate to codeload, start terminal and run python from terminal, now enter:

from moonshot import Moonshot

It gives you error because it tries to import from codeload.moonshot. What happened to “global modules first”?

I’ve got it working, still the question - is it possible to stop quantrocket from adding init.py files into every folder?



Hmm, I’m not able to reproduce this. Relative imports are disabled via /opt/conda/lib/python3.6/site-packages/sitecustomize.py.

    # Disable relative imports (users must import from codeload)
    if "" in sys.path:

This means import moonshot won’t look for codeload.moonshot even if you’re in the codeload directory. This sitecustomize.py file gets installed on both jupyter and satellite. This has been in place since version 1.5.

In any case you can look at that file and install your own version if needed.


This is it! When I create python console from Jupyter, “” is not in sys.path, but when I call python from bash Terminal, “” is in sys.path for both my old installation and the new one (version 1.9.0). But I can simply add these lines to my scripts now. Thanks!