예제 #1
0
def getjsonorders(instrument, t):
    """ Returns open orders from redis orderbook. """
    orders = []
    if config.is_valid_instrument(instrument):
        if t == "bid":
            bids = redis.zrange(instrument + "/bid", 0, -1, withscores=True)
            for bid in bids:
                orders.append({
                    "price": bid[1],
                    "amount": redis.hget(bid[0], "amount")
                })
        else:
            asks = redis.zrange(instrument + "/ask", 0, -1, withscores=True)
            for ask in asks:
                orders.append({
                    "price": ask[1],
                    "amount": redis.hget(ask[0], "amount")
                })
        # So prices are not quoted in satoshis
        # TODO: move this client side?
        for order in orders:
            order['amount'] = float(order['amount']) / config.get_multiplier(
                instrument.split("_")[0])
    else:
        orders.append("Invalid trade pair!")
    jo = json.dumps(orders)
    return Response(jo, mimetype='application/json')
예제 #2
0
def getvolume(instrument):
    """ Returns open orders from redis orderbook. """
    #TODO: add some error checking in here
    completed_book = instrument+"/completed"
    orders = redis.zrange(completed_book,0,-1,withscores=True)
    quote_volume = 0.0
    base_volume = 0.0
    for order in orders:
        # I *REALLY* should not be doing this every time I go though, but it's temporary
        # Note this is evaluated before gethigh and getlow when the front page is displayed so those values should be correct as well due to clean in up here
        if not redis.exists(order[0]):
            redis.zrem(completed_book,order[0])
            continue
        quote_volume += float(redis.hget(order[0],'quote_currency_amount'))
        base_volume += float(redis.hget(order[0],'base_currency_amount'))
    return {"quote_currency_volume":quote_volume, "base_currency_volume":base_volume}
예제 #3
0
def activate_account(code):
    uid = redis.hget('activation_keys', code)
    if not uid:
        return  home_page("ltc_btc", danger='Invalid registration code!')
    user = User.query.filter(User.id==uid).first()
    if not user or user.activated:
        return  home_page("ltc_btc", danger='Account already registered or invalid code!')
    user.activated = True
    redis.hdel('activation_keys', code)
    db_session.commit()
    return home_page("ltc_btc", dismissable='Account successfully registered!')
예제 #4
0
def activate_account(code):
    uid = redis.hget('activation_keys', code)
    if not uid:
        return home_page("ltc_btc", danger='Invalid registration code!')
    user = User.query.filter(User.id == uid).first()
    if not user or user.activated:
        return home_page("ltc_btc",
                         danger='Account already registered or invalid code!')
    user.activated = True
    redis.hdel('activation_keys', code)
    db_session.commit()
    flash("Account successfully registered!", "dismissable")
    return home_page("ltc_btc")
예제 #5
0
def getjsonorders(instrument, t):
    """ Returns open orders from redis orderbook. """
    orders = []
    if config.is_valid_instrument(instrument):
        if t == "bid":
            bids = redis.zrange(instrument + "/bid", 0, -1, withscores=True)
            for bid in bids:
                orders.append(
                    {"price": bid[1], "amount": redis.hget(bid[0], "amount")})
        else:
            asks = redis.zrange(instrument + "/ask", 0, -1, withscores=True)
            for ask in asks:
                orders.append(
                    {"price": ask[1], "amount": redis.hget(ask[0], "amount")})
        # So prices are not quoted in satoshis
        # TODO: move this client side?
        for order in orders:
            order['amount'] = float(
                order['amount']) / config.get_multiplier(instrument.split("_")[0])
    else:
        orders.append("Invalid trade pair!")
    jo = json.dumps(orders)
    return Response(jo, mimetype='application/json')