コード例 #1
0
ファイル: converter.py プロジェクト: ChartsBot/telegram-bots
    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)"
コード例 #2
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)"
コード例 #3
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
コード例 #4
0
ファイル: bloody_bot.py プロジェクト: rottedBen/telegram-bots
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
コード例 #5
0
def send_candlestick_pyplot(token,
                            charts_path,
                            k_days,
                            k_hours,
                            t_from,
                            t_to,
                            txt: str = None):
    print("requesting coin " + token + " from " + str(k_days) + " days and " +
          str(k_hours) + " hours")

    path = charts_path + token + '.png'
    last_price = graphs_util.print_candlestick(token, t_from, t_to, path, txt)

    callback_message = 'refresh_chart_' + "h:" + str(k_hours) + "d:" + str(
        k_days) + "t:" + token
    callback_message_1_w = 'refresh_chart_' + "h:" + str(0) + "d:" + str(
        7) + "t:" + token
    callback_message_1_d = 'refresh_chart_' + "h:" + str(0) + "d:" + str(
        1) + "t:" + token
    callback_message_1_m = 'refresh_chart_' + "h:" + str(0) + "d:" + str(
        30) + "t:" + token
    callback_message_2_h = 'refresh_chart_' + "h:" + str(2) + "d:" + str(
        0) + "t:" + token
    refresh_button = InlineKeyboardButton('Refresh ⌛',
                                          callback_data=callback_message)
    delete_button = InlineKeyboardButton('Delete 🗑️',
                                         callback_data='delete_message')
    button_list_chart = [
        [refresh_button, delete_button],
        [
            InlineKeyboardButton('2 hours',
                                 callback_data=callback_message_2_h),
            InlineKeyboardButton('1 day', callback_data=callback_message_1_d),
            InlineKeyboardButton('1 week', callback_data=callback_message_1_w),
            InlineKeyboardButton('1 month', callback_data=callback_message_1_m)
        ]
    ]
    # menu = util.build_menu(button_list_chart, 4, header_buttons=header)
    reply_markup_chart = InlineKeyboardMarkup(button_list_chart)
    msg_time = " " + str(
        k_days) + " day(s) " if k_days > 0 else " last " + str(
            k_hours) + " hour(s) "
    print(float_to_str(last_price))
    ad = util.get_ad()
    message = "<b>" + token + "</b>" + msg_time + "<code>$" + float_to_str(
        last_price)[0:10] + "</code>\n" + ad + ""

    return message, path, reply_markup_chart
コード例 #6
0
def send_gecko_chart(token_name: str, charts_path, k_days, grpc_graph_painter_client: GraphPainterServiceStub,
                     txt: str = None, options=[], with_ad=None):
    logging.info("requesting coin on gecko with symbol " + token_name + " from " + str(k_days) + " days")
    path = charts_path + token_name.replace('/', '-') + '.jpeg'
    collection_price: CollectionSingleTradePoint = graphs_util.print_simple_gecko_chart(token_name=token_name, days=k_days, file_path=path, grpc_graph_painter_client=grpc_graph_painter_client, txt=txt, options=options) #requests_util.get_gecko_chart(token_name=token_name, days=k_days)
    msg_time = " " + str(k_days) + " day(s)"
    ad = util.get_ad() if with_ad is None else with_ad
    last_price = collection_price.last_value().value
    h_l_message = util.high_low_to_message(max(collection_price.values()), min(collection_price.values()), '')
    message = "<b>" + token_name + "</b>" + msg_time + " on coingecko <code>$" + float_to_str(
        last_price)[0:10] + "\n" + h_l_message + "</code>\n" + ad + ""
    # r_c_s for Refresh Simple Chart

    callback_info_price = util.generate_callback_data_price(ticker_name=token_name,
                                                               address=token_name,
                                                               chain_name='gecko')
    button_price = InlineKeyboardButton('Infos 📰', callback_data=callback_info_price)
    reply_markup_chart = util.generate_reply_markup_chart(shortcut='rcgecko_',
                                                          refresh_times=[0, k_days, 'Refresh ⌛'],
                                                          l_times=[
                                                                   [0, 1, '1 day'],
                                                                   [0, 7, '1 week'],
                                                                   [0, 30, '1 month'],
                                                                   [0, 365, '1 year']],
                                                          token=token_name,
                                                          chain=SupportedChains.GECKO.value,
                                                          maybe_options=options,
                                                          with_switch_price=button_price)

    return message, path, reply_markup_chart
コード例 #7
0
def send_candlestick_pyplot(token, charts_path, k_days, k_hours, t_from, t_to,
                            grpc_graph_painter_client: GraphPainterServiceStub, txt: str = None, options=[],
                            with_ad=None):
    logging.info("requesting coin " + token + " from " + str(k_days) + " days and " + str(k_hours) + " hours")

    path = charts_path + token.replace('/', '-') + '.jpeg'
    collection_price = graphs_util.print_candlestick(token, t_from, t_to, path, grpc_graph_painter_client, txt, options)

    options_str = "o:" if options is None else "o:" + '//'.join(options)
    callback_message = 'refresh_chart_' + "h:" + str(k_hours) + "d:" + str(k_days) + "t:" + token + options_str
    callback_message_1_w = 'refresh_chart_' + "h:" + str(0) + "d:" + str(7) + "t:" + token + options_str
    callback_message_1_d = 'refresh_chart_' + "h:" + str(0) + "d:" + str(1) + "t:" + token + options_str
    callback_message_1_m = 'refresh_chart_' + "h:" + str(0) + "d:" + str(30) + "t:" + token + options_str
    callback_message_2_h = 'refresh_chart_' + "h:" + str(2) + "d:" + str(0) + "t:" + token + options_str
    refresh_button = InlineKeyboardButton('Refresh ⌛', callback_data=callback_message)
    # delete_button = InlineKeyboardButton('Delete 🗑️', callback_data='delete_message')
    button_list_chart = [[
        refresh_button
    ],
        [
            InlineKeyboardButton('2 hours', callback_data=callback_message_2_h),
            InlineKeyboardButton('1 day', callback_data=callback_message_1_d),
            InlineKeyboardButton('1 week', callback_data=callback_message_1_w),
            InlineKeyboardButton('1 month', callback_data=callback_message_1_m)
        ]]
    if options is not None:
        if "f" in options or "finance" in options:
            callback_message = 'refresh_chart_' + "h:" + str(k_hours) + "d:" + str(k_days) + "t:" + token + options_str
            callback_message_1_w = 'refresh_chart_' + "h:" + str(0) + "d:" + str(5) + "t:" + token + options_str
            callback_message_1_d = 'refresh_chart_' + "h:" + str(0) + "d:" + str(1) + "t:" + token + options_str
            callback_message_1_m = 'refresh_chart_' + "h:" + str(0) + "d:" + str(24) + "t:" + token + options_str
            callback_message_1_y = 'refresh_chart_' + "h:" + str(0) + "d:" + str(260) + "t:" + token + options_str
            refresh_button = InlineKeyboardButton('Refresh ⌛', callback_data=callback_message)
            # delete_button = InlineKeyboardButton('Delete 🗑️', callback_data='delete_message')
            button_list_chart = [[
                refresh_button
            ],
                [
                    InlineKeyboardButton('1 day', callback_data=callback_message_1_d),
                    InlineKeyboardButton('1 week', callback_data=callback_message_1_w),
                    InlineKeyboardButton('1 month', callback_data=callback_message_1_m),
                    InlineKeyboardButton('1 year', callback_data=callback_message_1_y),
                ]]
    reply_markup_chart = InlineKeyboardMarkup(button_list_chart)
    msg_time = " " + str(k_days) + " day(s) " if k_days > 0 else " last " + str(k_hours) + " hour(s) "
    if with_ad is None:
        ad = util.get_ad()
    else:
        ad = with_ad
    last_price = collection_price.last_value().v_close
    h_l_message = util.high_low_to_message(collection_price.highest_value().v_high, collection_price.lowest_value().v_low, '')
    message = "<b>" + token + "</b>" + msg_time + "<code>$" + float_to_str(last_price)[0:10] + "\n" + h_l_message + "</code>\n" + ad + ""

    return message, path, reply_markup_chart
コード例 #8
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)
コード例 #9
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
コード例 #10
0
def send_basic_chart(token_info: TokenMetadata, charts_path, k_days, k_hours, t_from, t_to, chain: Chain, grpc_graph_painter_client: GraphPainterServiceStub,
                     txt: str = None, options=[], with_ad=None):
    logging.info(
        f"{chain.name} - requesting coin {token_info.name} - {token_info.address} decimals: {token_info.decimals} from {k_days} days and {k_hours} hours")
    path = charts_path + token_info.address.replace('/', '-') + '.jpeg'
    collection_price = graphs_util.print_simple_chart(token_info, t_from, t_to, path, chain, grpc_graph_painter_client, txt, options)
    msg_time = " " + str(k_days) + " day(s) " if k_days > 0 else " last " + str(k_hours) + " hour(s) "
    ad = util.get_ad() if with_ad is None else with_ad
    h_l_message = util.high_low_to_message(max(collection_price.values()), min(collection_price.values()), '')
    message = "<b>" + token_info.ticker + "</b>" + msg_time + " on " + chain.name + " <code>$" + float_to_str(
        collection_price.last_value().value)[0:10] + "\n" + h_l_message + "</code>\n" + ad + ""
    # r_c_s for Refresh Simple Chart
    reply_markup_chart = util.generate_reply_markup_chart(shortcut='rcs_',
                                                          refresh_times=[k_hours, k_days, 'Refresh ⌛'],
                                                          l_times=[[2, 0, '2 hours'],
                                                                   [0, 1, '1 day'],
                                                                   [0, 7, '1 week'],
                                                                   [0, 30, '1 month']],
                                                          token=token_info.address,
                                                          chain=chain,
                                                          maybe_options=options)

    return message, path, reply_markup_chart