bitx.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:bitrader 作者: jr-minnaar 项目源码 文件源码
def api_request(self, call, params, kind='auth', http_call='get'):
        """
        General API request. Generally, use the convenience functions below
        :param kind: the type of request to make. 'auth' makes an authenticated call; 'basic' is unauthenticated
        :param call: the API call to make
        :param params: a dict of query parameters
        :return: a json response, a BitXAPIError is thrown if the api returns with an error
        """
        url = self.construct_url(call)
        auth = self.auth if kind == 'auth' else None
        if http_call == 'get':
            response = requests.get(url, params, headers=self.headers, auth=auth)
        elif http_call == 'post':
            response = requests.post(url, data = params, headers=self.headers, auth=auth)
        else:
            raise ValueError('Invalid http_call parameter')
        try:
            result = response.json()
        except ValueError:
            result = {'error': 'No JSON content returned'}
        if response.status_code != 200 or 'error' in result:
            raise BitXAPIError(response)
        else:
            return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号