Exemple #1
0
 def test_ftx_algotrading_exception_raise(self):
     """Test that we can raise an FtxAlgotradingException"""
     self.assertRaises(
         FtxAlgotradingException,
         self.ExceptionRaiser.raise_ftx_algotrading_exception,
         FtxAlgotradingException("Error")
     )
    def stop_time_frame_acq(self, time_frame_length: int) -> None:
        """
        Stops the data acquisition for a given time frame

        :param time_frame_length: The given time frame
        """
        if time_frame_length not in self._time_frames:
            raise FtxAlgotradingException(
                f"Trying to stop a non existing time frame {time_frame_length} for market {self.market}"
            )

        self._time_frames[time_frame_length].stop()
    def get_time_frame(self, time_frame_length: int) -> TimeFrameManager:
        """
        Return the given time frame instance

        :param time_frame_length: The given time frame
        :return: The given time frame instance
        """
        if time_frame_length not in self._time_frames:
            raise FtxAlgotradingException(
                f"Trying to access a non existing time frame {time_frame_length} for market {self.market}"
            )

        return self._time_frames[time_frame_length]
Exemple #4
0
def check_fields_in_dict(dictionary, fields, dictionary_name) -> bool:
    """
    Check that the fields are in the dict and raise an exception if not

    :param dictionary: The dictionary in which the check has to be done
    :type dictionary: dict
    :param fields: List of fields to check
    :type fields: list[str]
    :param dictionary_name: name of the dictionary (for exception message purpose)
    :type dictionary_name: str
    :return: True if all the fields are in the given dictionary, raise an exception otherwise
    """
    for field in fields:
        if field not in dictionary:
            raise FtxAlgotradingException(
                "%s field(s) required but not found in %s: %s" %
                (", ".join(fields), dictionary_name, str(dictionary)))
    return True
    def add_time_frame(self, time_frame_length: int) -> None:
        """
        Add a new time frame

        :param time_frame_length: The length of the time frame in seconds (15, 60, 300, 900, 3600, 14400, 86400)
        """
        if time_frame_length not in SUPPORTED_TIME_FRAME_LENGTH:
            raise FtxAlgotradingException(
                f"Time frame length must be one of the following: "
                f"{', '.join([str(item) for item in SUPPORTED_TIME_FRAME_LENGTH])} "
            )

        if time_frame_length in self._time_frames:
            logging.warning(
                f"Time frame length ({time_frame_length}) is already managed for market {self.market}"
            )
            return

        self._time_frames[time_frame_length] = TimeFrameManager(
            time_frame_length, self.market, self._ftx_rest_api, self._lock)