Exemplo n.º 1
0
def condition(data):  # Define the condition function of the Decision

    if redis_client.active_rising_peak(
    ) and data.btc_balance > 0:  # We carry out the condition check only if the decision is set active in redis

        band = fetch()

        if band:  # Since the data is in redis the band is active

            if data.sell < band[
                    'lower']:  # If the sell-price has fallen below the band we must take action

                return True

            delta = round2(
                data.sell * UPPER_LIMIT_FACTOR - band['upper']
            )  # Change in upper band based on the current sell price

            if delta > 0:  # If the sell price has increased such that the band is pushed upwards we update the band (it NEVER goes down)

                band['upper'] += delta
                band['lower'] += delta

                log("\n" + current_time())
                log("Delta = ${}. Pushing band up to: ${} - ${}.".format(
                    delta, band['lower'], band['upper']))

                push(band)

                btc = client.btc()
                client.cancel_all_orders()
                client.sell_order(btc, round2(band['upper']))

        else:  # The band is inactive

            if data.sell > ACTIVATION_THRESHOLD:  # Avg Sell is above Activation Threshold so we activate the band

                log("\n" + current_time())
                log(
                    "Sell price = ${} has risen above the Activation Threshold = ${}"
                    .format(data.sell, ACTIVATION_THRESHOLD), True)

                b = {
                    'lower': data.sell * LOWER_LIMIT_FACTOR,
                    'upper': data.sell * UPPER_LIMIT_FACTOR
                }  # Set band values
                rds.set(
                    REDIS_KEY, json.dumps(b)
                )  # Convert dictionary to json string and store it in redis server

                btc = client.btc()
                client.cancel_all_orders()
                client.sell_order(
                    btc, round2(b['upper'])
                )  # Set up a sell order for the upper band limit

    return False
def condition(data):        # Define the condition function of the Decision

    if redis_client.active_falling_trench() and data.usd_balance > 10:

        band = fetch()

        if band:            # Since the data is in redis the band is active

            if data.buy > band['upper']:      # If the buy-price has risen above the band we must take action (acquire BTC)

                return True

            delta = round2(band['lower'] - data.buy * LOWER_LIMIT_FACTOR)      # Change in lower band based on the current buy price

            if delta > 0:       # If the buy price has decreased such that the band is pushed downwards we update the band (it NEVER goes up)

                band['upper'] -= delta
                band['lower'] -= delta

                if band['upper'] > 1.005 * data.buy:     # Ensure that the upper band is not more than 0.5% above the current buy price

                    band['upper'] = 1.005 * data.buy
                    log("Calculated upper limit > 1.005 times buy price. Adjusting.")

                log(current_time())
                log("Delta = -${}. Pushing band down to: ${} - ${}.\n".format(delta, band['lower'], band['upper']))

                push(band)

                usd = data.usd_balance
                client.cancel_all_orders()
                client.usd_buy_order(usd, round2(band['lower']))

                log("New buy order created.")

        else:               # The band is inactive

            if data.buy < ACTIVATION_THRESHOLD:        # Buy Price is below Activation Threshold so we activate the band

                log(current_time())
                log("Avg Buy price = ${} has fallen below the Activation Threshold = ${}".format(data.avg_buy, ACTIVATION_THRESHOLD), True)

                b = {'upper': ACTIVATION_THRESHOLD, 'lower': data.buy * LOWER_LIMIT_FACTOR}       # Set band values
                rds.set(REDIS_KEY, json.dumps(b))               # Convert dictionary to json string and store it in redis server

                usd = data.usd_balance
                client.cancel_all_orders()
                client.usd_buy_order(usd, round2(b['lower']))      # Set up a sell order for the upper band limit

                log("Creating band: ${} - ${}".format(b['lower'], b['upper']))

    return False
def condition(data):        # Define the condition function of the Decision

    if redis_client.active_rising_peak() and data.btc_balance > 0:       # We carry out the condition check only if the decision is set active in redis

        band = fetch()

        if band:            # Since the data is in redis the band is active

            if data.sell < band['lower']:      # If the sell-price has fallen below the band we must take action

                return True

            delta = round2(data.sell * UPPER_LIMIT_FACTOR - band['upper'])      # Change in upper band based on the current sell price

            if delta > 0:       # If the sell price has increased such that the band is pushed upwards we update the band (it NEVER goes down)

                band['upper'] += delta
                band['lower'] += delta

                log("\n" + current_time())
                log("Delta = ${}. Pushing band up to: ${} - ${}.".format(delta, band['lower'], band['upper']))

                push(band)

                btc = client.btc()
                client.cancel_all_orders()
                client.sell_order(btc, round2(band['upper']))

        else:               # The band is inactive

            if data.sell > ACTIVATION_THRESHOLD:        # Avg Sell is above Activation Threshold so we activate the band

                log("\n" + current_time())
                log("Sell price = ${} has risen above the Activation Threshold = ${}".format(data.sell, ACTIVATION_THRESHOLD), True)

                b = {'lower': data.sell * LOWER_LIMIT_FACTOR, 'upper': data.sell * UPPER_LIMIT_FACTOR}       # Set band values
                rds.set(REDIS_KEY, json.dumps(b))               # Convert dictionary to json string and store it in redis server

                btc = client.btc()
                client.cancel_all_orders()
                client.sell_order(btc, round2(b['upper']))      # Set up a sell order for the upper band limit

    return False
def condition(data):        # Define the condition function of the Decision

    if data.btc_balance > 0:

        if data.sell < MINIMUM_THRESHOLD:

            log(current_time())
            log("Sell price = ${} has fallen below the Min. Threshold = ${}".format(data.sell, MINIMUM_THRESHOLD), True)

            return True

    return False
Exemplo n.º 5
0
def condition(data):

    if redis_client.active_minimize_loss() and data.btc_balance > 0:

        if data.sell < DROP_FACTOR * data.last_buy_price:

            log(current_time())
            log("Original Buy Price: {obuy} - Current Sell Price: {sell} - Delta: {delta} - %age: {pct}".format(obuy=data.last_buy_price, sell=data.sell, delta=data.sell - data.last_buy_price, pct=(data.sell - data.last_buy_price)/data.last_buy_price * 100))

            return True

    return False
Exemplo n.º 6
0
def condition(data):  # Define the condition function of the Decision

    if data.btc_balance > 0:

        if data.sell < MINIMUM_THRESHOLD:

            log(current_time())
            log(
                "Sell price = ${} has fallen below the Min. Threshold = ${}".
                format(data.sell, MINIMUM_THRESHOLD), True)

            return True

    return False
def condition(data):

    if redis_client.active_minimum_profit() and data.btc_balance > 0:

        if BAND_LOWER * data.last_buy_price < data.sell < BAND_UPPER * data.last_buy_price:

            if max_price(data.weighted_sell_prices) > TRIGGER_THRESHOLD * data.last_buy_price:      # The weighted sell prices exceeded the upper threshold before dropping sometime in the past

                log(current_time())
                log("Orig. Buy Price: {obuy} - Curr. Sell Price: {sell} - Delta: {delta} - %age: {pct}".format(obuy=data.last_buy_price, sell=data.sell, delta=data.sell - data.last_buy_price, pct=(data.sell - data.last_buy_price) / data.last_buy_price * 100))

                log("Max Weighted Sell price: {}".format(max_price(data.sell_prices)))

                return True

    return False
def condition(data):

    if redis_client.active_minimum_profit() and data.btc_balance > 0:

        if BAND_LOWER * data.last_buy_price < data.sell < BAND_UPPER * data.last_buy_price:

            if max_price(
                    data.weighted_sell_prices
            ) > TRIGGER_THRESHOLD * data.last_buy_price:  # The weighted sell prices exceeded the upper threshold before dropping sometime in the past

                log(current_time())
                log("Orig. Buy Price: {obuy} - Curr. Sell Price: {sell} - Delta: {delta} - %age: {pct}"
                    .format(obuy=data.last_buy_price,
                            sell=data.sell,
                            delta=data.sell - data.last_buy_price,
                            pct=(data.sell - data.last_buy_price) /
                            data.last_buy_price * 100))

                log("Max Weighted Sell price: {}".format(
                    max_price(data.sell_prices)))

                return True

    return False