Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- from bs4 import BeautifulSoup
- import datetime
- from pandas import DataFrame
- symbol = "BTC"
- interval = "day"
- int2type = {
- "day": "24H",
- "hour12": "12H",
- "hour6": "06H",
- "hour": "01H",
- "minute30": "30M",
- "minute10": "10M",
- "minute5": "05M",
- "minute3": "03M",
- }
- url = "https://m.bithumb.com/trade/chart/{}".format(symbol)
- resp = requests.get(url)
- html = resp.text
- # parsing coin type
- string = html.split("COIN = ")[1].split(";")[0]
- coin = json.loads(string)
- tk2ct = {v['symbol_name']: k for k, v in coin['C0100'].items()}
- # parsing xcoin name
- selector = "#barcodeForm > input[type=hidden]:nth-child(2)"
- soup = BeautifulSoup(html, 'html5lib')
- xcoin_name = soup.select(selector)[0]['value']
- url = "https://m.bithumb.com/trade_history/chart_data"
- headers = {
- "cookie": 'csrf_xcoin_name={}'.format(xcoin_name),
- "x-requested-with": "XMLHttpRequest"
- }
- data = {
- "coinType": tk2ct[symbol],
- "crncCd": "C0100",
- "tickType": int2type[interval],
- "csrf_xcoin_name": xcoin_name
- }
- resp = requests.post(url, data=data, headers=headers).json()
- for x in resp['data']:
- x[0] = datetime.datetime.fromtimestamp(x[0] / 1000)
- columns = [symbol, 'open', 'close', 'high', 'low', 'volume']
- df = DataFrame(resp['data'], columns=columns)
- df = df.set_index(symbol)
- print(df.head())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement