Ejemplo n.º 1
0
def main():
    api_key = config.get(USER_CFG_SECTION, 'api_key')
    api_secret_key = config.get(USER_CFG_SECTION, 'api_secret_key')
    tld = config.get(USER_CFG_SECTION,
                     'tld') or 'com'  # Default Top-level domain is 'com'

    client = BinanceAPIManager(api_key, api_secret_key, tld, logger)

    logger.info("Creating database schema if it doesn't already exist")
    create_database()

    set_coins(supported_coin_list)

    migrate_old_state()

    initialize_trade_thresholds(client)

    if get_current_coin() is None:
        current_coin_symbol = config.get(USER_CFG_SECTION, 'current_coin')
        if not current_coin_symbol:
            current_coin_symbol = random.choice(supported_coin_list)

        logger.info("Setting initial coin to {0}".format(current_coin_symbol))

        if current_coin_symbol not in supported_coin_list:
            exit(
                "***\nERROR!\nSince there is no backup file, a proper coin name must be provided at init\n***"
            )
        set_current_coin(current_coin_symbol)

        if config.get(USER_CFG_SECTION, 'current_coin') == '':
            current_coin = get_current_coin()
            logger.info("Purchasing {0} to begin trading".format(current_coin))
            all_tickers = client.get_all_market_tickers()
            client.buy_alt(current_coin, BRIDGE, all_tickers)
            logger.info("Ready to start trading")

    schedule = SafeScheduler(logger)
    schedule.every(SCOUT_SLEEP_TIME).seconds.do(
        scout,
        client=client,
        transaction_fee=SCOUT_TRANSACTION_FEE,
        multiplier=SCOUT_MULTIPLIER).tag("scouting")
    schedule.every(1).minutes.do(update_values,
                                 client=client).tag("updating value history")
    schedule.every(1).minutes.do(
        prune_scout_history,
        hours=SCOUT_HISTORY_PRUNE_TIME).tag("pruning scout history")
    schedule.every(1).hours.do(prune_value_history).tag(
        "pruning value history")

    while True:
        schedule.run_pending()
        time.sleep(1)
def transaction_through_tether(client: BinanceAPIManager, pair: Pair):
    '''
    Jump from the source coin to the destination coin through tether
    '''
    if client.sell_alt(pair.from_coin, BRIDGE) is None:
        logger.info("Couldn't sell, going back to scouting mode...")
        return None
    # This isn't pretty, but at the moment we don't have implemented logic to escape from a bridge coin... This'll do for now
    result = None
    while result is None:
        result = client.buy_alt(pair.to_coin, BRIDGE)

    set_current_coin(pair.to_coin)
    update_trade_threshold(client)
Ejemplo n.º 3
0
def initialize_current_coin(client: BinanceAPIManager):
    '''
    Decide what is the current coin, and set it up in the DB.
    '''
    if get_current_coin() is None:
        current_coin_symbol = config.get(USER_CFG_SECTION, 'current_coin')
        if not current_coin_symbol:
            current_coin_symbol = random.choice(supported_coin_list)

        logger.info("Setting initial coin to {0}".format(current_coin_symbol))

        if current_coin_symbol not in supported_coin_list:
            exit(
                "***\nERROR!\nSince there is no backup file, a proper coin name must be provided at init\n***"
            )
        set_current_coin(current_coin_symbol)

        # if we don't have a configuration, we selected a coin at random... Buy it so we can start trading.
        if config.get(USER_CFG_SECTION, 'current_coin') == '':
            current_coin = get_current_coin()
            logger.info("Purchasing {0} to begin trading".format(current_coin))
            all_tickers = client.get_all_market_tickers()
            client.buy_alt(current_coin, BRIDGE, all_tickers)
            logger.info("Ready to start trading")