def test_get_trend(trader: Trader): """ Test trader get trend functionality. :param trader: Trader object. """ assert trader.get_trend() is None bullish_strategy1 = Strategy(name='b1', parent=None) bullish_strategy1.trend = BULLISH trader.strategies['b1'] = bullish_strategy1 assert trader.get_trend() == BULLISH bullish_strategy2 = Strategy(name='b2', parent=None) bullish_strategy2.trend = BULLISH trader.strategies['b2'] = bullish_strategy2 assert trader.get_trend() == BULLISH bearish_strategy = Strategy(name='b3', parent=None) bearish_strategy.trend = BEARISH trader.strategies['b3'] = bearish_strategy assert trader.get_trend() is None for strategy in trader.strategies.values(): strategy.trend = BEARISH assert trader.get_trend() == BEARISH
def test_get_trend(self): self.assertEqual(self.trader.get_trend(), None) bullish_strategy1 = Strategy(name='b1', parent=None) bullish_strategy1.trend = BULLISH self.trader.strategies['b1'] = bullish_strategy1 self.assertEqual(self.trader.get_trend(), BULLISH) bullish_strategy2 = Strategy(name='b2', parent=None) bullish_strategy2.trend = BULLISH self.trader.strategies['b2'] = bullish_strategy2 self.assertEqual(self.trader.get_trend(), BULLISH) bearish_strategy = Strategy(name='b3', parent=None) bearish_strategy.trend = BEARISH self.trader.strategies['b3'] = bearish_strategy self.assertEqual(self.trader.get_trend(), None) for strategy in self.trader.strategies: self.trader.strategies[strategy].trend = BEARISH self.assertEqual(self.trader.get_trend(), BEARISH)
def test_get_strategy_inputs(self): dummy_strategy = Strategy(name="dummy", parent=None) def temp(): return 3, 4, 5 dummy_strategy.get_params = temp self.assertEqual(dummy_strategy.get_params(), (3, 4, 5)) self.trader.strategies = {'dummy': dummy_strategy} self.assertEqual(self.trader.get_strategy_inputs('dummy'), '3, 4, 5')
def test_get_strategy_inputs(trader: Trader): """ Test trader get strategy inputs functionality. :param trader: Trader object. """ dummy_strategy = Strategy(name="dummy", parent=None) def temp(): return 3, 4, 5 dummy_strategy.get_params = temp assert dummy_strategy.get_params() == (3, 4, 5) trader.strategies = {'dummy': dummy_strategy} assert trader.get_strategy_inputs('dummy') == '3, 4, 5'
def __init__(self, parent, logger=None): super(Configuration, self).__init__(parent) # Initializing object uic.loadUi(configurationUi, self) # Loading the main UI self.parent = parent self.threadPool = QThreadPool() self.logger = logger self.data = None self.dataType = None self.downloadThread = None self.tokenPass = False self.chatPass = False self.credentialsFolder = "Credentials" self.configFolder = 'Configuration' self.basicFilePath = os.path.join(helpers.ROOT_DIR, 'state.json') self.categoryTabs = [ self.mainConfigurationTabWidget, self.simulationConfigurationTabWidget, self.backtestConfigurationTabWidget, ] self.strategies = get_strategies_dictionary(Strategy.__subclasses__()) self.strategyDict = {} # We will store all the strategy slot information in this dictionary. self.lossDict = {} # We will store stop loss settings here. self.takeProfitDict = {} # We will store take profit settings here. self.load_combo_boxes() # Primarily used for backtest interval changer logic. self.load_slots() # Loads stop loss, take profit, and strategies slots. self.load_credentials() # Load credentials if they exist.
def __init__(self, startingBalance: float, data: list, strategies: list, strategyInterval: Union[str, None] = None, symbol: str = None, marginEnabled: bool = True, startDate: datetime = None, endDate: datetime = None, drawdownPercentage: int = 100, precision: int = 4, outputTrades: bool = True, logger: Logger = None): super().__init__(symbol=symbol, precision=precision, startingBalance=startingBalance, marginEnabled=marginEnabled) convert_all_dates_to_datetime(data) self.data = data self.check_data() self.outputTrades: bool = outputTrades # Boolean that'll determine whether trades are outputted to file or not. self.interval = self.get_interval() self.intervalMinutes = get_interval_minutes(self.interval) self.pastActivity = [ ] # We'll add previous data here when hovering through graph in GUI. self.drawdownPercentageDecimal = drawdownPercentage / 100 # Percentage of loss at which bot exits backtest. self.optimizerRows = [] self.logger = logger if len(strategyInterval.split()) == 1: strategyInterval = convert_small_interval(strategyInterval) self.allStrategies = get_strategies_dictionary( Strategy.__subclasses__()) self.strategyInterval = self.interval if strategyInterval is None else strategyInterval self.strategyIntervalMinutes = get_interval_minutes( self.strategyInterval) self.intervalGapMinutes = self.strategyIntervalMinutes - self.intervalMinutes self.intervalGapMultiplier = self.strategyIntervalMinutes // self.intervalMinutes if self.intervalMinutes > self.strategyIntervalMinutes: raise RuntimeError( f"Your strategy interval ({self.strategyIntervalMinutes} minute(s)) can't be smaller " f"than the data interval ({self.intervalMinutes} minute(s)).") self.ema_dict = {} self.rsi_dictionary = {} self.setup_strategies(strategies) self.startDateIndex = self.get_start_index(startDate) self.endDateIndex = self.get_end_index(endDate)
def __init__(self, startingBalance: float, data: list, strategies: list, strategyInterval: Union[str, None] = None, symbol: str = None, marginEnabled: bool = True, startDate: datetime = None, endDate: datetime = None, precision: int = 4, outputTrades: bool = True): super().__init__(symbol=symbol, precision=precision, startingBalance=startingBalance) self.marginEnabled = marginEnabled self.outputTrades: bool = outputTrades # Boolean that'll determine whether trades are outputted to file or not. convert_all_dates_to_datetime(data) self.data = data self.check_data() self.interval = self.get_interval() self.intervalMinutes = get_interval_minutes(self.interval) self.pastActivity = [ ] # We'll add previous data here when hovering through graph in GUI. if len(strategyInterval.split()) == 1: strategyInterval = convert_small_interval(strategyInterval) self.allStrategies = get_strategies_dictionary( Strategy.__subclasses__()) self.strategyInterval = self.interval if strategyInterval is None else strategyInterval self.strategyIntervalMinutes = get_interval_minutes( self.strategyInterval) self.intervalGapMinutes = self.strategyIntervalMinutes - self.intervalMinutes self.intervalGapMultiplier = self.strategyIntervalMinutes // self.intervalMinutes if self.intervalMinutes > self.strategyIntervalMinutes: raise RuntimeError( "Your strategy interval can't be smaller than the data interval." ) self.ema_dict = {} self.rsi_dictionary = {} self.setup_strategies(strategies) self.startDateIndex = self.get_start_index(startDate) self.endDateIndex = self.get_end_index(endDate)
def test_get_strategies_info_string(self): dummy_strategy = Strategy(name="dummy", parent=None) dummy_strategy2 = Strategy(name='dummy2', parent=None) def temp(): return 3, 4, 5 def temp2(): return 5, 6, 7, 8, 9, 10 dummy_strategy.get_params = temp dummy_strategy2.get_params = temp2 expected_string = '\nStrategies:\n\tDummy: 3, 4, 5\n\tDummy2: 5, 6, 7, 8, 9, 10' self.trader.strategies = {'dummy': dummy_strategy, 'dummy2': dummy_strategy2} self.assertEqual(self.trader.get_strategies_info_string(), expected_string)
def test_get_strategies_info_string(trader: Trader): """ Test trader get strategies info string functionality. :param trader: Trader object. """ dummy_strategy = Strategy(name="dummy", parent=None) dummy_strategy2 = Strategy(name='dummy2', parent=None) def temp(): return 3, 4, 5 def temp2(): return 5, 6, 7, 8, 9, 10 dummy_strategy.get_params = temp dummy_strategy2.get_params = temp2 expected_string = 'Strategies:\n\tDummy: 3, 4, 5\n\tDummy2: 5, 6, 7, 8, 9, 10' trader.strategies = {'dummy': dummy_strategy, 'dummy2': dummy_strategy2} assert trader.get_strategies_info_string() == expected_string
def __init__(self, parent: QMainWindow, logger: Logger = None): super(Configuration, self).__init__(parent) # Initializing object uic.loadUi(configurationUi, self) # Loading the main UI self.parent = parent self.threadPool = QThreadPool() self.logger = logger self.optimizer_backtest_dict = { BACKTEST: { 'startDate': self.backtestStartDate, 'endDate': self.backtestEndDate, 'tickers': self.backtestTickerLineEdit, 'intervals': self.backtestIntervalComboBox, 'data': None, 'dataIntervalComboBox': self.backtestIntervalComboBox, 'dataInterval': None, 'dataType': None, 'infoLabel': self.backtestInfoLabel, 'dataLabel': self.backtestDataLabel, 'downloadThread': None, 'downloadLabel': self.backtestDownloadLabel, 'downloadButton': self.backtestDownloadDataButton, 'stopDownloadButton': self.backtestStopDownloadButton, 'importButton': self.backtestImportDataButton, 'downloadProgress': self.backtestDownloadProgressBar }, OPTIMIZER: { 'startDate': self.optimizerStartDate, 'endDate': self.optimizerEndDate, 'tickers': self.optimizerTickerLineEdit, 'intervals': self.optimizerIntervalComboBox, 'data': None, 'dataIntervalComboBox': self.optimizerIntervalComboBox, 'dataInterval': None, 'dataType': None, 'infoLabel': self.optimizerInfoLabel, 'dataLabel': self.optimizerDataLabel, 'downloadThread': None, 'downloadLabel': self.optimizerDownloadLabel, 'downloadButton': self.optimizerDownloadDataButton, 'stopDownloadButton': self.optimizerStopDownloadButton, 'importButton': self.optimizerImportDataButton, 'downloadProgress': self.optimizerDownloadProgressBar } } self.lossTypes = ("Trailing", "Stop") self.takeProfitTypes = ('Stop',) self.lossOptimizerTypes = ('lossPercentage', 'stopLossCounter') self.takeProfitOptimizerTypes = ('takeProfitPercentage',) # Telegram self.tokenPass = False self.chatPass = False # Folders and files self.credentialsFolder = "Credentials" self.configFolder = 'Configuration' self.stateFilePath = os.path.join(helpers.ROOT_DIR, 'state.json') self.categoryTabs = [ self.mainConfigurationTabWidget, self.simulationConfigurationTabWidget, self.backtestConfigurationTabWidget, self.optimizerConfigurationTabWidget ] self.strategies = get_strategies_dictionary(Strategy.__subclasses__()) self.strategyDict = {} # We will store all the strategy slot information in this dictionary. self.lossDict = {} # We will store stop loss settings here. self.takeProfitDict = {} # We will store take profit settings here. load_slots(self) # Loads stop loss, take profit, and strategies slots. load_credentials(self) # Load credentials if they exist.