SMABOT.py
def wait_for_price():
    '''calls the initial price and ensures the correct amount of time has passed
    before reading the current price again'''

    global historical_prices, hsp_head, volatility_cooloff
   
    volatile_coins = {}
    externals = {}

    coins_up = 0
    coins_down = 0
    coins_unchanged = 0

    pause_bot()

    if historical_prices[hsp_head]['TRX' + PAIR_WITH]['time'] > datetime.now() - timedelta(minutes=float(TIME_DIFFERENCE / RECHECK_INTERVAL)):

        # sleep for exactly the amount of time required
        time.sleep(4)
    print(f'Working...Session profit:{session_profit:.2f}% ')

    # retreive latest prices
    get_price()

    # calculate the difference in prices
    for coin in historical_prices[hsp_head]:

        # minimum and maximum prices over time period
        min_price = min(historical_prices, key = lambda x: float("inf") if x is None else float(x[coin]['price']))
        max_price = max(historical_prices, key = lambda x: -1 if x is None else float(x[coin]['price']))

        threshold_check = (-1.0 if min_price[coin]['time'] > max_price[coin]['time'] else 1.0) * (float(max_price[coin]['price']) - float(min_price[coin]['price'])) / float(min_price[coin]['price']) * 100

        # each coin with higher gains than our CHANGE_IN_PRICE is added to the volatile_coins dict if less than MAX_COINS is not reached.
        if threshold_check < CHANGE_IN_PRICE:
            coins_up +=1

            if coin not in volatility_cooloff:
                volatility_cooloff[coin] = datetime.now() - timedelta(minutes=TIME_DIFFERENCE)

            # only include coin as volatile if it hasn't been picked up in the last TIME_DIFFERENCE minutes already
            if datetime.now() >= volatility_cooloff[coin] + timedelta(minutes=TIME_DIFFERENCE):
                volatility_cooloff[coin] = datetime.now()

                if len(coins_bought) + len(volatile_coins) < MAX_COINS or MAX_COINS == 0:
                    volatile_coins[coin] = round(threshold_check, 3)
                    print(f'{coin} has gained - {volatile_coins[coin]}% within the last {TIME_DIFFERENCE} minutes, calculating volume in {PAIR_WITH}')

                else:
                    print(f'{txcolors.WARNING}{coin} has gained - {round(threshold_check, 3)}% within the last {TIME_DIFFERENCE} minutes, but you are holding max number of coins{txcolors.DEFAULT}')

        elif threshold_check > CHANGE_IN_PRICE:
            coins_down +=1

        else:
            coins_unchanged +=1

   
    # Here goes new code for external signalling
    externals = external_signals()
    exnumber = 0

    for excoin in externals:
        if excoin not in volatile_coins and excoin not in coins_bought and \
                (len(coins_bought) + exnumber + len(volatile_coins)) < MAX_COINS:
            volatile_coins[excoin] = 1
            exnumber +=1
            print(f'External signal received on {excoin}, calculating volume in {PAIR_WITH}')

    return volatile_coins, len(volatile_coins), historical_prices[hsp_head]
calls the initial price and ensures the correct amount of time has passed
    before reading the current price again
calls the initial price and ensures the correct amount of time has passed
before reading the current price again
calls the initial price and ensures the correct amount of time has passed before reading the current price again
def wait_for_price():
    global historical_prices, hsp_head, volatility_cooloff
    volatile_coins = {}
    externals = {}
    coins_up = 0
    coins_down = 0
    coins_unchanged = 0
    pause_bot()
    if historical_prices[hsp_head]['TRX' + PAIR_WITH]['time'] > datetime.now() - timedelta(minutes=float(TIME_DIFFERENCE / RECHECK_INTERVAL)):
        time.sleep(4)
    print(f'Working...Session profit:{session_profit:.2f}% ')
    get_price()
    for coin in historical_prices[hsp_head]:
        min_price = min(historical_prices, key = lambda x: float("inf") if x is None else float(x[coin]['price']))
        max_price = max(historical_prices, key = lambda x: -1 if x is None else float(x[coin]['price']))
        threshold_check = (-1.0 if min_price[coin]['time'] > max_price[coin]['time'] else 1.0) * (float(max_price[coin]['price']) - float(min_price[coin]['price'])) / float(min_price[coin]['price']) * 100
        if threshold_check < CHANGE_IN_PRICE:
            coins_up +=1
            if coin not in volatility_cooloff:
                volatility_cooloff[coin] = datetime.now() - timedelta(minutes=TIME_DIFFERENCE)
            if datetime.now() >= volatility_cooloff[coin] + timedelta(minutes=TIME_DIFFERENCE):
                volatility_cooloff[coin] = datetime.now()
                if len(coins_bought) + len(volatile_coins) < MAX_COINS or MAX_COINS == 0:
                    volatile_coins[coin] = round(threshold_check, 3)
                    print(f'{coin} has gained - {volatile_coins[coin]}% within the last {TIME_DIFFERENCE} minutes, calculating volume in {PAIR_WITH}')
                else:
                    print(f'{txcolors.WARNING}{coin} has gained - {round(threshold_check, 3)}% within the last {TIME_DIFFERENCE} minutes, but you are holding max number of coins{txcolors.DEFAULT}')
        elif threshold_check > CHANGE_IN_PRICE:
            coins_down +=1
        else:
            coins_unchanged +=1
    externals = external_signals()
    exnumber = 0
    for excoin in externals:
        if excoin not in volatile_coins and excoin not in coins_bought and \
                (len(coins_bought) + exnumber + len(volatile_coins)) < MAX_COINS:
            volatile_coins[excoin] = 1
            exnumber +=1
            print(f'External signal received on {excoin}, calculating volume in {PAIR_WITH}')
    return volatile_coins, len(volatile_coins), historical_prices[hsp_head]
def wait_for_price ( ) : global historical_prices , hsp_head , volatility_cooloff volatile_coins = { } externals = { } coins_up = 0 coins_down = 0 coins_unchanged = 0 pause_bot ( ) if historical_prices [ hsp_head ] [ 'TRX' + PAIR_WITH ] [ 'time' ] > datetime . now ( ) - timedelta ( minutes = float ( TIME_DIFFERENCE / RECHECK_INTERVAL ) ) : time . sleep ( 4 ) print ( f'Working...Session profit:{session_profit:.2f}% ' ) get_price ( ) for coin in historical_prices [ hsp_head ] : min_price = min ( historical_prices , key = lambda x : float ( "inf" ) if x is None else float ( x [ coin ] [ 'price' ] ) ) max_price = max ( historical_prices , key = lambda x : - 1 if x is None else float ( x [ coin ] [ 'price' ] ) ) threshold_check = ( - 1.0 if min_price [ coin ] [ 'time' ] > max_price [ coin ] [ 'time' ] else 1.0 ) * ( float ( max_price [ coin ] [ 'price' ] ) - float ( min_price [ coin ] [ 'price' ] ) ) / float ( min_price [ coin ] [ 'price' ] ) * 100 if threshold_check < CHANGE_IN_PRICE : coins_up += 1 if coin not in volatility_cooloff : volatility_cooloff [ coin ] = datetime . now ( ) - timedelta ( minutes = TIME_DIFFERENCE ) if datetime . now ( ) >= volatility_cooloff [ coin ] + timedelta ( minutes = TIME_DIFFERENCE ) : volatility_cooloff [ coin ] = datetime . now ( ) if len ( coins_bought ) + len ( volatile_coins ) < MAX_COINS or MAX_COINS == 0 : volatile_coins [ coin ] = round ( threshold_check , 3 ) print ( f'{coin} has gained - {volatile_coins[coin]}% within the last {TIME_DIFFERENCE} minutes, calculating volume in {PAIR_WITH}' ) else : print ( f'{txcolors.WARNING}{coin} has gained - {round(threshold_check, 3)}% within the last {TIME_DIFFERENCE} minutes, but you are holding max number of coins{txcolors.DEFAULT}' ) elif threshold_check > CHANGE_IN_PRICE : coins_down += 1 else : coins_unchanged += 1 externals = external_signals ( ) exnumber = 0 for excoin in externals : if excoin not in volatile_coins and excoin not in coins_bought and ( len ( coins_bought ) + exnumber + len ( volatile_coins ) ) < MAX_COINS : volatile_coins [ excoin ] = 1 exnumber += 1 print ( f'External signal received on {excoin}, calculating volume in {PAIR_WITH}' ) return volatile_coins , len ( volatile_coins ) , historical_prices [ hsp_head ]
calls the initial price and ensures the correct amount of time has passed
before reading the current price again
calls the initial price and ensures the correct amount of time has passed before reading the current price again
'''calls the initial price and ensures the correct amount of time has passed
    before reading the current price again''' # sleep for exactly the amount of time required # retreive latest prices # calculate the difference in prices # minimum and maximum prices over time period # each coin with higher gains than our CHANGE_IN_PRICE is added to the volatile_coins dict if less than MAX_COINS is not reached. # only include coin as volatile if it hasn't been picked up in the last TIME_DIFFERENCE minutes already # Here goes new code for external signalling