예제 #1
0
def getRobotsDel():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)
    if filters.get('id'):
        PGHelper.execute_vars("DELETE FROM robots WHERE id = %s",
                              (int(filters.get('id'))))
    return jsonify(valid=True)
예제 #2
0
def getApi():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)

    time = (datetime.datetime.utcnow() -
            datetime.timedelta(minutes=5)).isoformat()
    if filters.get('filters') is None or len(filters.get('filters')) == 0:
        data = PGHelper.selectAll(
            "select * from (SELECT DISTINCT ON (e1.name, e2.name, p_name) e1.name as e1_name, e2.name as e2_name, divergent.time as time, divergent.diff as diff, CONCAT(p.base_key, '-', p.quote_key) as p_name FROM divergent LEFT JOIN exchanges AS e1 ON (exchanges1_id=e1.id) LEFT JOIN exchanges AS e2 ON (exchanges2_id=e2.id) LEFT JOIN pairs as p ON (pair_id=p.id) WHERE divergent.time > '"
            + time +
            "' ORDER BY e1.name, e2.name, p_name, divergent.time desc) as q order by diff desc LIMIT 200"
        )
    else:
        where_str = "divergent.time > '" + time + "'"
        if filters.get('filters').get('exchanges'):
            where_str = where_str + "AND e1.id IN(" + ",".join(
                filters.get('filters').get(
                    'exchanges')) + ") OR e2.id IN(" + ",".join(
                        filters.get('filters').get('exchanges')) + ")"
        if filters.get('filters').get('pairs'):
            where_str = where_str + "AND p.id IN(" + ",".join(
                filters.get('filters').get('pairs')) + ")"
        if filters.get('filters').get('actives'):
            pass
        data = PGHelper.selectAll(
            "select * from (SELECT DISTINCT ON (e1.name, e2.name, p.pair_name) e1.name as e1_name, e2.name as e2_name, divergent.time as time, divergent.diff as diff, p.pair_name as p_name FROM divergent LEFT JOIN exchanges AS e1 ON (exchanges1_id=e1.id) LEFT JOIN exchanges AS e2 ON (exchanges2_id=e2.id) LEFT JOIN pairs as p ON (pair_id=p.id) WHERE "
            + where_str +
            " ORDER BY e1.name, e2.name, p.pair_name, divergent.time desc) as q order by diff desc LIMIT 200"
        )

    return jsonify(valid=True, result=data)
예제 #3
0
def register():
    incoming = request.get_json()
    incoming = ObjectHelper.cleanEmptyValues(incoming)
    if incoming.get('data'):
        try:
            incoming = incoming.get('data')
            if incoming.get('userlogin') and incoming.get(
                    'password') and incoming.get('email'):
                user = PGHelper.selectOne(
                    "SELECT password FROM users WHERE userlogin='******'userlogin') + "'")
                if user:
                    return jsonify(valid=False, error="exist")
                else:
                    password = Users.generate_new_password(
                        incoming.get('password'))
                    role = PGHelper.selectOne("SELECT get_role_id('admin')")
                    PGHelper.execute_vars(
                        "INSERT INTO users (userlogin, password, email, banned, username, role, created) VALUES (%s, %s, %s, false, %s, %s, %s)",
                        (incoming.get('userlogin'), password,
                         incoming.get('email') if incoming.get('email') else
                         "", incoming.get('username')
                         if incoming.get('username') else "",
                         role.get('get_role_id'), datetime.utcnow()))
                    ids = PGHelper.selectOne(
                        "SELECT id FROM users WHERE userlogin='******'userlogin') + "' AND email='" +
                        incoming.get('email') + "'")
                    if ids and ids.get('id'):
                        user = {
                            "id":
                            ids.get('id'),
                            "email":
                            incoming.get('email'),
                            "role":
                            role,
                            "username":
                            incoming.get('username')
                            if incoming.get('username') else "",
                            "userlogin":
                            incoming.get('userlogin')
                        }
                        token = generate_token(user)
                        return jsonify(valid=True, token=token)
                    else:
                        return jsonify(valid=False, error="server_error")
            else:
                return jsonify(valid=False, error="no_data")
        except BaseException:
            return jsonify(valid=False, error="exception")

    else:
        return jsonify(valid=False, error="no_input")
예제 #4
0
def getSettings():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)

    if filters.get('user'):
        if filters.get('data'):
            PGHelper.execute_vars("UPDATE users SET settings=%s WHERE id=%s",
                                  (filters.get('data'), filters.get('user')))
            return jsonify(valid=True)
        else:
            data = PGHelper.selectOne(
                "SELECT settings, id FROM users WHERE id=" +
                filters.get('user'))
            return jsonify(valid=True, result=data)
    else:
        return jsonify(valid=False, error="no_user")
예제 #5
0
def getInternalAssets():
	filters = request.get_json()
	filters = ObjectHelper.cleanEmptyValues(filters)

	if filters.get('id') and filters.get('data') and len(filters.get('data')) > 1:
		summ = 0
		for k, v in enumerate(filters.get('data')):
			if filters.get('data')[k+1]:
				pair = v + "_" + filters.get('data')[k+1]
			else:
				pair = v + "_" + filters.get('data')[0]

			stage1 = PGHelper.selectOne("SELECT pair, ask FROM tickers_source WHERE pair='" + pair + "' AND exchange='" + filters.get('id') + "' ORDER BY time DESC LIMIT 1")

			if stage1:
				if summ == 0:
					summ = stage1.get('ask')
				else:
					summ = summ / stage1.get('ask')
			else:
				summ = 0

		return jsonify(valid=True, result=summ)
	else:
		return jsonify(valid=False, error="no_data")
예제 #6
0
def getRobotsList():
    # filters = request.get_json()
    # filters = ObjectHelper.cleanEmptyValues(filters)

    data = PGHelper.selectAll(
        "SELECT robots.summ as summ, robots.safe as safe, signals.id as sig_id, signals.name as signame, signals.type, e1.name as e1_name, e2.name as e2_name, a1.name as a1_name, a2.name as a2_name, a3.name as a3_name, signals.data2, u.userlogin, u.username FROM robots LEFT JOIN signals ON(robots.signal=signals.id) LEFT JOIN exchanges AS e1 ON (exchange1=e1.key) LEFT JOIN exchanges AS e2 ON (exchange2=e2.key) LEFT JOIN assets AS a1 ON (asset1=a1.symbol) LEFT JOIN assets AS a2 ON (asset2=a2.symbol) LEFT JOIN assets AS a3 ON (asset3=a3.symbol) LEFT JOIN users AS u ON (user_id=u.id)"
    )
    return jsonify(valid=True, result=data)
예제 #7
0
def getEventsList():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)

    data = PGHelper.selectAll(
        "SELECT events.name as signame, events.type, e1.name as e1_name, e2.name as e2_name, a1.name as a1_name, a2.name as a2_name, a3.name as a3_name, events.data2, events.time as time, u.userlogin, u.username FROM events LEFT JOIN exchanges AS e1 ON (exchange1=e1.id) LEFT JOIN exchanges AS e2 ON (exchange2=e2.id) LEFT JOIN assets AS a1 ON (asset1=a1.id) LEFT JOIN assets AS a2 ON (asset2=a2.id) LEFT JOIN assets AS a3 ON (asset3=a3.id) LEFT JOIN users AS u ON (user_id=u.id) ORDER BY events.time DESC"
    )
    return jsonify(valid=True, result=data)
예제 #8
0
def getRobotsSet():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)
    if filters.get('summ') and filters.get('safe') and filters.get('signal'):
        if filters.get('id'):
            PGHelper.execute_vars(
                "UPDATE robots SET signal = %s, summ = %s, safe = %s WHERE id = %s",
                (int(filters.get('signal')), float(filters.get('summ')),
                 filters.get('safe'), int(filters.get('id'))))
        else:
            PGHelper.execute_vars(
                "INSERT INTO robots (signal, summ, safe) VALUES(%s, %s, %s)",
                (int(filters.get('signal')), float(
                    filters.get('summ')), filters.get('safe')))
        return jsonify(valid=True)
    else:
        return jsonify(valid=False, error="no_data")
예제 #9
0
def getMain():
    user = PGHelper.selectOne(
        "SELECT username, userlogin FROM users WHERE id=" +
        g.current_user.get('ID'))
    if user:
        user["cash"] = 0.00000007
        user["hold"] = 0.00000007
        return jsonify(valid=True, result=user)
    else:
        return jsonify(valid=False, error="no_user")
예제 #10
0
def getInternalList():
	filters = request.get_json()
	filters = ObjectHelper.cleanEmptyValues(filters)
	if filters.get('filters') is None or len(filters.get('filters')) == 0:
		data = PGHelper.selectAll("SELECT internal.id, percent, e1.name as exchange, a1.name as asset1, a2.name as asset2, a3.name as asset3, internal.time as time FROM internal LEFT JOIN exchanges AS e1 ON (exchange=e1.id) LEFT JOIN assets AS a1 ON (asset0=a1.id) LEFT JOIN assets AS a2 ON (asset1=a2.id) LEFT JOIN assets AS a3 ON (asset2=a3.id) ORDER BY percent desc LIMIT 1000")
		for k, v in enumerate(data):
			data[k]['time'] = v.get('time').isoformat()
	else:
		where_str = "WHERE percent > 0 "
		if filters.get('filters').get('exchanges'):
			where_str = where_str + "AND e1.id IN(" + ",".join(filters.get('filters').get('exchanges')) + ")"
		if filters.get('filters').get('assets'):
			where_str = where_str + "AND a1.id IN(" + ",".join(filters.get('filters').get('assets')) + ") OR a2.id IN(" + ",".join(filters.get('filters').get('assets')) + ") OR a3.id IN(" + ",".join(filters.get('filters').get('assets')) + ")"
		if filters.get('filters').get('actives'):
			pass
		where = where_str if where_str else ""
		data = PGHelper.selectAll("SELECT internal.id, percent, e1.name as exchange, a1.name as asset1, a2.name as asset2, a3.name as asset3, internal.time as time FROM internal LEFT JOIN exchanges AS e1 ON (exchange=e1.id) LEFT JOIN assets AS a1 ON (asset0=a1.id) LEFT JOIN assets AS a2 ON (asset1=a2.id) LEFT JOIN assets AS a3 ON (asset2=a3.id) " + where + " ORDER BY percent desc")
		for k, v in enumerate(data):
			data[k]['time'] = v.get('time').isoformat()
	return jsonify(valid=True, result=data)
예제 #11
0
    def get_user_with_user_and_password(user, password):
        hashed = Users.hashed_password(password)

        user = PGHelper.selectOne(
            "SELECT password, id, email, username, userlogin FROM users WHERE userlogin='******' LIMIT 1")
        if user and bc.checkpw(hashed.encode('utf-8'),
                               user.get('password').encode('utf-8')):
            return user
        else:
            return None
예제 #12
0
def emailex():
    incoming = request.get_json()
    incoming = ObjectHelper.cleanEmptyValues(incoming)
    if incoming.get('email'):
        user = PGHelper.selectOne("SELECT userlogin FROM users WHERE email='" +
                                  incoming.get('email') + "'")
        if user:
            return jsonify(valid=True, result=True)
        else:
            return jsonify(valid=True, result=False)
    else:
        return jsonify(valid=False, error="no_data")
예제 #13
0
def getSignalsSet():
    filters = request.get_json()
    filters = ObjectHelper.cleanEmptyValues(filters)
    if filters.get('id') and filters.get('type') and filters.get(
            'percent') and filters.get('name') and filters.get('data1'):
        if filters.get('type') == 1:  # Внутренний
            data = PGHelper.selectOne(
                "SELECT a1.symbol as a1, a2.symbol as a2, a3.symbol as a3, e1.key as e1 FROM internal LEFT JOIN exchanges AS e1 ON (exchange=e1.id) LEFT JOIN assets AS a1 ON (asset0=a1.id) LEFT JOIN assets AS a2 ON (asset1=a2.id) LEFT JOIN assets AS a3 ON (asset2=a3.id) WHERE internal.id="
                + str(filters.get('id')))
        else:
            data = PGHelper.selectOne(
                "SELECT p.base_key as a1, p.quote_key as a2, e1.key as e1, e2.key as e2 FROM divergent LEFT JOIN exchanges AS e1 ON (exchanges1_id=e1.id) LEFT JOIN exchanges AS e2 ON (exchanges2_id=e2.id) LEFT JOIN pairs AS p ON (pair_id=p.id) WHERE divergent.id="
                + str(filters.get('id')))

        PGHelper.execute_vars(
            "INSERT INTO signals (name, user_id, exchange1, exchange2, asset1, asset2, asset3, type, data1, data2) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
            (filters.get('name'), int(g.current_user.get("ID")),
             data.get('e1'), data.get('e2') if data.get('e2') else "",
             data.get('a1'), data.get('a2'),
             data.get('a3') if data.get('a3') else "", filters.get('type'),
             filters.get('data1'), filters.get('percent')))
        return jsonify(valid=True)
    else:
        return jsonify(valid=False, error="no_data")
예제 #14
0
def getAssets():
    data = PGHelper.selectAll(
        "SELECT id, symbol, name FROM assets ORDER BY id DESC")
    return jsonify(valid=True, result=data)
예제 #15
0
def getMarkets():
    data = PGHelper.selectAll(
        "SELECT id, key, name FROM exchanges ORDER BY id DESC")
    return jsonify(valid=True, result=data)
예제 #16
0
 def is_admin(ids):
     user = PGHelper.selectOne("SELECT username FROM users WHERE id=" +
                               ids + " AND role=get_role_id('admin')")
     if user:
         return True
     return False
예제 #17
0
def getPairs():
    data = PGHelper.selectAll(
        "SELECT id, CONCAT(base_name, '-', quote_name) as name FROM pairs WHERE base_key <> '' AND quote_key <> '' ORDER BY id DESC"
    )
    return jsonify(valid=True, result=data)