Beispiel #1
0
def notify_revenue(db):
    # beginning of last UTC day
    start_time = Delorean().last_day().truncate('day').datetime
    end_time = Delorean().truncate('day').datetime

    # This revenue calculating logic takes about 10s to run
    open_position_offset = positions.fast_position(
        db,
        end_time=start_time,
    )

    open_position_trades = revenue_lib.open_position_trades(
        open_position_offset,
        db,
        start_time,
    )

    trades = db\
        .query(Trade)\
        .join(Order)\
        .filter(Order.actor == 'Multi')\
        .filter(Trade.time_created >= start_time)\
        .filter(Trade.time_created < end_time)\
        .options(joinedload('order'))\
        .order_by(Trade.time_created)\
        .all()

    matched_trades, _ = revenue_lib.split_trades(open_position_trades +
                                                 trades, )

    __, revenue, __, __ = revenue_lib.profit_data(matched_trades, 'USD')

    slacker = Slacker('#general', 'revenue', icon_emoji=':moneybag:')
    slacker.notify('We made %s today' % revenue)
Beispiel #2
0
def message_dev_for_summary(dev):
    channel = '#general'
    message = 'Hey @%s, what did you get up to today?' % dev['name']
    emoji = fun_emoji()
    bot_name = fun_bot_name(emoji)
    slacker = Slacker(channel, bot_name, icon_emoji=emoji)
    slacker.notify(message)
Beispiel #3
0
def message_dev_for_checkin(dev, current_time):
    logger.info('pinging @%s' % dev['name'])

    channel = '@%s' % dev['name']
    message = 'Time for a quick checkin'
    emoji = clock_emoji(current_time)
    slacker = Slacker(channel, 'checkin', icon_emoji=emoji)
    slacker.notify(message)
Beispiel #4
0
def btc_withdrawal_notification(exchange_db, amount):
    on_call_dev = get_on_call_dev()
    amount = amount.round_to_decimal_places(0)
    channel = '@%s' % on_call_dev
    message = 'Do a %d BTC withdrawal from %s' % (amount.amount,
                                                  exchange_db.name)

    logger.info('Hipchat ping: %s' % message)

    slacker = Slacker(channel, 'withdrawals', icon_emoji=':moneybag:')
    slacker.notify(message)
Beispiel #5
0
def notify_on_call_dev(transaction, db_account):
    """
    Notify the current on-call dev that a wire has landed
    """
    try:
        on_call_dev = shoebox.get_on_call_dev()
        channel = '@%s' % on_call_dev

        message = '%s wire landed in %s [%s]' % (
            transaction['amount'], db_account.name, transaction['description'])

        slacker = Slacker(channel, 'mover', icon_emoji=':moneybag:')
        slacker.notify(message)
    except:
        pass
Beispiel #6
0
def get_breaking_bitcoin_news():
    reddit_breaking_news = redditor.get_reddit_breaking_news(
        'bitcoin', upvote_threshold=500)

    hn_keyword_dict = {
        'bitcoin': 15,
        'bitstamp': 5,
        'bitfinex': 5,
        'cavirtex': 5,
        'quadriga': 5,
        'okcoin': 5,
        'coinbase': 5,
        'coinsetter': 5,
        'gemini': 5,
        'kraken': 5,
    }

    hn_breaking_news = hackernewsie.get_hn_breaking_news(hn_keyword_dict)

    for news in reddit_breaking_news:
        news['source'] = 'Reddit'

    for news in hn_breaking_news:
        news['source'] = 'HN'

    breaking_news = reddit_breaking_news + hn_breaking_news
    if breaking_news:
        message = 'Breaking News:\n'

        for news in breaking_news:
            message += '<%s|%s> (<%s|%s comments>)\n\n' % (
                news['url'], news['title'], news['comments_url'],
                news['source'])

        slacker = Slacker('#news', 'news')
        slacker.notify(message)
Beispiel #7
0
def money_moving():
    current_time = Delorean().datetime

    morning_timeslot = parse('9am -0800').datetime  # when we get up in PST
    afternoon_timeslot = parse(
        '3:30pm -0500').datetime  # 4pm EST is BMO's wire cutoff

    in_morning_timeslot = (current_time.hour == morning_timeslot.hour
                           and current_time.minute == morning_timeslot.minute)

    in_afternoon_timeslot = (current_time.hour == afternoon_timeslot.hour and
                             current_time.minute == afternoon_timeslot.minute)

    if in_morning_timeslot or in_afternoon_timeslot:
        on_call_dev = get_on_call_dev()
        channel = '@%s' % on_call_dev

        if in_morning_timeslot:
            message = 'Time for early morning money moving!'
        elif in_afternoon_timeslot:
            message = 'Time for afternoon money moving! (Wire cutoff is 4pm EST)'

        slacker = Slacker(channel, 'mover', icon_emoji=':moneybag:')
        slacker.notify(message)
Beispiel #8
0
class TradesAuditor(Auditor):
    def __init__(self, exchanges=[]):
        self.exchanges = exchanges

    def heartbeat(self, response=None):
        subprocess.call(
            ["touch", "monit/heartbeat/trades_auditor_heartbeat.txt"])

    @defer.inlineCallbacks
    def start(self):
        self.redis = yield util.setup_redis()
        self.setup_mysql()
        self.heartbeat_key = 'trades_auditor_heartbeat'
        self.looping_call = LoopingCall(self.audit).start(1800)
        self.accuracy_bottom = Decimal('0.99')
        self.accuracy_top = Decimal('1.01')
        self.slacker = Slacker('#notifications', 'Auditor')

    @inlineCallbacks
    def audit(self):
        successes = []

        for exchange in self.exchanges:
            now = datetime.utcnow()
            twenty_four_hours_ago = now - timedelta(hours=24)
            ten_minutes_ago = now - timedelta(minutes=10)

            trades_sum_result = yield self.engine.execute(
                select([func.sum(trades.c.volume)]).where(
                    and_(
                        trades.c.exchange.__eq__(exchange),
                        trades.c.timestamp.between(twenty_four_hours_ago, now),
                    )))

            trades_sum_result = yield trades_sum_result.fetchone()
            trades_volume = trades_sum_result[0] or 0

            exchange_volume_result = yield self.engine.execute(
                select([exchange_volumes.c.exchange_volume]).where(
                    and_(
                        exchange_volumes.c.exchange.__eq__(exchange),
                        exchange_volumes.c.timestamp.between(
                            ten_minutes_ago, now),
                    )).order_by(exchange_volumes.c.timestamp.desc()))

            exchange_volume_result = yield exchange_volume_result.fetchone()

            if exchange_volume_result:
                most_recent_exchange_volume = exchange_volume_result[0]

                accuracy = trades_volume / most_recent_exchange_volume
                log.msg('Trade Volume Accuracy on %s: %s' %
                        (exchange, accuracy))

                if accuracy < self.accuracy_bottom or accuracy > self.accuracy_top:
                    successes.append(False)

                    self.slacker.notify(
                        '%s Trades Poller at %s accuracy. Outside %s-%s' % (
                            exchange,
                            accuracy,
                            self.accuracy_bottom,
                            self.accuracy_top,
                        ))
                else:
                    successes.append(True)

        # If all exchanges passed their audit then we heartbeat.
        if all(successes):
            self.heartbeat()