예제 #1
0
파일: balance.py 프로젝트: nextpuma/AXE-Bot
def check_balance_before_start(coin, stake_per_trade):
    balance = fetch_balance(coin)
    if balance >= stake_per_trade and minimum_order_size(
            coin, stake_per_trade) is True:
        if check_licence_is_expire():
            adv_messages()
        notificator("You have " + number_for_human(balance) + " " + str(coin))
        notificator("Stake will be " + number_for_human(stake_per_trade) +
                    " " + str(coin))
        notificator("We will trade :")
        return True

    else:
        if check_licence_is_expire():
            adv_messages()
        notificator("You have " + number_for_human(balance) + " " + str(coin))
        notificator("Stake " + number_for_human(stake_per_trade) + " " +
                    str(coin))
        notificator("Small " + str(coin) + " balance !")
        notificator("Bot stopped")
        return False
예제 #2
0
def trade_result(
    buy_order_id,
    sell_order_id,
    coin_pair,
    coin_2,
    sell_order,
    buy_order,
    coin,
    stake_per_trade,
):
    try:

        profit_lst = calculate_profit(coin_2)
        notificator("Profit :\n\n" + number_for_human(profit_lst[0]) + " " +
                    coin_2 + "\n" + str(profit_lst[2])[:6] + " %")

        datetime_start = check_order_date_time_by_id(buy_order_id, coin_pair)
        datetime_end = check_order_date_time_by_id(sell_order_id, coin_pair)

        if save_to_sqlite == "YES":
            save_result_to_sqlite(
                str(sell_order),
                str(buy_order),
                datetime_start,
                datetime_end,
                profit_lst[0],
                str(coin_2),
                str(coin_pair),
            )
        if save_to_firebase == "YES":
            save_result_to_firebase(
                str(sell_order),
                str(buy_order),
                datetime_start,
                datetime_end,
                profit_lst[0],
                str(coin_2),
                str(coin_pair),
            )

        start_again(coin_pair, coin, coin_2)

    except Exception as e:
        if show_error == "YES":
            notificator(str(e))
예제 #3
0
def get_indicators_signal_sell(coin, coin_2, price_buy):
    coin_pair_for_get_bars = (
        coin + coin_2
    )  # another format(ETHBTC) then coin_pair(ETH/BTC) for ccxt

    try:
        while True:
            if sell_indicators_type == "RSI+BB":

                price_ok_tmp = (price_buy / 100) * price_buffer
                price_ok = price_buy + price_ok_tmp

                coin_price = check_coin_price(coin_pair_for_get_bars)
                bb_up = bollingerband(coin_pair_for_get_bars,
                                      sell_indicators_timeframe)[1]
                rsi_data_now = rsi(coin_pair_for_get_bars,
                                   sell_indicators_timeframe)

                stop_loss = price_buy - (
                    (price_buy / 100) *
                    stop_loss_percent_for_start_sell_on_sell_signal)

                if use_stop_loss_while_start_sell_on_sell_signal == "YES":
                    if coin_price <= stop_loss:
                        notificator("Stop loss, selling")
                        return {"signal": "SELL"}
                        break

                if (coin_price > bb_up and rsi_data_now > rsi_sell_level
                        and price_ok < coin_price):

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "Price " + str(number_for_human(coin_price)) +
                                "\n" + "BB up " +
                                str(number_for_human(bb_up))[:9] + "\n" +
                                "RSI " + str(rsi_data_now)[:9] + "\n" +
                                "Timeframe " + str(sell_indicators_timeframe) +
                                "\n" + "SELL")
                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "bb_up": bb_up,
                        "rsi_data_now": rsi_data_now,
                        "signal": "SELL",
                    }

                    if get_config()["ignore_sell_signal_enable"] == "YES":

                        if get_config()["ignore_sell_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_sell_signal_time_sec"]))
                            break

                        if get_config()["ignore_sell_signal_type"] == "times":
                            if (ignore_sell_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_sell_signal_times"]),
                            ) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for SELL Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

            if sell_indicators_type == "RSI":
                price_ok_tmp = (price_buy / 100) * price_buffer
                price_ok = price_buy + price_ok_tmp

                coin_price = check_coin_price(coin_pair_for_get_bars)
                rsi_data_now = rsi(coin_pair_for_get_bars,
                                   sell_indicators_timeframe)

                stop_loss = price_buy - (
                    (price_buy / 100) *
                    stop_loss_percent_for_start_sell_on_sell_signal)

                if use_stop_loss_while_start_sell_on_sell_signal == "YES":
                    if coin_price <= stop_loss:
                        notificator("Stop loss, selling")
                        return {"signal": "SELL"}
                        break

                if rsi_data_now > rsi_sell_level and price_ok < coin_price:

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "RSI " + str(rsi_data_now)[:9] + "\n" +
                                "Timeframe " + str(sell_indicators_timeframe) +
                                "\n" + "SELL")
                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "rsi_data_now": rsi_data_now,
                        "signal": "SELL",
                    }

                    if get_config()["ignore_sell_signal_enable"] == "YES":

                        if get_config()["ignore_sell_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_sell_signal_time_sec"]))
                            break

                        if get_config()["ignore_sell_signal_type"] == "times":
                            if (ignore_sell_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_sell_signal_times"]),
                            ) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for SELL Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

            if sell_indicators_type == "BB":
                price_ok_tmp = (price_buy / 100) * price_buffer
                price_ok = price_buy + price_ok_tmp

                coin_price = check_coin_price(coin_pair_for_get_bars)
                bb_up = bollingerband(coin_pair_for_get_bars,
                                      sell_indicators_timeframe)[1]

                stop_loss = price_buy - (
                    (price_buy / 100) *
                    stop_loss_percent_for_start_sell_on_sell_signal)

                if use_stop_loss_while_start_sell_on_sell_signal == "YES":
                    if coin_price <= stop_loss:
                        notificator("Stop loss, selling")
                        return {"signal": "SELL"}
                        break

                if coin_price > bb_up and price_ok < coin_price:

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "Price " + str(number_for_human(coin_price)) +
                                "\n" + "BB up " +
                                str(number_for_human(bb_up))[:9] + "\n" +
                                "Timeframe " + str(sell_indicators_timeframe) +
                                "\n" + "SELL")
                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "bb_up": bb_up,
                        "signal": "SELL",
                    }

                    if get_config()["ignore_sell_signal_enable"] == "YES":

                        if get_config()["ignore_sell_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_sell_signal_time_sec"]))
                            break

                        if get_config()["ignore_sell_signal_type"] == "times":
                            if (ignore_sell_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_sell_signal_times"]),
                            ) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for SELL Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

    except Exception as e:
        if show_error == "YES":
            notificator(str(e) + ' from get_indicators_signal_sell')
예제 #4
0
def get_indicators_signal(coin, coin_2):
    coin_pair_for_get_bars = (
        coin + coin_2
    )  # another format(ETHBTC) then coin_pair(ETH/BTC) for ccxt

    try:
        while True:
            if buy_indicators_type == "RSI+BB":
                coin_price = check_coin_price(coin_pair_for_get_bars)
                bb_low = bollingerband(coin_pair_for_get_bars,
                                       buy_indicators_timeframe)[0]
                rsi_data_now = rsi(coin_pair_for_get_bars,
                                   buy_indicators_timeframe)

                if coin_price < bb_low and rsi_data_now < rsi_buy_level:

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "Price " + str(number_for_human(coin_price)) +
                                "\n" + "BB low " +
                                str(number_for_human(bb_low))[:9] + "\n" +
                                "RSI " + str(rsi_data_now)[:9] + "\n" +
                                "Timeframe " + str(buy_indicators_timeframe) +
                                "\n" + "BUY")

                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "bb_low": bb_low,
                        "rsi_data_now": rsi_data_now,
                        "signal": "BUY",
                    }

                    if get_config()["ignore_buy_signal_enable"] == "YES":

                        if get_config()["ignore_buy_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_buy_signal_time_sec"]))
                            break

                        if get_config()["ignore_buy_signal_type"] == "times":
                            if (ignore_buy_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_buy_signal_times"])) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

            if buy_indicators_type == "RSI":
                coin_price = check_coin_price(coin_pair_for_get_bars)
                rsi_data_now = rsi(coin_pair_for_get_bars,
                                   buy_indicators_timeframe)

                if rsi_data_now < rsi_buy_level:

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "RSI " + str(rsi_data_now)[:9] + "\n" +
                                "Timeframe " + str(buy_indicators_timeframe) +
                                "\n" + "BUY")
                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "rsi_data_now": rsi_data_now,
                        "signal": "BUY",
                    }

                    if get_config()["ignore_buy_signal_enable"] == "YES":

                        if get_config()["ignore_buy_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_buy_signal_time_sec"]))
                            break

                        if get_config()["ignore_buy_signal_type"] == "times":
                            if (ignore_buy_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_buy_signal_times"])) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

            if buy_indicators_type == "BB":
                coin_price = check_coin_price(coin_pair_for_get_bars)
                bb_low = bollingerband(coin_pair_for_get_bars,
                                       buy_indicators_timeframe)[0]

                if coin_price < bb_low:

                    notificator("Pair " + str(coin_pair_for_get_bars) + "\n" +
                                "Price " + str(number_for_human(coin_price)) +
                                "\n" + "BB low " +
                                str(number_for_human(bb_low))[:9] + "\n" +
                                "Timeframe " + str(buy_indicators_timeframe) +
                                "\n" + "BUY")
                    signal = {
                        "pair": coin_pair_for_get_bars,
                        "price": coin_price,
                        "bb_low": bb_low,
                        "signal": "BUY",
                    }

                    if get_config()["ignore_buy_signal_enable"] == "YES":

                        if get_config()["ignore_buy_signal_type"] == "time":
                            return ingnore_signal_time(
                                signal,
                                int(get_config()
                                    ["ignore_buy_signal_time_sec"]))
                            break

                        if get_config()["ignore_buy_signal_type"] == "times":
                            if (ignore_buy_signal_times(
                                    signal,
                                    int(get_config()
                                        ["ignore_buy_signal_times"])) == "OK"):
                                return signal
                                break
                    else:
                        return signal
                        break

                else:
                    if debug == "YES":
                        notificator("Awaiting for Signal ...")
                    time.sleep(api_requests_frequency)
                    continue

    except Exception as e:
        if show_error == "YES":
            notificator(str(e) + ' from get_indicators_signal')
예제 #5
0
def trail_buy(coin, coin_2, stake_per_trade):
    try:
        buy_trail_step = float(get_config()["buy_trail_step"])
        coin_pair = coin + "/" + coin_2
        coin_pair_for_get_bars = (
            coin + coin_2
        )  # another format(ETHBTC) then coin_pair(ETH/BTC) for ccxt
        notificator("Awaiting buy ...")
        start_price = check_coin_price(coin_pair_for_get_bars)
        time.sleep(1)
        current_price = check_coin_price(coin_pair_for_get_bars)
        current_change_percent = (
            (float(current_price) - start_price) / start_price) * 100
        last_change_percent = current_change_percent

        while True:

            if last_change_percent + buy_trail_step >= current_change_percent:
                if last_change_percent > current_change_percent:
                    last_change_percent = current_change_percent

                current_price = check_coin_price(coin_pair_for_get_bars)
                current_change_percent = (
                    (float(current_price) - start_price) / start_price) * 100

                if debug == "YES":
                    notificator("last_change_percent :\n" +
                                str(last_change_percent)[:9] + "\n\n" +
                                "current_change_percent :\n" +
                                str(current_change_percent)[:9] + "\n\n" +
                                "buy_trail_step :\n" + str(buy_trail_step))

                time.sleep(api_requests_frequency)
                continue

            else:
                if use_limit_orders == "YES":

                    amount_to_buy = calculate_amount_to_by(
                        coin_pair, stake_per_trade, coin_2, current_price)

                    buy_order_new = make_order(coin_pair, "limit", "buy",
                                               amount_to_buy, current_price)
                    buy_order_id = buy_order_new["id"]

                    if check_order_status_by_id(buy_order_id,
                                                coin_pair) == "canceled":
                        notificator("Buy order was canceled, restart ...")
                        start_again(coin_pair, coin, coin_2)
                        break

                    if check_order_status_by_id(buy_order_id,
                                                coin_pair) == "closed":
                        buy_order = fetch_full_closed_order_by_id(
                            buy_order_id, coin_pair)
                        price_buy = fetch_filled_price_by_id(
                            buy_order_id, coin_pair)
                        amount_filled = fetch_filled_order_amount_by_id(
                            buy_order_id, coin_pair)
                        notificator("Buy (limit) " +
                                    number_for_human(amount_filled) + " " +
                                    coin + " at price " +
                                    number_for_human(price_buy) + " success")
                        if start_sell_trail_on_sell_signal == "YES":
                            notificator("Awaiting SELL signal ...")
                            if (get_indicators_signal_sell(
                                    coin, coin_2,
                                    price_buy)["signal"] == "SELL"):
                                trail_sell(
                                    coin_pair,
                                    buy_order_id,
                                    price_buy,
                                    coin,
                                    coin_2,
                                    buy_order,
                                    stake_per_trade,
                                    coin_pair_for_get_bars,
                                )

                                break
                        trail_sell(
                            coin_pair,
                            buy_order_id,
                            price_buy,
                            coin,
                            coin_2,
                            buy_order,
                            stake_per_trade,
                            coin_pair_for_get_bars,
                        )

                        break
                else:
                    while True:
                        amount_to_buy = calculate_amount_to_by(
                            coin_pair, stake_per_trade, coin_2, current_price)
                        buy_order = make_order(coin_pair, "market", "buy",
                                               amount_to_buy, None)
                        if buy_order is not None:
                            break
                        else:
                            continue

                    buy_order_id = buy_order["id"]
                    price_buy = fetch_filled_price_by_id(
                        buy_order_id, coin_pair)
                    amount_filled = fetch_filled_order_amount_by_id(
                        buy_order_id, coin_pair)
                    notificator("Buy (market) " +
                                number_for_human(amount_filled) + " " + coin +
                                " at price " + number_for_human(price_buy) +
                                " success")
                    notificator("Awaiting sell ...")

                    if start_sell_trail_on_sell_signal == "YES":
                        notificator("Awaiting SELL signal ...")
                        if (get_indicators_signal_sell(
                                coin, coin_2, price_buy)["signal"] == "SELL"):
                            trail_sell(
                                coin_pair,
                                buy_order_id,
                                price_buy,
                                coin,
                                coin_2,
                                buy_order,
                                stake_per_trade,
                                coin_pair_for_get_bars,
                            )
                            break

                    trail_sell(
                        coin_pair,
                        buy_order_id,
                        price_buy,
                        coin,
                        coin_2,
                        buy_order,
                        stake_per_trade,
                        coin_pair_for_get_bars,
                    )
                    break

    except ccxt.NetworkError as e:
        if show_error == "YES":
            notificator(str(e))
    except ccxt.ExchangeError as e:
        if show_error == "YES":
            notificator(str(e))
    except Exception as e:
        if show_error == "YES":
            notificator(str(e))
예제 #6
0
def trail_sell(coin_pair, buy_order_id, price_buy, coin, coin_2, buy_order,
               stake_per_trade, coin_pair_for_get_bars):
    try:
        sell_trail_step = float(get_config()["sell_trail_step"])
        start_price = price_buy
        current_price = check_coin_price(coin_pair_for_get_bars)
        current_change_percent = (
            (float(current_price) - start_price) / start_price) * 100
        last_change_percent = current_change_percent

        amount_to_sell = calculate_amount_to_sell(buy_order, coin)

        while True:

            if last_change_percent - sell_trail_step <= current_change_percent:
                if last_change_percent < current_change_percent:
                    last_change_percent = current_change_percent

                current_price = check_coin_price(coin_pair_for_get_bars)
                current_change_percent = (
                    (float(current_price) - start_price) / start_price) * 100

                if debug == "YES":
                    notificator("last_change_percent :\n" +
                                str(last_change_percent)[:9] + "\n\n" +
                                "current_change_percent :\n" +
                                str(current_change_percent)[:9] + "\n\n" +
                                "sell_trail_step :\n" + str(sell_trail_step))

                time.sleep(api_requests_frequency)
                if dynamic_trail_enable == "YES":
                    sell_trail_step = dynamic_trail(last_change_percent)
                continue

            else:
                if use_limit_orders == "YES":
                    sell_order_new = make_order(coin_pair, "limit", "sell",
                                                amount_to_sell, current_price)
                    sell_order_id = sell_order_new["id"]

                    if check_order_status_by_id(sell_order_id,
                                                coin_pair) == "canceled":
                        notificator("Sell order was canceled, restart ...")
                        start_again(coin_pair, coin, coin_2)
                        break

                    if check_order_status_by_id(sell_order_id,
                                                coin_pair) == "closed":
                        sell_order = fetch_full_closed_order_by_id(
                            sell_order_id, coin_pair)

                        price_sell = fetch_filled_price_by_id(
                            sell_order_id, coin_pair)
                        amount_filled = fetch_filled_order_amount_by_id(
                            sell_order_id, coin_pair)
                        notificator("Sell (limit) " +
                                    number_for_human(amount_filled) + " " +
                                    coin + " at price " +
                                    number_for_human(price_sell) + " success")
                        if get_config()["dynamic_trail_enable"] == "YES":
                            notificator("Trailing stop was " +
                                        number_for_human(sell_trail_step))

                        trade_result(
                            buy_order_id,
                            sell_order_id,
                            coin_pair,
                            coin_2,
                            sell_order,
                            buy_order,
                            coin,
                            stake_per_trade,
                        )
                        break

                else:
                    sell_order = make_order(coin_pair, "market", "sell",
                                            amount_to_sell, None)
                    sell_order_id = sell_order["id"]
                    price_sell = fetch_filled_price_by_id(
                        sell_order_id, coin_pair)
                    amount_filled = fetch_filled_order_amount_by_id(
                        sell_order_id, coin_pair)
                    notificator("Sell (market) " +
                                number_for_human(amount_filled) + " " + coin +
                                " at price " + number_for_human(price_sell) +
                                " success")
                    if get_config()["dynamic_trail_enable"] == "YES":
                        notificator("Trailing stop was " +
                                    number_for_human(sell_trail_step))

                    trade_result(
                        buy_order_id,
                        sell_order_id,
                        coin_pair,
                        coin_2,
                        sell_order,
                        buy_order,
                        coin,
                        stake_per_trade,
                    )
                    break

    except ccxt.NetworkError as e:
        if show_error == "YES":
            notificator(str(e))
    except ccxt.ExchangeError as e:
        if show_error == "YES":
            notificator(str(e))
    except Exception as e:
        if show_error == "YES":
            notificator(str(e))