コード例 #1
0
        def wrapper():
            try:
                validate_params(expected_params)

                params = request.args.to_dict()
                params['timestamp'] = utils.get_timestamp(
                    request.args.to_dict())

                logger.debug('Params: {}'.format(params))
                result = func(params)
                logger.debug('Output: {}'.format(result))

                return jsonify({
                    'success': True,
                    'message': '',
                    'result': result
                })
            except Exception as e:
                # traceback.print_exc()
                logger.error(e)
                return jsonify({
                    'success': False,
                    'message': str(e),
                    'result': None
                })
コード例 #2
0
def trading_api():
    try:
        api_key = request.headers.get('Key')
        if not api_key:
            raise ValueError('Key is missing ')

        params = request.args.to_dict()
        params['api_key'] = api_key
        command = params.get('command')
        params['timestamp'] = utils.get_timestamp(request.args.to_dict())

        if command == 'returnBalances':
            output = poloniex.get_balance_api(**params)
        elif command == 'returnDepositsWithdrawals':
            output = poloniex.get_history_api(**params)
        elif command == 'returnOpenOrders':
            output = poloniex.get_open_orders_api(**params)
        elif command == 'sell' or command == 'buy':
            params['type'] = command
            output = poloniex.trade_api(**params)
        elif command == 'cancelOrder':
            output = poloniex.cancel_order_api(**params)
        elif command == 'withdraw':
            output = poloniex.withdraw_api(**params)
        else:
            return jsonify(
                {'error': 'command {} is not supported'.format(command)})
        return jsonify(output)
    except Exception as e:
        # traceback.print_exc()
        logger.error(e)
        return jsonify({'error': str(e)})
コード例 #3
0
def depth(pairs):
    timestamp = utils.get_timestamp(request.args.to_dict())
    try:
        depth = liqui.get_depth_api(pairs, timestamp)
        return jsonify(depth)
    except Exception as e:
        return jsonify({'success': 0, 'error': str(e)})
コード例 #4
0
        def wrapper():
            error = validate_params(expected_params)
            if error:
                return str(error)

            params = request.args.to_dict()
            logger.debug('Original params: {}'.format(params))
            if not public:
                api_key = request.headers.get('X-MBX-APIKEY')
                if not api_key:
                    return str(MISSING_ERROR['api_key'])
                else:
                    params['api_key'] = api_key.lower()

            params['timestamp'] = utils.get_timestamp(request.args.to_dict())

            logger.debug('Params: {}'.format(params))
            try:
                result = func(params)
            except Exception as e:
                # traceback.print_exc()
                logger.error('Error Output: {}'.format(str(e)))
                return jsonify({'code': -1, 'msg': str(e)})

            logger.debug('Output: {}'.format(result))

            return jsonify(result)
コード例 #5
0
def public():
    params = request.args.to_dict()
    command = params.get('command')
    if command == 'returnOrderBook':
        params['timestamp'] = utils.get_timestamp()
        try:
            ob = poloniex.order_book_api(**params)
            return jsonify(ob)
        except Exception as e:
            logger.error(e)
            return jsonify({'error': str(e)})
    else:
        return jsonify(
            {'error': 'command {} is not supported'.format(command)})
コード例 #6
0
        def wrapper():
            error = validate_params(expected_params)
            if error:
                return str(error)

            params = request.form.to_dict()

            api_key = request.headers.get('X-BFX-APIKEY')
            if not api_key:
                return str(MISSING_ERROR['api_key'])
            params['api_key'] = api_key.lower()

            params['timestamp'] = utils.get_timestamp(request.args.to_dict())

            logger.info('Params: {}'.format(params))
            try:
                result = func(params)
                logger.info('Output: {}'.format(result))
                return jsonify(result)
            except Exception as e:
                logger.error(e)
                return jsonify({'message': str(e)})
コード例 #7
0
def index():
    try:
        api_key = request.headers.get('Key')
        if not api_key:
            raise AttributeError("Missing 'Key' Header")

        params = request.form.to_dict()
        params['api_key'] = api_key.lower()

        method = params.get('method')
        if not method:
            raise KeyError('Method is missing in your request')

        params['timestamp'] = utils.get_timestamp(request.args.to_dict())

        logger.debug('Params: {}'.format(params))

        if method == 'getInfo':
            output = liqui.get_balance_api(**params)
        elif method == 'Trade':
            output = liqui.trade_api(**params)
        elif method == 'WithdrawCoin':
            output = liqui.withdraw_api(**params)
        elif method == 'OrderInfo':
            output = liqui.get_order_api(**params)
        elif method == 'ActiveOrders':
            output = liqui.get_active_orders_api(**params)
        elif method == 'CancelOrder':
            output = liqui.cancel_order_api(**params)
        else:
            raise AttributeError('Invalid method requested')

        logger.debug('Output: {}'.format(output))
        return jsonify({'success': 1, 'return': output})
    except Exception as e:
        # traceback.print_exc()
        logger.debug('Error Output: {}'.format(e))
        return jsonify({'success': 0, 'error': str(e)})
コード例 #8
0
def order_book(symbol):
    timestamp = utils.get_timestamp(request.args.to_dict())
    try:
        return jsonify(bitfinex.order_book_api(symbol, timestamp))
    except Exception as e:
        return jsonify({'message': str(e)})