Blue shift ide - how to import and use custom libraries

The tutorial says to use custom libraries you create a directory, a init.py file willbe created then you can just add files.  However, no init.py is created and I cant create the python files as it doesnt obey naming conventions.  Can some explain how I can use the alpaca python api within my blueshift algorythm please?  Thanks

 

We will automatically add a blank init.py (which is not visible to you) so that your workspace directory can act like a python module. You can just simply create a directory, go and create a regular code file and define your functions or classes there. Then later on in some other directory, you can import it and use it. E.g.


  1. create a directory called foo. Create a strategy file named bar and wrife a function called xyz.
  2. create another directory called foo2. Create a straegy named bar2. Here you can import the 'xyz' function as 'from foo.bar import xyz'.

Thanks, okay I will have a go, although I'm not writing a python class of function I have trying to use an external library.  Is this the best way to do this, do I have to copy in every file, is there no way to support external libraries?  Is there an example of how to do this? Thanks

Maybe if I explain a bnit more of what I am trying to do.  I want to get all assets avaiable on alpaca, then I want to be able to select a bunch of stocks to buy, and if a stock changing state to a certain point, I want to sell that stock and pick another stock which fits a criteria.  My first step in initialize would be to get a complete list of assets.  Maybe I could just use a python request to all the http rest point to get the list?  Thanks again for any help.

Apologies, I was not clear. The method I explained before is useful to create your own module (typically a collections of functions, classes that you will use across your strategies). External packages cannot be created in that manner. We also have a whitelist which lists all external packages that are allowed on the platform.



The second thing your explained (screening all stocks based on a certain metric) can be achieved using the pipeline API (see here, we screen ALL stocks in S&P 500 based on a volume filter and then generate signals based on past returns).



However, for live trading (including for Alpaca), pipeline is not supported yet. At present you can define an exhausitve list (a much smaller list than all tickers supported by broker) to approximate this. The request module is not in whitelist. Even if were, a query to fetch data for all tickers will either freeze the program due to out-of-memory error or be banned by the broker for api rate limit violation, whichever happens first.



This means there is no way to monitor ALL stocks,. There is no method to list out ALL stocks. Universe covered by a broker (including Alpaca) can consists of tens of thousands of symbols.