Esempio n. 1
0
def otc_accept_quote(quote_id):
    url = "/api/{0}/accept/{1}".format(get_otc_api_version(), quote_id)
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url)
    ret = {}
    try:
        resp = requests.post(get_otc_full_url(env["API_HOST"], url),
                             headers=headers)
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp.json()
    return ret
Esempio n. 2
0
def earn_get_orders():
    url = "/api/{0}/invest/orders".format(get_spot_api_version())
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url)
    ret = {}
    try:
        resp = requests.get(get_spot_full_url(env["API_HOST"], url),
                            headers=headers)
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp.json()
    return ret
Esempio n. 3
0
def spot_place_limit_order(data):
    url = "/api/{0}/order".format(get_spot_api_version())
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url,
                          json.dumps(data))
    ret = {}
    try:
        resp = requests.post(get_spot_full_url(env["API_HOST"], url),
                             json=data,
                             headers=headers)
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp.json()
    return ret
Esempio n. 4
0
def on_open(ws):
    # OPTIONAL: login with auth to get quote
    url = "/ws/otc"
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url)
    payload = {
        "op": "authKeyExpires",
        "args": [
            headers["btse-api"],
            headers["btse-nonce"],
            headers["btse-sign"],
        ],
    }
    ws.send(json.dumps(payload))

    # subscribe to otc streaming quote
    _subscribe_topic(ws, "BTC-USD", 1, "USD", "order1")
    _subscribe_topic(ws, "BTC-USD", 2, "USD", "order2")
    _subscribe_topic(ws, "BTC-USD", 3, "USD", "order3")
Esempio n. 5
0
def futures_change_settlement_currency(data):
    url = "/api/{0}/settle_in".format(get_futures_api_version())
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url,
                          json.dumps(data))
    ret = {}
    try:
        resp = requests.post(
            get_futures_full_url(env["API_HOST"], url),
            json=data,
            headers=headers,
        )
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp
    return ret
def spot_get_wallet_address(currency):
    url = "/api/{0}/user/wallet/address".format(get_spot_api_version())
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url)
    ret = {}
    params = {"currency": currency}
    try:
        resp = requests.get(
            get_spot_full_url(env["API_HOST"], url),
            params=params,
            headers=headers,
        )
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp.json()
    return ret
Esempio n. 7
0
def earn_get_history(page_number=1, page_size=10):
    url = "/api/{0}/invest/history".format(get_spot_api_version())
    env = get_env_info()
    headers = gen_headers(env["API_KEY"], env["API_SECRET_KEY"], url)
    params = {
        "pageNumber": page_number,
        "pageSize": page_size,
    }
    ret = {}
    try:
        # page_number is 1-based
        resp = requests.get(
            get_spot_full_url(env["API_HOST"], url),
            params=params,
            headers=headers,
        )
        resp.raise_for_status()
    except HTTPError as http_err:
        print("HTTP error occurred: {0}".format(http_err))
    except Exception as err:
        print("Other error occurred: {0}".format(err))
    else:
        ret = resp.json()
    return ret
Esempio n. 8
0
class Handler(BaseHandler):
    crawl_config = {
        'headers': gen_headers(),
    }

    @every(minutes=24 * 60)
    def on_start(self):
        self.crawl(f'https://www.douban.com/group/{target_group_id}/members',
                   callback=self.index_page)

    @config(age=10 * 24 * 60 * 60)
    def index_page(self, response):
        current_page = int(
            response.url.replace(
                '#more',
                '').split('start=')[-1]) if 'start=' in response.url else 0
        next_page_urls = []
        for each in response.doc('a[href^="http"]').items():
            if 'members?start=' in each.attr.href:
                next_page_urls.append(each.attr.href)
                continue
            if '/people/' in each.attr.href:
                member_id = each.attr.href.split('/people/')[-1]
                url = 'https://www.douban.com/j/contact/addtoblacklist'
                data = {'people': member_id, 'ck': cookies.get('ck')}
                if not member_id.startswith('1'):
                    continue
                headers = {
                    'Connection':
                    'keep-alive',
                    'Accept':
                    'application/json, text/javascript, */*; q=0.01',
                    'Sec-Fetch-Dest':
                    'empty',
                    'X-Requested-With':
                    'XMLHttpRequest',
                    'User-Agent':
                    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
                    'Content-Type':
                    'application/x-www-form-urlencoded',
                    'Origin':
                    'https://www.douban.com',
                    'Sec-Fetch-Site':
                    'same-origin',
                    'Sec-Fetch-Mode':
                    'cors',
                    'Referer':
                    'https://www.douban.com/people/87926379/',
                    'Accept-Language':
                    'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6',
                }
                headers['Referer'] = each.attr.href
                ck = response.cookies

                print(response.cookies)
                resp = requests.post(url,
                                     data=data,
                                     cookies=ck,
                                     headers=headers).json()
                print(resp)
                # self.crawl(url, data=data, cookies=response.cookies, callback=self.detail_page, headers=headers, method="POST")
                continue

        next_page_start = min([
            int(i.replace('#more', '').split('?start=')[-1])
            for i in next_page_urls
            if int(i.replace('#more', '').split('?start=')[-1]) > current_page
        ])
        next_page_url = f'https://www.douban.com/group/{target_group_id}/members?start={next_page_start}'
        self.crawl(next_page_url, callback=self.index_page)

    @config(priority=2)
    def detail_page(self, response):
        return {
            "text": response.content,
            "title": response.doc('title').text(),
        }