示例#1
0
def get_k_line(pair_name, time_interval='1min'):
    if '1min' == time_interval:
        result = sql_module.query_data(
            'SELECT * FROM history_market WHERE pair = "%s" ORDER BY timetick LIMIT 1440'
            % pair_name)
    #elif '3min' == time_interval :
    #elif '5min' == time_interval :
    #elif '15min' == time_interval :
    #elif '1h' == time_interval :
    #elif '4h' == time_interval :
    #elif '12h' == time_interval :
    #elif '1d' == time_interval :
    #elif '1w' == time_interval :
    #    result = sql_module.query_data('SELECT * FROM history_market WHERE pair = "%s" ORDER BY timetick LIMIT 1440' % pair_name)

    output_result = []

    for index in result:
        output_result.append({
            'open': str(index[1]),
            'close': str(index[2]),
            'max': str(index[3]),
            'min': str(index[4]),
            'timetick': str(index[5]),
            'amount': str(index[6]),
        })

    if not result:
        return server_data.server_api_result(False, 'No Data')

    return server_data.server_api_result(True, data=output_result)
示例#2
0
def get_simple_k_line(pair_name):
    SIMPLE_K_LINE_TIME_INTERVAL = 30

    result = sql_module.query_data(
        'SELECT close FROM history_market WHERE pair = "%s" AND timeinterval = "1m" ORDER BY timetick LIMIT 1440'
        % pair_name)

    if not result:
        return server_data.server_api_result(False, 'No Data')

    output_result = []

    for index in range(0, len(result), SIMPLE_K_LINE_TIME_INTERVAL):
        end_search_limit = 0

        if index + SIMPLE_K_LINE_TIME_INTERVAL > len(result):
            end_search_limit = len(result)
        else:
            end_search_limit = index + SIMPLE_K_LINE_TIME_INTERVAL

        max_close = 0

        for search_max_index in range(index, end_search_limit):
            if max_close < result[search_max_index]:
                max_close = str(result[search_max_index][0])

        output_result.append(max_close)

    return server_data.server_api_result(True, data=output_result)
示例#3
0
def get_depth(pair_name):
    DEPTH_EXPIRE_DATA_TIME = 5 * 60
    result = sql_module.query_data(
        'SELECT timetick,bid,ask FROM history_depth WHERE pair = "%s" ORDER BY timetick LIMIT 30'
        % pair_name)

    if result:
        timetick = result[0][0]
        exec('bid_list = ' + result[0][1])
        exec('ask_list = ' + result[0][2])

        if base_library.get_time_tick() < timetick + DEPTH_EXPIRE_DATA_TIME:
            return server_data.server_api_result(True,
                                                 data={
                                                     'timetick': timetick,
                                                     'bid': bid_list,
                                                     'ask': ask_list,
                                                 })

    depth_result = exchange_api.exchange.update_depth(pair_name)

    if not depth_result:
        return server_data.server_api_result(False, 'No Data')

    return server_data.server_api_result(True, data=depth_result)
示例#4
0
    def is_exist_k_line_data(pair_name, time_tick, time_interval):
        result = sql_module.query_data('SELECT * FROM history_market WHERE pair = "%s" and timetick = %s and timeinterval = "%s"' % \
                                       (pair_name,time_tick,time_interval))

        if result:
            return True

        return False
示例#5
0
def get_uid_by_user_name(user_name):
    result = sql_module.query_data(
        'SELECT uid FROM user_info WHERE name="%s"' % user_name)

    if result:
        return server_data.server_api_result(True, data=result[0][0])

    return server_data.server_api_result(False, 'Not Found')
示例#6
0
def is_exist_user(user_name):
    result = sql_module.query_data('SELECT * FROM user_info WHERE name="%s"' %
                                   user_name)

    if result:
        return server_data.server_api_result(True)

    return server_data.server_api_result(False, 'Not Found User')
示例#7
0
    def is_exist_coin_pair(pair_name):
        result = sql_module.query_data(
            'SELECT * FROM market WHERE pair = "%s" ' % (pair_name))

        if result:
            return True

        return False
示例#8
0
def is_active_user(user_name):
    result = sql_module.query_data(
        'SELECT active FROM user_info WHERE name="%s"' % user_name)

    if result:
        if result[0][0] == 1:
            return server_data.server_api_result(True)

    return server_data.server_api_result(False, 'This User was not Active')
示例#9
0
    def get_coin_amount(uid, coin_name):
        coin_name = 'coin_%s' % coin_name
        result = sql_module.query_data(
            'select %s from user_coin where uid = "%d"' % (coin_name, uid))

        if len(result):
            return result[0]

        return False
示例#10
0
def get_last_blockchain_transation(coin_name):
    result = sql_module.query_data(
        'SELECT address,tx,timetick FROM history_transation WHERE coin = "%s" ORDER BY timetick LIMIT 1'
        % coin_name)

    if len(result):
        return (result[0][0], result[0][1], int(result[0][2]))

    return False
示例#11
0
def get_user_coin(uid):
    result = sql_module.query_data(
        'SELECT * FROM user_address WHERE uid = %s' % uid)

    if result:
        result = []

        return server_data.server_api_result(True, data=result)

    return server_data.server_api_result(False, 'Not Found')
示例#12
0
def is_not_expier_valid_code_time(user_name):
    result = sql_module.query_data(
        'SELECT valid_code_make_time FROM user_info WHERE name="%s"' %
        user_name)

    if result:
        if base_library.get_time_tick(
        ) <= result[0][0] + VALID_CODE_EXPIER_TIME:
            return server_data.server_api_result(True)

    return server_data.server_api_result(False, 'Valid Code Expire')
示例#13
0
def get_user_balance(uid, coin_name):
    coin_name = coin_name.lower()
    result = sql_module.query_data(
        'SELECT %s FROM user_coin WHERE uid = "%s"' % (coin_name, uid))

    if not len(result):
        return server_data.server_api_result(False, 'No Data')

    if len(result):
        return server_data.server_api_result(True, data=float(result[0][0]))

    return server_data.server_api_result(False, 'Not Found')
示例#14
0
def get_user_withdraw_address(uid, coin_name):
    coin_name = coin_name.lower()

    if 'btc' == coin_name:
        result = sql_module.query_data(
            'SELECT bind_btc_address FROM user_address WHERE uid = "%s" LIMIT 1'
            % uid)
    elif 'eth' == coin_name:
        result = sql_module.query_data(
            'SELECT bind_eth_address FROM user_address WHERE uid = "%s" LIMIT 1'
            % uid)
    elif 'usdt' == coin_name:
        result = sql_module.query_data(
            'SELECT bind_usdt_address FROM user_address WHERE uid = "%s" LIMIT 1'
            % uid)
    else:
        return server_data.server_api_result(False, 'UnSupport Coin')

    if len(result):
        return server_data.server_api_result(True, data=result[0][0])

    return server_data.server_api_result(False, 'No Bind')
示例#15
0
    def is_support_exchange_coin(coin_name):
        result = sql_module.query_data(
            'select COLUMN_NAME from information_schema.COLUMNS where table_name = "user_coin"'
        )
        coin_name = 'coin_%s' % coin_name

        if len(result):
            if len(result[0]):
                for index in result[0]:
                    if coin_name == index:
                        return True

        return False
示例#16
0
def query_user_by_withdraw_address(coin_name, address):
    coin_name = coin_name.lower()

    if 'btc' == coin_name:
        result = sql_module.query_data(
            'SELECT uid FROM user_address WHERE bind_btc_address = "%s" LIMIT 1'
            % address)
    elif 'eth' == coin_name:
        result = sql_module.query_data(
            'SELECT uid FROM user_address WHERE bind_eth_address = "%s" LIMIT 1'
            % address)
    elif 'usdt' == coin_name:
        result = sql_module.query_data(
            'SELECT uid FROM user_address WHERE bind_usdt_address = "%s" LIMIT 1'
            % address)
    else:
        return server_data.server_api_result(False, 'UnSupport Coin')

    if len(result):
        return server_data.server_api_result(True, data=result[0][0])

    return server_data.server_api_result(False, 'Not Found')
示例#17
0
def get_transation(coin_name, address):
    result = sql_module.query_data(
        'SELECT tx,timetick FROM history_transation WHERE coin = "%s" And address = "%s"'
        % (coin_name, address))

    if len(result):
        output_result = []

        for index in result:
            output_result.append((index[0], int(index[1])))

        return result

    return False
示例#18
0
def get_real_time_deal_record(pair_name):
    result = sql_module.query_data(
        'SELECT price,amount,timetick FROM history_exchange WHERE pair = "%s" ORDER BY timetick LIMIT 60'
        % pair_name)

    if not result:
        return server_data.server_api_result(False, 'No Data')

    format_result = []

    for index in result:
        format_result.append((float(index[0]), float(index[1]), int(index[2])))

    return server_data.server_api_result(True, data=format_result)
示例#19
0
def check_valid_code(user_name, valid_code):
    if not is_legal_user_name(user_name):
        return server_data.server_api_result(False, 'Is illegal User Name')

    if not is_not_expier_valid_code_time(user_name).get_status():
        return server_data.server_api_result(False, 'Valid Code Expire')

    result = sql_module.query_data(
        'SELECT valid_code FROM user_info WHERE name="%s"' % user_name)

    if result:
        if result[0][0] == valid_code:
            return server_data.server_api_result(True)

    return server_data.server_api_result(False, 'Valid Code Error')
示例#20
0
def login(user_name, user_password):
    if not is_legal_user_name(user_name):
        return server_data.server_api_result(False, 'Is illegal User Name')

    if not is_active_user(user_name).get_status():
        return server_data.server_api_result(False, 'User has not Regedit')

    result = sql_module.query_data(
        'SELECT password FROM user_info WHERE name = "%s"' % user_name)

    if result:
        if result[0][0] == user_password:
            return server_data.server_api_result(True)

    return server_data.server_api_result(False, 'User or Password incorrect')
示例#21
0
def get_coin_info(pair_name):
    result = sql_module.query_data('SELECT * FROM market WHERE pair = "%s"' %
                                   pair_name)

    if not result:
        return server_data.server_api_result(False, 'No Data')

    result = {
        'pair': result[0][0],
        'price': str(result[0][1]),
        'amount': str(result[0][2]),
        'increase': str(result[0][3]),
        'open': str(result[0][4]),
    }

    return server_data.server_api_result(True, data=result)
示例#22
0
    def update_all_coin(self):
        symbols_list = self.get_all_coin()

        for pair_name in symbols_list:
            data = self.fetch_ticker(pair_name)
            try:
                amount = data['info']['vol']
                price = data['info']['sell']
            except:
                pass

            if base_api.is_exist_coin_pair(pair_name):
                #print 'Update Coin Data:',pair_name

                now_time = time.localtime()

                if 0 == now_time.tm_hour and 0 == now_time.tm_min and 0 == now_time.tm_sec:
                    sql_module.insert_data('UPDATE market SET price = %s , open = %s , amount = %s , increase = 0 WHERE pair = "%s"' % \
                                           (price,amount,pair_name))
                else:
                    result = sql_module.query_data(
                        'SELECT open FROM market WHERE pair = "%s" ' %
                        (pair_name))

                    if result:
                        open_price = float(result[0][0])
                        now_price = float(price)

                        if float(price) >= open_price:
                            increase = (now_price - open_price) / open_price
                        else:
                            increase = (open_price - now_price) / open_price

                        sql_module.insert_data('UPDATE market SET price = %s , amount = %s , increase = %.3f WHERE pair = "%s"' % \
                                               (price,amount,increase,pair_name))

            else:
                #print 'Add New Coin Data:',pair_name

                sql_module.insert_data('INSERT INTO market(pair,price,open,amount,increase) VALUES ("%s",%s,%s,%s,0)' % \
                                       (pair_name,price,price,amount))

            self.fill_k_line_data(pair_name)
示例#23
0
def get_rank():
    result = sql_module.query_data(
        'SELECT * FROM market ORDER BY increase DESC')

    if not result:
        return server_data.server_api_result(False, 'No Data')

    output_result = []

    for index in result:
        #simple_k_line_data = get_simple_k_line(index[0])

        output_result.append({
            'name': index[0],
            'price': str(index[1]),
            'amount': str(index[2]),
            'increase': str(index[3]),
            #'simple_k_line' : simple_k_line_data.get_data()
        })

    return server_data.server_api_result(True, data=output_result)
示例#24
0
def get_coin_list():
    result = sql_module.query_data(
        'SELECT column_name FROM information_schema.columns WHERE table_schema = "backend" And table_name = "user_coin"'
    )

    return result[0]