Пример #1
0
class Transaction(DocumentValidation):
    coin_token = StringField(required=True,
                             choices=get_coin_tokens(s.SYMBOLS_PER_EXCHANGE))
    units = DecimalField(required=True,
                         min_value=0,
                         precision=s.SYMBOL_FLOAT_PRECISION)
    amount = DecimalField(required=True,
                          min_value=0,
                          precision=s.SYMBOL_FLOAT_PRECISION)
    unit_price = DecimalField(required=True,
                              min_value=0,
                              precision=s.SYMBOL_FLOAT_PRECISION)
    user = ReferenceField(User, required=True)
    added_on = DateField(required=True)
    in_or_out = StringField(required=True, choices=(
        "in",
        "out",
    ))

    meta = {
        "collection": "transaction",
        "ordering": ["-added_on"],
    }

    _pre_save_hooks = (_calculate_unit_price, )
Пример #2
0
def context_processor():
    return dict(
        version=__version__,
        ga_tracking_id=current_app.config["GA_TRACKING_ID"],
        current_year=datetime.utcnow().year,
        frequencies=g.HISTORY_FREQUENCY,
        pairs=get_pairs(g.SYMBOLS_PER_EXCHANGE),
        tokens=get_coin_tokens(g.SYMBOLS_PER_EXCHANGE),
    )
Пример #3
0
def context_processor():
    return dict(
        application_server_key=current_app.config["APPLICATION_SERVER_KEY"],
        version=__version__,
        ga_tracking_id=current_app.config["GA_TRACKING_ID"],
        current_year=datetime.utcnow().year,
        frequencies=g.HISTORY_FREQUENCY,
        pairs=get_pairs(g.SYMBOLS_PER_EXCHANGE),
        tokens=get_coin_tokens(g.SYMBOLS_PER_EXCHANGE, show_all=True),
    )
Пример #4
0
def context_processor():
    return dict(
        socket_base_url=current_app.config["SOCKET_BASE_URL"],
        version=__version__,
        ga_tracking_id=current_app.config["GA_TRACKING_ID"],
        current_year=datetime.utcnow().year,
        frequencies=g.HISTORY_FREQUENCY,
        pairs=get_pairs(g.SYMBOLS_PER_EXCHANGE),
        tokens=get_coin_tokens(g.SYMBOLS_PER_EXCHANGE),
        attributes={"price_usdt": "Price USDT"},
    )
Пример #5
0
def context_processor():
    return dict(
        socket_base_url=current_app.config["SOCKET_BASE_URL"],
        socket_books_url=current_app.config["SOCKET_BOOKS_URL"],
        version=__version__,
        ga_tracking_id=current_app.config["GA_TRACKING_ID"],
        current_year=datetime.utcnow().year,
        frequencies=g.HISTORY_FREQUENCY,
        pairs=get_pairs(g.SYMBOLS_PER_EXCHANGE),
        tokens=get_coin_tokens(g.SYMBOLS_PER_EXCHANGE, show_all=True),
    )
Пример #6
0
class Notification(DocumentValidation):
    coin_token = StringField(required=True,
                             choices=get_coin_tokens(s.SYMBOLS_PER_EXCHANGE))
    message = StringField(required=True)
    user = ReferenceField(User, required=True)
    is_positive = BooleanField()

    meta = {
        "collection": "notification",
        "ordering": ["-created_on"],
    }

    @queryset_manager
    def objects(doc_cls, queryset):
        return queryset[:30]
Пример #7
0
class NotificationRule(DocumentValidation):
    coin_token = StringField(required=True,
                             choices=get_coin_tokens(s.SYMBOLS_PER_EXCHANGE))
    metric = StringField(required=True, choices=(
        "price",
        "volume",
    ))
    interval = StringField(required=True, choices=s.HISTORY_FREQUENCY)
    percentage = DecimalField(required=True, precision=2)
    user = ReferenceField(User, required=True)

    meta = {
        "collection": "notification_rule",
        "ordering": ["coin_token", "created_on"],
    }
Пример #8
0
        "name": BINANCE,
        "market_depth": BINANCE
    },
    "IDEX": {
        "pair": "ETH",
        "name": IDEX,
        "market_depth": IDEX
    },
    "LQD": {
        "pair": "ETH",
        "name": BILAXY,
        "market_depth": IDEX
    },
    "CARD": {
        "pair": "ETH",
        "name": HOTBIT,
        "market_depth": IDEX
    },
    "EWT": {
        "pair": "ETH",
        "name": LIQUID,
    },
}

# Check to make sure that ALL configured symbols must have an
# exchange and pair referenced
from xtcryptosignals.common.utils import get_coin_tokens  # noqa: E402

assert sorted(get_coin_tokens(SYMBOLS_PER_EXCHANGE)) == sorted(
    list(EXCHANGES_AND_PAIRS_OF_REFERENCE.keys()))
Пример #9
0
def tokens():
    return dict(tokens=get_coin_tokens(g.SYMBOLS_PER_EXCHANGE)), 200
Пример #10
0
def portfolio(auth):
    _portfolio = dict(coin_tokens=dict())
    total_paid = 0
    total_value = 0
    for coin_token in get_coin_tokens(s.SYMBOLS_PER_EXCHANGE):

        total_units_in = Transaction.objects(user=auth.user,
                                             coin_token=coin_token,
                                             in_or_out="in").sum("units")

        if total_units_in == 0:
            continue

        total_units_out = Transaction.objects(user=auth.user,
                                              coin_token=coin_token,
                                              in_or_out="out").sum("units")

        total_amount_paid = Transaction.objects(user=auth.user,
                                                coin_token=coin_token,
                                                in_or_out="in").sum("amount")

        total_amount_received = Transaction.objects(
            user=auth.user, coin_token=coin_token,
            in_or_out="out").sum("amount")

        total_units = total_units_in - total_units_out

        if total_units == 0:
            continue

        total_amount = total_amount_paid - total_amount_received

        average_paid = total_amount / total_units

        exchange = get_exchange_for(coin_token)

        try:
            current_price = _get_current_price(exchange, coin_token)
        except TypeError:
            # pair is not stored in Redis - most likely Exchange API is
            # failing
            # TODO: Still display this row in red in UI
            continue

        _portfolio["coin_tokens"].update({
            coin_token:
            dict(
                exchange=exchange,
                current_price=round(current_price, s.SYMBOL_FLOAT_PRECISION),
                units=round(total_units, s.SYMBOL_FLOAT_PRECISION),
                amount=total_amount,
                average_paid=average_paid,
                balance=round((current_price - average_paid) * total_units),
                position=_get_percentage(current_price, average_paid),
            ),
        })

        total_paid += total_amount

        total_value += total_units * current_price

    btc_price = _portfolio["coin_tokens"]["BTC"]["current_price"]

    _portfolio.update(
        total_paid=round(total_paid, 2),
        total_value=round(total_value, 2),
        total_position=_get_percentage(total_value, total_paid),
        total_in_btc=round(total_value / btc_price, 2),
    )

    _set_share_per_coin_token(_portfolio)

    return _portfolio