Exemple #1
0
    def __init__(self,
                 startingBalance: float = 1000,
                 interval: str = '1h',
                 symbol: str = 'BTCUSDT',
                 loadData: bool = True,
                 updateData: bool = True,
                 logFile: str = 'simulation',
                 precision: int = 2,
                 addTradeCallback=None):
        """
        SimulationTrader object that will mimic real live market trades.
        :param startingBalance: Balance to start simulation trader with.
        :param interval: Interval to start trading on.
        :param symbol: Symbol to start trading with.
        :param loadData: Boolean whether we load data from data object or not.
        :param updateData: Boolean for whether data will be updated if it is loaded.
        :param logFile: Filename that logger will log to.
        :param precision: Precision to round data to.
        :param addTradeCallback: Callback signal to emit to (if provided) to reflect a new transaction.
        """
        super().__init__(precision=precision,
                         symbol=symbol,
                         startingBalance=startingBalance)
        self.logger = get_logger(logFile=logFile,
                                 loggerName=logFile)  # Get logger.
        self.dataView: Data = Data(interval=interval,
                                   symbol=symbol,
                                   loadData=loadData,
                                   updateData=updateData,
                                   logObject=self.logger,
                                   precision=precision)
        self.binanceClient = self.dataView.binanceClient  # Retrieve Binance client.
        self.symbol = self.dataView.symbol  # Retrieve symbol from data-view object.

        self.previousNet = self.balance  # Our previous net will just be the starting balance in the beginning.
        self.coinName = self.get_coin_name()  # Retrieve primary coin to trade.
        self.commissionPaid = 0  # Total commission paid to broker.
        self.dailyChangeNets = [
        ]  # Daily change net list. Will contain list of all nets.

        self.completedLoop = True  # Loop that'll keep track of bot. We wait for this to turn False before some action.
        self.lock = Lock(
        )  # Lock to ensure a transaction doesn't occur when another one is taking place.
        self.addTradeCallback = addTradeCallback

        self.customStopLoss = None  # Custom stop loss to use if we want to exit trade before trailing or stop loss.
        self.stopLoss = None  # Price at which bot will exit trade due to stop loss limits.
        self.smartStopLossEnter = False  # Boolean that'll determine whether current position is from a smart stop loss.
        self.scheduledSafetyTimer = None  # Next time to check if it's a true stop loss.

        self.inHumanControl = False  # Boolean that keeps track of whether human or bot controls transactions.
        self.trend = None

        self.optionDetails = [
        ]  # Current option values. Holds most recent option values.
        self.lowerOptionDetails = [
        ]  # Lower option values. Holds lower interval option values (if exist).
Exemple #2
0
 def __init__(self,
              startingBalance: float = 1000,
              interval: str = '1h',
              symbol: str = 'BTCUSDT',
              loadData: bool = True,
              updateData: bool = True,
              isSpot: bool = False,
              inSpot: bool = False,
              logFile: str = 'simulation',
              precision: int = 2,
              addTradeCallback=None):
     """
     SimulationTrader object that will mimic real live market trades.
     :param startingBalance: Balance to start simulation trader with.
     :param interval: Interval to start trading on.
     :param symbol: Symbol to start trading with.
     :param loadData: Boolean whether we load data from data object or not.
     :param updateData: Boolean for whether data will be updated if it is loaded.
     :param logFile: Filename that logger will log to.
     :param precision: Precision to round data to.
     :param addTradeCallback: Callback signal to emit to (if provided) to reflect a new transaction.
     """
     super().__init__(precision=precision,
                      symbol=symbol,
                      startingBalance=startingBalance)
     self.logger = get_logger(log_file=logFile,
                              logger_name=logFile)  # Get logger.
     self.dataView: Data = Data(interval=interval,
                                symbol=symbol,
                                loadData=loadData,
                                updateData=updateData,
                                logObject=self.logger,
                                precision=precision)
     self.binanceClient = self.dataView.binanceClient  # Retrieve Binance client.
     self.symbol = self.dataView.symbol  # Retrieve symbol from data-view object.
     self.coinName = self.get_coin_name()  # Retrieve primary coin to trade.
     self.commissionPaid = 0  # Total commission paid to broker.
     self.completedLoop = True  # Loop that'll keep track of bot. We wait for this to turn False before some action.
     self.inHumanControl = False  # Boolean that keeps track of whether human or bot controls transactions.
     self.lock = Lock(
     )  # Lock to ensure a transaction doesn't occur when another one is taking place.
     self.addTradeCallback = addTradeCallback  # Callback for GUI to add trades.
     self.dailyChangeNets = [
     ]  # Daily change net list. Will contain list of all nets.
     self.optionDetails = [
     ]  # Current option values. Holds most recent option values.
     self.lowerOptionDetails = [
     ]  # Lower option values. Holds lower interval option values (if exist).
     self.spot = isSpot
     self.inSpot = inSpot
Exemple #3
0
    def get_logging_object(enable_logging: bool, logFile: str, loggerObject):
        """
        Returns a logger object.
        :param enable_logging: Boolean that determines whether logging is enabled or not.
        :param logFile: File to log to.
        :param loggerObject: Logger object to return if there is one already specified.
        :return: Logger object or None.
        """
        if loggerObject:
            return loggerObject

        if enable_logging:
            return get_logger(log_file=logFile, logger_name=logFile)

        return None
Exemple #4
0
 def get_logging_object(log: bool, logFile: str, logObject):
     """
     Returns a logger object.
     :param log: Boolean that determines where logging is enabled or not.
     :param logFile: File to log to.
     :param logObject: Log object to return if there is one already specified.
     :return: Logger object or None.
     """
     if logObject:
         return logObject
     else:
         if not log:
             return None
         else:
             return get_logger(logFile, logFile)
Exemple #5
0
    def purge(self, directory):
        path = os.path.join(helpers.ROOT_DIR, directory)
        if not os.path.exists(path):
            QMessageBox.about(self, 'Warning', f"No {directory.lower()} files detected.")
            return

        message = f'Are you sure you want to delete your {directory.lower()} files? You might not be able to undo ' \
                  f'this operation. \n\nThe following path will be deleted: \n{path}'
        qm = QMessageBox
        ret = qm.question(self, 'Warning', message, qm.Yes | qm.No)

        if ret == qm.Yes and os.path.exists(path):
            shutil.rmtree(path)
            self.infoLabel.setText(f'{directory.capitalize()} files have been successfully deleted.')

            if directory == 'Logs':
                self.parent.logger = helpers.get_logger(log_file='algobot', logger_name='algobot')
    def purge(self, directory: str):
        """
        Deletes directory provided.
        """
        path = os.path.join(ROOT_DIR, directory)
        if not os.path.exists(path):
            create_popup(self, f"No {directory.lower()} files detected.")
            return

        message = f'Are you sure you want to delete your {directory.lower()} files? You might not be able to undo ' \
                  f'this operation. \n\nThe following path will be deleted: \n{path}'
        qm = QMessageBox
        ret = qm.question(self, 'Warning', message, qm.Yes | qm.No)

        if ret == qm.Yes and os.path.exists(path):
            shutil.rmtree(path)
            self.infoLabel.setText(
                f'{directory.capitalize()} files have been successfully deleted.'
            )

            if directory == 'Logs':  # Reinitialize log folder if old logs were purged.
                self.parent.logger = get_logger(log_file='algobot',
                                                logger_name='algobot')
Exemple #7
0
"""
Initialization file.
"""
from binance import Client

from algobot.helpers import get_current_version, get_latest_version, get_logger

MAIN_LOGGER = get_logger(log_file='algobot', logger_name='algobot')

CURRENT_VERSION = get_current_version()
LATEST_VERSION = get_latest_version()

try:
    BINANCE_CLIENT = Client()
except Exception as e:
    MAIN_LOGGER.exception(repr(e))
    BINANCE_CLIENT = None