Exemplo n.º 1
0
def make_new_valid_code(user_name):
    valid_code = base_library.make_random_code()

    sql_module.insert_data('UPDATE user_info SET valid_code = "%s" , valid_code_make_time = %s WHERE name = "%s"' % \
                           (valid_code,base_library.get_time_tick(),user_name))

    return valid_code
Exemplo n.º 2
0
def order_sell(uid, pair_name, amount, price):
    symbols_list = exchange_api.exchange.get_all_coin()

    if not pair_name in symbols_list:
        return server_data.server_api_result(False, 'Not Found Symbols')

    base_coin = pair_name.split('/')[0]

    if not exchange_api.base_api.is_support_exchange_coin(
            base_coin) or not exchange_api.base_api.is_exist_coin_pair(
                pair_name):
        return server_data.server_api_result(False,
                                             'Internal Exchange UnSupport')

    coin_amount = exchange_api.base_api.get_coin_amount(base_coin)

    if amount > coin_amount:
        return server_data.server_api_result(False, 'User Coin Amount Less')

    order_id = exchange_api.exchange.order_sell(pair_name, amount, price)

    if not order_id:
        return server_data.server_api_result(False, 'Make Order Except')

    poundage = amount * price * BUY_SELL_POUNDAGE_RATE

    sql_module.insert_data(
        'INSERT INTO history_exchange(uid,pair,amount,price,poundage,timetick) VALUES (%s,"%s","","%s",%s,%s)'
        % (uid, pair_name, amount, price, poundage,
           base_library.get_time_tick()))

    return server_data.server_api_result(True)
Exemplo n.º 3
0
    def update_depth(self, pair_name):
        data = self.get_depth(pair_name)

        if not data:
            return False

        #print 'update_depth()  Add New Coin Depth:',pair_name

        sql_module.insert_data('INSERT INTO history_depth(pair,timetick,bid,ask) VALUES ("%s",%s,"%s","%s")' % \
                               (pair_name,data['timetick'],str(data['bid']),str(data['ask'])))

        return data
Exemplo n.º 4
0
def make_new_user(user_name):
    if not is_legal_user_name(user_name):
        return server_data.server_api_result(False, 'Is illegal User Name')

    valid_code = None

    if not is_exist_user(user_name).get_status():
        valid_code = base_library.make_random_code()

        sql_module.insert_data('INSERT INTO user_info(name,password,valid_code,valid_code_make_time) VALUES ("%s","","%s",%s)' % \
                               (user_name,valid_code,base_library.get_time_tick()))
    else:
        valid_code = make_new_valid_code(user_name)

    #email_api.send_valid_code_email(user_name,valid_code)

    return valid_code
Exemplo n.º 5
0
    def fill_k_line_data(self, pair_name='BTC/USDT', time_interval='1m'):
        k_line_data = self.get_k_line_data(pair_name, time_interval)

        if not k_line_data:
            return

        last_k_line_data = k_line_data[-1]

        for index in k_line_data:
            if base_api.is_exist_k_line_data(pair_name, index['time'],
                                             time_interval):
                continue

            #print 'Add New K-Line Data:',index

            sql_module.insert_data('INSERT INTO history_market(pair,open,close,max,min,timetick,amount,timeinterval) VALUES ("%s",%s,%s,%s,%s,%s,%s,"%s")' % \
                                   (pair_name,index['open'],index['close'],index['max'],index['min'],index['time'],index['amount'],time_interval))
Exemplo n.º 6
0
def init_user(user_name, user_password):
    uid_data = get_uid_by_user_name(user_name)

    if not uid_data.get_status():
        return server_data.server_api_result(False, uid_data.get_description())

    sql_module.insert_data('UPDATE user_info SET password = "******" , active = 1 WHERE name = "%s"' % \
                           (user_password,user_name))

    uid = uid_data.get_data()

    sql_module.insert_data(
        'INSERT INTO user_address(uid,bind_btc_address,bind_eth_address,bind_usdt_address) VALUES (%s)'
        % (uid))
    sql_module.insert_data('INSERT INTO user_coin(uid) VALUES (%s)' % (uid))

    return server_data.server_api_result(True)
Exemplo n.º 7
0
def set_user_withdraw_address(uid, coin_name, address):
    coin_name = coin_name.lower()

    if 'btc' == coin_name:
        sql_module.insert_data(
            'UPDATE user_address SET bind_btc_address = "%s" WHERE uid = "%s"'
            % (address, uid))
    elif 'eth' == coin_name:
        sql_module.insert_data(
            'UPDATE user_address SET bind_eth_address = "%s" WHERE uid = "%s"'
            % (address, uid))
    elif 'usdt' == coin_name:
        sql_module.insert_data(
            'UPDATE user_address SET bind_usdt_address = "%s" WHERE uid = "%s"'
            % (address, uid))
    else:
        return server_data.server_api_result(False, 'UnSupport Coin')

    return server_data.server_api_result(True)
Exemplo n.º 8
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)
Exemplo n.º 9
0
def add_blockchain_transation(coin_name, address, tx, timetick):
    sql_module.insert_data(
        'INSERT INTO history_transation(coin,address,tx,timetick) VALUES ("%s","%d","%s",%s)'
        % (coin_name, address, tx, timetick))