Esempio n. 1
0
def Main():
    resetOrdersPairs = False
    session = get_session('sqlite:///pyjuquetest1.db')
    # First time you run this, uncomment the next line
    # initialize_database(session)
    if resetOrdersPairs:
        clearOrdersFromDB(session)

    bot = session.query(Bot).filter_by(name='test_bot_2').first()
    # input your path to credentials here.
    exchange = Binance(get_credentials_from_env=True)
    strategy = AlwaysBuyStrategy()
    om = BotController(session, bot, exchange, strategy)

    while True:
        try:
            om.executeBot()
        except KeyboardInterrupt:
            return
Esempio n. 2
0
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
Esempio n. 3
0
def Main():
    bot_config = getYamlConfig(bot_name)

    db_url = None
    if bot_config.__contains__('db_url'):
        db_url = bot_config['db_url']

    session = getSession(db_url)
    exchange = CcxtExchange(
        'binance', {
            'apiKey': getenv('BINANCE_API_KEY'),
            'secret': getenv('BINANCE_API_SECRET'),
            'timeout': 30000,
            'enableRateLimit': True,
        })
    Strategies = getStrategies()

    bot = session.query(Bot).filter_by(name=bot_name).first()
    if bot is None:
        print('No bot found by name: {}. Creating...'.format(bot_name))
        InitializeDatabase(session, bot_config)
        Main()

    symbols = []
    if bot_config.__contains__('symbols') is not None:
        symbols = bot_config['symbols']

    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 = bot_config['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
Esempio n. 4
0
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
Esempio n. 5
0
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 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']

    # 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()
    strategy = AlwaysBuyStrategy() # 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
Esempio n. 7
0
def _defineTaBot(bot_config):
    session = getSession(bot_config['db_url'])
    bot_name = bot_config['name']
    exchange_name = bot_config['exchange']['name']
    exchange_params = bot_config['exchange']['params']
    exchange = CcxtExchange(exchange_name, exchange_params)
    bot_model = session.query(TABotModel).filter_by(name=bot_name).first()

    if bot_model is None:
        print('No bot found by name: {}. Creating...'.format(bot_name))
        InitializeDatabaseTaBot(session, bot_config)
        return _defineTaBot(bot_config)

    # print('Bot model before init bot_controller', bot_model)
    timeframe = '5m'
    if bot_config.__contains__('timeframe'):
        timeframe = bot_config['timeframe']
    bot_controller = BotController(session, bot_model, exchange, None)
    if bot_config.__contains__('display_status'):
        if bot_config['display_status']:
            status_printer = yaspin()
            bot_controller.status_printer = status_printer
    else:
        status_printer = yaspin()
        bot_controller.status_printer = status_printer

    if bot_config.__contains__('strategy'):
        found = False
        if bot_config['strategy'].__contains__('custom'):
            if bot_config['strategy']['custom'] == True:
                found = True

                def nothing(self, symbol):
                    return False, None

                entry_function = nothing
                exit_function = nothing
                if bot_config['strategy'].__contains__('entry_function'):
                    if bot_config['strategy']['entry_function'] not in [
                            None, False
                    ]:
                        entry_function = bot_config['strategy'][
                            'entry_function']
                if bot_config['strategy'].__contains__('exit_function'):
                    if bot_config['strategy']['exit_function'] not in [
                            None, False
                    ]:
                        exit_function = bot_config['strategy']['exit_function']

            bot_controller.checkEntryStrategy = functools.partial(
                entry_function, bot_controller)
            bot_controller.checkExitStrategy = functools.partial(
                exit_function, bot_controller)

        if not found and bot_config['strategy'].__contains__('class'):
            bot_controller.strategy = bot_config['strategy']['class'](
                **bot_config['strategy']['params'])

    return bot_controller


# def Main():

#     for key in ['db_url', 'name', 'symbols', 'exchange', 'type']:
#         assert key in bot_config.keys(), '{} should be inside the config object'.format(key)
#     for key in ['name', 'params']:
#         assert key in bot_config['exchange'].keys(), '{} should be inside the exchange config object'.format(key)

#     session = getSession(bot_config['db_url'])
#     bot_name = bot_config['name']
#     exchange_name = bot_config['exchange']['name']
#     exchange_params = bot_config['exchange']['params']
#     exchange = CcxtExchange(exchange_name, exchange_params)
#     symbols = bot_config['symbols']
#     bot_type = bot_config['type']

#     bot_model = session.query(Bot).filter_by(name=bot_name).first()
#     if bot_model is None:
#         print('No bot found by name: {}. Creating...'.format(bot_name))
#         if bot_type == 'ta':
#             InitializeDatabaseTaBot(session, bot_config)
#         elif bot_ta == 'grid':
#             InitializeDatabaseGridBot(session, bot_config)
#         Main()

#     strategy = None
#     if bot_config.__contains__('entry_strategy'):
#         if bot_config.__contains__('class'):
#             strategy = bot_config['entry_strategy']['class'](**bot_config['entry_strategy']['params'])

#     bot_controller = None
#     if bot_type == 'ta':
#         bot_controller = BotController(session, bot_model, exchange, strategy)
#     elif bot_type == 'grid':
#         bot_controller = GridBotController(name)
#         bot.create(exchange, symbols[0], total_amount, trade_amount, trade_step, total_trades)

#     if bot_config.__contains__('display_status'):
#         if bot_config['display_status']:
#             status_printer = yaspin()
#             bot_controller.status_printer = status_printer

#     while True:
#         try:
#             bot_controller.executeBot()
#         except KeyboardInterrupt:
#             return
#         bot_controller.status_printer.start()
#         left_to_sleep = bot_config['sleep']
#         while left_to_sleep > 0:
#             if bot_controller.status_printer != None:
#                 open_orders = bot_controller.bot_model.getOpenOrders(bot_controller.session)
#                 bot_controller.status_printer.text = 'Open Orders: {} | Checking signals in {} |'.format(
#                     len(open_orders),
#                     left_to_sleep)
#             time.sleep(1)
#             left_to_sleep -= 1

# if __name__ == '__main__':
#     Main()