예제 #1
0
def price_view(trading_pair):
    view = ''

    currency_symbol = trading_pair['counter_currency']

    counter_currency = COUNTER_CURRENCIES.index(
        trading_pair['counter_currency'])
    currency = trading_pair['transaction_currency']

    exchanges = get_exchanges()

    last_prices_object = PriceHistory.objects.filter(
        source__in=exchanges,
        transaction_currency=currency,
        counter_currency=counter_currency).order_by(
            '-timestamp')[:len(exchanges)]

    seen = set()
    seen_add = seen.add
    # remove dublicates
    unique_last_prices = [
        price for price in last_prices_object
        if not (price.source in seen or seen_add(price.source))
    ]

    for price_obj in sorted(unique_last_prices, key=lambda pr: pr.close):
        view += f"\n{format_currency(price_obj.close, currency_symbol)} on {get_source_name(price_obj.source).title()} at {format_timestamp(price_obj.timestamp)}"

    return view
예제 #2
0
파일: info.py 프로젝트: kamleshahire/core
def info_view(update):
    view = f'Hello, hello, {update.message.from_user.first_name}!\n\n'

    exchanges = (get_source_name(index).capitalize() for index in get_exchanges())
    view += f'I support these exchanges: `{", ".join(exchanges)}\n\n`'

    period_in_seconds = 2*60*60 if not LOCAL else 2000*60*60
    trading_pairs = get_currency_pairs(source='all', period_in_seconds=period_in_seconds, counter_currency_format="text")

    coins = set(coin for coin, _ in trading_pairs)
    view += f'And {len(coins)} coins:\n`{", ".join(coins)}`\n\n'

    view += f'And {len(trading_pairs)} trading pairs, like `BTC_USDT, ETH_BTC, XRP_ETH ...`\nI love long text messages, but this message is already too long, even for me 🙂  '

    return view
예제 #3
0
def price_view(trading_pair):
    view = ''

    if trading_pair['counter_currency'] == 'USDT':
        currency_symbol = '$'
    else:
        currency_symbol = ''

    counter_currency = COUNTER_CURRENCIES.index(
        trading_pair['counter_currency'])
    currency = trading_pair['transaction_currency']

    exchanges = get_exchanges()

    last_prices_object = Price.objects.filter(
        source__in=exchanges,
        transaction_currency=currency,
        counter_currency=counter_currency).order_by(
            '-timestamp')[:len(exchanges)]

    seen = set()
    seen_add = seen.add
    # remove dublicates
    unique_last_prices = [
        price for price in last_prices_object
        if not (price.source in seen or seen_add(price.source))
    ]
    exchanges_with_price = natural_join([
        get_source_name(price.source).title() for price in unique_last_prices
    ])

    view += f"I found *{currency}*\_{trading_pair['counter_currency']} in {exchanges_with_price}\n"

    for price_obj in sorted(unique_last_prices, key=lambda pr: pr.price):
        view += f"\n*{format_currency(price_obj.price, currency_symbol)}* on {get_source_name(price_obj.source).title()} at {format_timestamp(price_obj.timestamp)}"

    return view
예제 #4
0
파일: itf.py 프로젝트: linuxmahara/core
from cache_memoize import cache_memoize
from telegram import ParseMode

from settings import INFO_BOT_CRYPTOPANIC_API_TOKEN, INFO_BOT_CACHE_TELEGRAM_BOT_SECONDS
from settings import COUNTER_CURRENCIES

from apps.indicator.models import PriceHistory

from apps.signal.models import Signal

from apps.info_bot.helpers import format_currency, format_timestamp, parse_telegram_cryptocurrency_args
from apps.info_bot.helpers import save_history

from taskapp.helpers import get_source_name, get_exchanges

SOURCES = get_exchanges()
## helpers


def percents(new_value, old_value):
    return 100 * (new_value - old_value) / old_value


def diff_symbol(diff):  # ↑ increase, ↓ decrease
    if diff > 0:
        d_sym = "⬆"
    elif diff < 0:
        d_sym = "⬇"
    else:
        d_sym = ""
    return d_sym
예제 #5
0
def compute_and_save_indicators_for_all_sources(resample_period):
    from taskapp.helpers import get_exchanges
    for exchange in get_exchanges():
        compute_and_save_indicators.delay(source=exchange, resample_period=resample_period)