Data Maps
data_map
The data_map
is the name we give to a specific data structure that will be interacted with when retrieving requested datasource_topics
and candle_topics
data.
It resides within the Strategy class that is being inherited and can be accessed by using the super()
keyword. This data_map holds all the data that is requested via the datasource_topics
and
candle_topics
.
It is represented with the following type Dict[str, List[Dict[str, str]]]
.
Note that the returned values are typed as
str
. In order to use the values for calculation, please refer to documentation and coerce the str type to the appropriate types. Example:
self.data_map["candles-1m-BTC/USDT-bybit"][-1]["start_time"] # returns a string
float(self.data_map["candles-1m-BTC/USDT-bybit"][-1]["close"]) # returns a float, usable in calculations
This structure is given to the user thorugh self.data_map
and/or super().data_map
split_data_map
The split_data_map
is more performant when compared to the normal data_map
.
The split_data_map
, similar to the data_map
is a specific data structure that can be interacted with to retrieve requested datasource_topics
and candle_topics
.
Similar to the DataMap
it resides within the Strategy class and is accessed in the same manner with self.split_data_map
and/or super().split_data_map
It is represented with the following type Dict[str, Dict[str, collections.deque]]
.
The defining difference between the split_data_map
and the data_map
is that the data is stored by the topic's keys. For an example, a candles-1m-BTC/USDT-bybit
topic would be stored by the 'open', 'high', 'low', 'close' values. This can be represented similar to the example below.
Example:
latest_close = self.split_data_map["candles-1m-BTC/USDT-bybit"]["close"][-1];
close_arr = np.array(self.split_data_map["candles-1m-BTC/USDT-bybit"]["close"])
With the new accessing method, we are able to create a np_array directly without having to use map()
and also retrieve the latest data with much more clarity.
When to use which?
When writing your live strategy and/or backtests that are expected to be turned into live running strategies. The use of split_data_map
is suggested.
The more performant access as well as direct conversion to np.array
will be more beneficial in such a case.
On the other hand, if your goal is to retrieve datasource and have the data be stored in a tangible JSON state or even converting ot CSV with ease,
the use of data_map
is suggested.