Beispiel #1
0
def convert_to_something(query_received, graphql_client_uni,
                         graphql_client_eth):
    if len(query_received) == 3:
        ticker_req = query_received[2]
        amount = float(query_received[1])
        res = convert_to_usd(amount, ticker_req, graphql_client_uni,
                             graphql_client_eth)
        message = str(amount) + " " + ticker_req + " = " + res + " USD"
        return message
    elif len(query_received) == 4:
        ticker_req = query_received[2]
        amount = float(query_received[1])
        ticker_to = query_received[3]
        res_req = convert_to_usd_raw(1, ticker_req, graphql_client_uni,
                                     graphql_client_eth)

        res_ticker_to = convert_to_usd_raw(1, ticker_to, graphql_client_uni,
                                           graphql_client_eth)
        res = amount * (res_req / res_ticker_to)
        res_req_usd_str = util.number_to_beautiful(round(
            res_req *
            amount)) if round(res_req * amount) > 10 else util.float_to_str(
                res_req * amount)
        res_str = util.number_to_beautiful(
            round(res)) if round(res) > 10 else util.float_to_str(res)[0:10]
        message = str(
            amount
        ) + " " + ticker_req + " = " + res_req_usd_str + " USD or " + res_str + " " + ticker_to
        return message
    else:
        return "Wrong format. Please use /convert AMOUNT CURRENCY (optional: CURRENCY_TO)"
Beispiel #2
0
    def convert_to_something(self, query_received) -> str:
        # sourcery skip: extract-method
        if len(query_received) == 3:
            ticker_req = query_received[2]
            amount = float(query_received[1])
            res = self.convert_to_usd(amount, ticker_req)
            message = str(amount) + " " + ticker_req + " = " + res + " USD"
            return message
        elif len(query_received) == 4:
            ticker_req = query_received[2]
            amount = float(query_received[1])
            ticker_to = query_received[3]
            res_req = self.convert_to_usd_raw(1, ticker_req)

            res_ticker_to = self.convert_to_usd_raw(1, ticker_to)
            res = amount * (res_req / res_ticker_to)
            res_req_usd_str = number_to_beautiful(round(
                res_req *
                amount)) if round(res_req * amount) > 10 else float_to_str(
                    res_req * amount)
            res_str = number_to_beautiful(
                round(res)) if round(res) > 10 else float_to_str(res)[0:10]
            message = str(
                amount
            ) + " " + ticker_req + " = " + res_req_usd_str + " USD or " + res_str + " " + ticker_to
            return message
        else:
            return "Wrong format. Please use /convert AMOUNT CURRENCY (optional: CURRENCY_TO)"
Beispiel #3
0
def get_chart_supply(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id

    query_received = update.message.text.split(' ')

    time_type, k_hours, k_days, tokens = commands_util.check_query(
        query_received, ticker)

    current_boob_nbr, current_ecto_nbr = general_end_functions.send_supply_two_pyplot(
        supply_file_path, k_days, k_hours, "BOOB", "ECTO", supply_chart_path)

    current_boob_str = util.number_to_beautiful(current_boob_nbr)
    current_ecto_str = util.number_to_beautiful(current_ecto_nbr)

    msg_time = " " + str(
        k_days) + " day(s) " if k_days > 0 else " last " + str(
            k_hours) + " hour(s) "

    caption = "Supply of the last " + msg_time + ".\nCurrent supply: \n<b>BOOB:</b> <pre>" + current_boob_str + \
              "</pre> \n<b>ECTO:</b> <pre>" + current_ecto_str + "</pre>"

    context.bot.send_photo(chat_id=chat_id,
                           photo=open(supply_chart_path, 'rb'),
                           caption=caption,
                           parse_mode="html")
Beispiel #4
0
def get_price(contract, pair_contract, graphclient_eth, graphclient_uni, name,
              decimals):
    print("getting price contract: " + str(contract))
    (derivedETH_7d, token_price_7d_usd, derivedETH_1d, token_price_1d_usd,
     derivedETH_now, token_price_now_usd) = requests_util.get_price_raw(
         graphclient_eth, graphclient_uni, contract)

    supply_cap_token = requests_util.get_supply_cap_raw(contract, decimals)
    supply_cat_pretty = str(util.number_to_beautiful(round(supply_cap_token)))
    market_cap = util.number_to_beautiful(
        int(float(supply_cap_token) * token_price_now_usd))

    vol_24h = requests_util.get_volume_24h(graphclient_uni, contract)
    if token_price_7d_usd is not None and token_price_7d_usd != 0.0:
        var_7d = -int(
            ((token_price_7d_usd - token_price_now_usd) / token_price_7d_usd) *
            100) if token_price_7d_usd > token_price_now_usd else int(
                ((token_price_now_usd - token_price_7d_usd) /
                 token_price_7d_usd) * 100)
        var_7d_str = "+" + str(var_7d) + "%" if var_7d > 0 else str(
            var_7d) + "%"
    else:
        var_7d_str = "Not available"
    if token_price_1d_usd is not None and token_price_1d_usd != 0.0:
        var_1d = -int(
            ((token_price_1d_usd - token_price_now_usd) / token_price_1d_usd) *
            100) if token_price_1d_usd > token_price_now_usd else int(
                ((token_price_now_usd - token_price_1d_usd) /
                 token_price_1d_usd) * 100)
        var_1d_str = "+" + str(var_1d) + "%" if var_1d > 0 else str(
            var_1d) + "%"
    else:
        var_1d_str = "Not available"

    print("vol 24: " + str(vol_24h))

    vol_24_pretty = util.number_to_beautiful(vol_24h)

    msg_vol_24 = "\nVol 24H = $" + vol_24_pretty if vol_24_pretty != "0" else ""

    holders = requests_util.get_number_holder_token(contract)
    holders_str = "\nHolders = " + str(holders) if holders != -1 else ""
    links = '<a href="etherscan.io/token/' + contract + '">Etherscan</a>|<a href="https://app.uniswap.org/#/swap?inputCurrency=' + contract + '">Uni</a>'
    ad = util.get_ad()
    message = "<code>" + name \
              + "\nETH: Ξ" + float_to_str(derivedETH_now)[0:10] \
              + "\nUSD: $" + float_to_str(token_price_now_usd)[0:10] \
              + "\n24H:  " + var_1d_str \
              + "\n7D :  " + var_7d_str \
              + "\n" \
              + msg_vol_24 \
              + "\nS.  Cap = " + supply_cat_pretty \
              + "\nM.  Cap = $" + market_cap \
              + holders_str + "</code>"\
              + "\n" + links \
              + "\n" + ad
    return message
Beispiel #5
0
def special_custom_price():
    (derivedETH_7d, token_price_7d_usd, derivedETH_1d, token_price_1d_usd,
     derivedETH_now, token_price_now_usd) = requests_util.get_price_raw(
         graphql_client_eth, graphql_client_uni, bloody_contract)

    supply_cap_token = requests_util.get_supply_cap_raw(
        bloody_contract, decimals)
    supply_cat_pretty = str(
        util.number_to_beautiful(round(supply_cap_token * 55)))
    market_cap = util.number_to_beautiful(
        int(float(supply_cap_token * 55) * token_price_now_usd))

    vol_24h = requests_util.get_volume_24h(graphql_client_uni, bloody_contract)
    if token_price_7d_usd is not None and token_price_7d_usd != 0.0:
        var_7d = -int(
            ((token_price_7d_usd - token_price_now_usd) / token_price_7d_usd) *
            100) if token_price_7d_usd > token_price_now_usd else int(
                ((token_price_now_usd - token_price_7d_usd) /
                 token_price_7d_usd) * 100)
        var_7d_str = "+" + str(var_7d) + "%" if var_7d > 0 else str(
            var_7d) + "%"
    else:
        var_7d_str = "Not available"
    if token_price_1d_usd is not None and token_price_1d_usd != 0.0:
        var_1d = -int(
            ((token_price_1d_usd - token_price_now_usd) / token_price_1d_usd) *
            100) if token_price_1d_usd > token_price_now_usd else int(
                ((token_price_now_usd - token_price_1d_usd) /
                 token_price_1d_usd) * 100)
        var_1d_str = "+" + str(var_1d) + "%" if var_1d > 0 else str(
            var_1d) + "%"
    else:
        var_1d_str = "Not available"

    print("vol 24: " + str(vol_24h))

    vol_24_pretty = util.number_to_beautiful(vol_24h)

    msg_vol_24 = "\nVol 24H = $" + vol_24_pretty if vol_24_pretty != "0" else ""

    holders = requests_util.get_number_holder_token(bloody_contract)
    holders_str = "\nHolders = " + str(holders) if holders != -1 else ""
    ad = util.get_ad()
    message = "<code>" + name \
              + "\nETH: Ξ" + util.float_to_str(derivedETH_now)[0:10] \
              + "\nUSD: $" + util.float_to_str(token_price_now_usd)[0:10] \
              + "\n24H:  " + var_1d_str \
              + "\n7D :  " + var_7d_str \
              + "\n" \
              + msg_vol_24 \
              + "\nS.  Cap = " + supply_cat_pretty \
              + "\nM.  Cap = $" + market_cap \
              + holders_str \
              + "</code>" \
              + "\n"
    return message
Beispiel #6
0
def convert_to_usd(amount, currency_ticker, graphqlclient_uni,
                   graphqlclient_eth):
    total = convert_to_usd_raw(amount, currency_ticker, graphqlclient_uni,
                               graphqlclient_eth)
    return util.number_to_beautiful(
        round(total)) if round(total) > 10 else float_to_str(total)
Beispiel #7
0
def get_price(contract, pair_contract, graphclient_eth, graphclient_uni, name, decimals, uni_wrapper):
    logging.info("getting price for contract: " + str(contract))
    t0 = time.time()
    (derivedETH_7d, token_price_7d_usd, derivedETH_1d, token_price_1d_usd, derivedETH_now,
     token_price_now_usd) = requests_util.get_price_raw(graphclient_eth, graphclient_uni, contract)
    logging.info("getting price for contract took " + str(round(time.time() - t0)))

    # msg_one_eth = "\n1 Ξ: " + float_to_str(1 / derivedETH_now)[0:10] + ' ' + name[:5]

    token_info = requests_util.get_token_info_old(contract)

    supply_cap_token, holders, full_name = 0, 0, ""
    if token_info is not None and 'error' not in token_info:
        supply_cap_token = int(token_info['totalSupply']) / 10 ** int(token_info['decimals'])
        holders = int(token_info['holdersCount'])
        full_name = token_info['name']

    util.write_supply_cap(round(supply_cap_token), name)
    supply_cat_pretty = str(util.number_to_beautiful(round(supply_cap_token)))
    market_cap = util.number_to_beautiful(int(float(supply_cap_token) * token_price_now_usd))

    if pair_contract == "" or pair_contract is None:
        pair = web3_util.does_pair_token_eth_exist(contract, uni_wrapper)
        logging.info("pair found = " + str(pair))
        if pair is not None:
            vol_24h = requests_util.get_volume_24h(graphclient_uni, pair.lower())
        else:
            vol_24h = 0
    else:
        pair = pair_contract
        vol_24h = requests_util.get_volume_24h(graphclient_uni, pair.lower())

    if token_price_7d_usd is not None and token_price_7d_usd != 0.0:
        var_7d_msg = _calculate_price_diff(
            token_price_7d_usd, token_price_now_usd, "\n7D : "
        )

    else:
        var_7d_msg = ""
    if token_price_1d_usd is not None and token_price_1d_usd != 0.0:
        var_1d_msg = _calculate_price_diff(
            token_price_1d_usd, token_price_now_usd, "\n24H: "
        )

    else:
        var_1d_msg = ""

    logging.debug("vol 24: " + str(vol_24h))

    vol_24_pretty = util.number_to_beautiful(vol_24h)

    msg_vol_24 = "\nVol 24H = $" + vol_24_pretty if vol_24_pretty != "0" else ""
    name_header = "<b>" + name + '</b>'
    if full_name != "":
        name_header = "<b>(" + name + ') ' + full_name + '</b>'
    holders_str = "\nHolders = " + str(holders) if holders != -1 else ""
    links = '<a href="etherscan.io/token/' + contract + '">Etherscan</a>|<a href="https://app.uniswap.org/#/swap?inputCurrency=' + contract + '">Uniswap</a>'
    ad = util.get_ad()
    # message = name_header + '<code>' \
    #           + "\nETH: Ξ" + float_to_str(derivedETH_now)[0:10] \
    #           + "\nUSD: $" + float_to_str(token_price_now_usd)[0:10] \
    #           + var_1d_msg \
    #           + var_7d_msg \
    #           + msg_one_eth \
    #           + "\n" \
    #           + msg_vol_24 \
    #           + "\nS.  Cap = " + supply_cat_pretty \
    #           + "\nM.  Cap = $" + market_cap \
    #           + holders_str + "</code>"\
    #           + "\n" + links \
    #           + "\n" + ad
    return name_header + '<code>' \
           + "\nUSD: $" + float_to_str(token_price_now_usd)[0:10] \
           + var_1d_msg \
           + var_7d_msg \
           + "\n" \
           + msg_vol_24 \
           + "\nS.  Cap = " + supply_cat_pretty \
           + "\nM.  Cap = $" + market_cap \
           + holders_str + "</code>" \
           + "\n" + links \
           + "\n" + ad