Skip to content
robwsc edited this page Mar 27, 2023 · 2 revisions

Data is loaded into Stratis via Data Adapters. Data Adapters are classes that are used to fetch data from a datasource. They create OHLC objects that are used by the strategy.

OHLC objects are created using the .get_data() method.

You can view the source code for this class here

Currently, there is only one built in Data Adapter, the CSVAdapter. This adapter is used to load data from a CSV file. The shape of the CSV file should be as follows:

timestamp,open,high,low,close,volume

An example .csv file can be found in app/tests/data/AAPL.csv.

While the CSVAdapter is the only built in Data Adapter, it is easy to create your own. An example of a custom Data Adapter may look like this:

class APIDataAdapter(DataAdapter):

    url = os.getenv('DATA_API_URL', None)

    def get_data(self, symbol):

        if self.url is None:
            raise Exception('DATA_API_URL not set')

        # you will have to modify this to get the data from the API, this is just an example
        r = requests.get(f'{self.url}/data/{symbol}/ohlc')
        r.raise_for_status()
        candles = r.json().get('candles', [])

        # dataframe from the candles
        df = pd.DataFrame.from_records(candles)
        df.set_index('timestamp', inplace=True)

        # symbol object
        symbol = Symbol(symbol)

        # finally, create the OHLC object and return it
        ohlc = OHLC(symbol=symbol, dataframe=df)
        return ohlc
Clone this wiki locally