def Main(): resetOrdersPairs = False session = getSession('sqlite:///' + db_name) exchange = Binance(get_credentials_from_env=True) # Add all symbols on exchange # for symbol in exchange.SYMBOL_DATAS.keys(): # if exchange.SYMBOL_DATAS[symbol]["status"] == "TRADING" \ # and exchange.SYMBOL_DATAS[symbol]["quoteAsset"] == "BTC": # symbols.append(symbol) # First time you run this, uncomment the next line #initialize_database(session, symbols) bot = session.query(Bot).filter_by(name=bot_name).first() # strategy = AlwaysBuyStrategy() strategy = BBRSIStrategy(13, 40, 70, 30) bot_controller = BotController(session, bot, exchange, strategy) sp = yaspin() bot_controller.sp = sp bot_controller.sp_on = True while True: try: bot_controller.executeBot() except KeyboardInterrupt: return bot_controller.sp.start() left_to_sleep = time_to_sleep while left_to_sleep > 0: bot_controller.sp.text = "Waiting for {} more seconds...".format( left_to_sleep) time.sleep(1) left_to_sleep -= 1
def Main(): resetOrdersPairs = False session = getSession('sqlite:///pyjuque_ccxt_binance_live_1.db') exchange = CcxtExchange( 'binance', { 'apiKey': getenv('BINANCE_API_KEY'), 'secret': getenv('BINANCE_API_SECRET'), # 'password': getenv('OKEX_PASSWORD'), 'timeout': 30000, 'verbose': True, 'enableRateLimit': True, }) symbols = ['TRX/ETH', 'XRP/ETH'] # for symbol in exchange.SYMBOL_DATAS.keys(): # if exchange.SYMBOL_DATAS[symbol]["status"] == "TRADING" \ # and exchange.SYMBOL_DATAS[symbol]["quoteAsset"] == "BTC": # symbols.append(symbol) # First time you run this, uncomment the next line # initialize_database(session, symbols) bot = session.query(Bot).filter_by(name='test_bot_ccxt_tudor').first() # input your path to credentials here. strategy = AlwaysBuyStrategy() # strategy = BBRSIStrategy(13, 40, 70, 30) bot_controller = BotController(session, bot, exchange, strategy) sp = yaspin() bot_controller.sp = sp bot_controller.sp_on = True while True: try: bot_controller.executeBot() except KeyboardInterrupt: return bot_controller.sp.start() left_to_sleep = time_to_sleep while left_to_sleep > 0: bot_controller.sp.text = "Waiting for {} more seconds...".format( left_to_sleep) time.sleep(1) left_to_sleep -= 1
def __init__(self, name=None): self.sp = False self.screen = False if name == None: pass # print('GridBot is nonexistent, ' # 'please call self.create() ' # 'with the required parameters') else: session = getSession('sqlite:///{}.db'.format(name)) bot = session.query(GridBotModel).first() if bot == None: pass # print('GridBot is nonexistent, ' # 'please call self.create() ' # 'with the required parameters') else: # print('GridBot found!') self.bot = bot self.name = name self.session = session self.symbol = bot.symbol self.total_amount = bot.starting_balance self.trade_amount = bot.trade_amount self.trade_step = bot.trade_step self.test_mode = bot.test_run self.exchange_name = bot.exchange.upper() self.exchange = CcxtExchange( bot.exchange.lower(), { 'apiKey': getenv('{}_API_KEY'.format(self.exchange_name)), 'secret': getenv('{}_API_SECRET'.format(self.exchange_name)), 'password': getenv('{}_PASSWORD'.format(self.exchange_name)), 'timeout': 30000, # 'verbose': True, 'enableRateLimit': True, })
def Main(): symbols = [] resetOrdersPairs = False session = getSession() exchange = Binance(get_credentials_from_env=True) Strategies = BotInitializer.getStrategies() bot = session.query(Bot).filter_by(name=bot_name).first() if bot is None: print('No bot found by name: ' + bot_name + '. Creating...') if bot_config['symbols'] is None: print('No symbols found in template. Adding all...') for symbol in exchange.SYMBOL_DATAS.keys(): if exchange.SYMBOL_DATAS[symbol]["status"] == "TRADING" \ and exchange.SYMBOL_DATAS[symbol]["quoteAsset"] == "BTC": symbols.append(symbol) InitializeDatabase(session, symbols, bot_name=bot_name) # Restart? Main() bot_config = BotInitializer.getYamlConfig(bot_name) if bot_config['symbols'] is not None: symbols = bot_config['strategy'] strategy = Strategies[bot_config['strategy']['name']](**bot_config['strategy']['params']) bot_controller = BotController(session, bot, exchange, strategy) sp = yaspin() bot_controller.sp = sp bot_controller.sp_on = True while True: try: bot_controller.executeBot() except KeyboardInterrupt: return bot_controller.sp.start() left_to_sleep = time_to_sleep while left_to_sleep > 0: bot_controller.sp.text = "Waiting for {} more seconds...".format(left_to_sleep) time.sleep(1) left_to_sleep -= 1
def Main(): resetOrdersPairs = False session = getSession('sqlite:///pyjuque_test_3.db') exchange = Binance() symbols = [] for symbol in exchange.SYMBOL_DATAS.keys(): if exchange.SYMBOL_DATAS[symbol]["status"] == "TRADING" \ and exchange.SYMBOL_DATAS[symbol]["quoteAsset"] == "BTC": symbols.append(symbol) # First time you run this, uncomment the next line # initialize_database(session, symbols) if resetOrdersPairs: clearOrdersFromDB(session) bot = session.query(Bot).filter_by(name='test_bot_2').first() # input your path to credentials here. # strategy = AlwaysBuyStrategy() strategy = BBRSIStrategy(13, 40, 70, 30) bot_controller = BotController(session, bot, exchange, strategy) sp = yaspin() bot_controller.sp = sp bot_controller.sp_on = True while True: try: bot_controller.executeBot() except KeyboardInterrupt: return bot_controller.sp.start() bot_controller.sp.text = "Waiting for {} seconds...".format( time_to_sleep) time.sleep(time_to_sleep)
def create(self, exchange, symbol, total_amount, trade_amount, trade_step, total_trades, test_mode=False): self.exchange = exchange self.exchange_name = self.exchange.exchange_id.upper() self.symbol = symbol self.total_amount = total_amount self.trade_amount = trade_amount self.trade_step = trade_step self.total_trades = total_trades self.test_mode = test_mode self.name = 'GridBot_{}_{}_{}_{}_{}'.format( self.exchange_name, symbol.replace('/', ''), str(int(total_amount)), str(int(trade_amount * total_amount)), str(trade_step * 100).replace('.', 'point')) if test_mode: self.name = self.name + '_test' raise NotImplementedError('Test Mode not implemented for GridBot') else: self.name = self.name + '_live' # print('Bot name is {}'.format(self.name)) self.session = getSession('sqlite:///{}.db'.format(self.name)) bot = self.session.query(GridBotModel).first() if bot == None: self._initializeDatabase() else: self.bot = bot