def fire(self, job_data): job_id = str(uuid.uuid4()) data = json.dumps({ "id": job_id, "data": job_data }) log.info("Queueing job #%s" % job_id) redis.rpush("jobq:%s" % self.name, data)
def cancelorder(old_order_id): if not is_logged_in(session): return home_page("ltc_btc",danger="Please log in to perform that action.") uid = session['userid'] if old_order_id not in redis.smembers(str(uid)+"/orders"): return home_page("ltc_btc",danger="Unable to cancel the specified order!") orderid = generate_password_hash(str(random.random())) redis.hmset(orderid, {"ordertype":'cancel', "uid":uid, 'old_order_id':old_order_id}) redis.rpush("order_queue",orderid) return home_page("ltc_btc", dismissable="Cancelled order!")
def addorder(): """ Checks balance and essential stuff, generates an order ID then adds order to a redis queue. """ instrument = request.form['currency_pair'] if not is_logged_in(session): return home_page(instrument, danger="Please log in to perform that action.") #They shouldn't be able to modify the trade pair, if it isnt valid either I messed up somewhere or they are trying to do something wrong if not config.is_valid_instrument(instrument): return home_page("ltc_btc", danger="Unknown Error, contact the administrator!") base_currency = request.form['currency_pair'].split("_")[0] quote_currency = request.form['currency_pair'].split("_")[1] try: rprice = Decimal(request.form['price']) ramount = string_to_currency_unit(request.form['amount'], config.get_multiplier(base_currency)) print(ramount) except Exception as e: print(e) return home_page(instrument, danger="Please enter numerical values for price and amount!") if ramount < 1: #TODO: find a good amount for this return home_page(instrument, danger="Transaction amount too low!") if rprice <= 0: return home_page(instrument, danger="Price must be greater than 0!") getcontext().prec = 6 whole, dec = ExtendedContext.divmod(rprice*ramount/config.get_multiplier(base_currency), Decimal(1)) total = int(whole * config.get_multiplier(base_currency) + dec * config.get_multiplier(base_currency)) print("total: " + str(total)) uid = session['userid'] orderid = generate_password_hash(str(random.random())) instrument = request.form['currency_pair'] bidtable = instrument + "/bid" asktable = instrument + "/ask" if request.form['ordertype'] == 'buy': currency = quote_currency if check_balance(currency,session['userid']) < total: return home_page(instrument, danger="Balance too low to execute order!") else: adjustbalance(currency,session['userid'],-1 * total) elif request.form['ordertype'] == 'sell': currency = base_currency if check_balance(currency, uid) < ramount: return home_page(instrument, danger="Balance too low to execute order!") else: adjustbalance(currency, uid, -1 * ramount) else: return home_page(instrument, danger="Unknown Error, contact the administrator!") #invalid order type, they must have been messing around redis.hmset(orderid, {"ordertype":request.form['ordertype'],"instrument":request.form['currency_pair'],"amount":ramount, "uid":uid,"price":rprice}) redis.rpush("order_queue",orderid) redis.sadd(str(uid)+"/orders", orderid) return home_page(instrument, dismissable="Order placed successfully!")
def addorder(): """ Checks balance and essential stuff, generates an order ID then adds order to a redis queue. """ instrument = request.form['currency_pair'] if not is_logged_in(session): return home_page(instrument, danger="Please log in to perform that action.") #They shouldn't be able to modify the trade pair, if it isnt valid either I messed up somewhere or they are trying to do something wrong if not config.is_valid_instrument(instrument): return home_page("ltc_btc", danger="Unknown Error, contact the administrator!") base_currency = request.form['currency_pair'].split("_")[0] quote_currency = request.form['currency_pair'].split("_")[1] try: rprice = float(request.form['price']) ramount = int(float(request.form['amount'])* config.get_multiplier(base_currency)) except: return home_page(instrument, danger="Please enter numerical values for price and amount!") if ramount < 1: #TODO: find a good amount for this return home_page(instrument, danger="Transaction amount too low!") if rprice <= 0: return home_page(instrument, danger="Price must be greater than 0!") total = int(rprice * ramount) uid = session['userid'] orderid = generate_password_hash(str(random.random())) instrument = request.form['currency_pair'] bidtable = instrument + "/bid" asktable = instrument + "/ask" if request.form['ordertype'] == 'buy': currency = quote_currency if check_balance(currency,session['userid']) < total: return home_page(instrument, danger="Balance too low to execute order!") else: adjustbalance(currency,session['userid'],-1 * total) elif request.form['ordertype'] == 'sell': currency = base_currency if check_balance(currency, uid) < ramount: return home_page(instrument, danger="Balance too low to execute order!") else: adjustbalance(currency, uid, -1 * ramount) else: return home_page(instrument, danger="Unknown Error, contact the administrator!") #invalid order type, they must have been messing around redis.hmset(orderid, {"ordertype":request.form['ordertype'],"instrument":request.form['currency_pair'],"amount":ramount, "uid":uid,"price":rprice}) redis.rpush("order_queue",orderid) redis.sadd(str(uid)+"/orders", orderid) return home_page(instrument, dismissable="Order placed successfully!")
def create_bet(user, match, team, items): data = { 'user': user, 'match': match, 'team': team, 'items': map(lambda i: SteamItem(i.id, None, None, { "price": float(i.price) }), items), 'state': BetState.OFFERED, 'created_at': datetime.utcnow(), } data['value'] = sum(map(lambda i: i.price, items)) with Cursor() as c: id = c.execute(CREATE_BET_SQL, data).fetchone() redis.rpush("trade-queue", json.dumps({ "time": time.time(), "type": "INTAKE", "id": id })) return id