Skip to content

Commit 2d001e3

Browse files
authored
Update hb_hq_api.py
1 parent c16ff05 commit 2d001e3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

hb_hq_api.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
#火币行情功能函数
1+
# HUOBI
22
import json,requests,urllib3,datetime; import pandas as pd; import numpy as np ; urllib3.disable_warnings()
33

4-
huobi_domain='api.huobi.de.com' #API地址 'api.huobi.pro' api.huobi.be没有被墙 api.huobi.de.com
4+
huobi_domain='api.huobi.pro'
55

6-
class Context: #根类
6+
class Context:
77
def __init__(self):
88
self.current_dt=datetime.datetime.now()
99

10-
# #1d:1天 4h:4小时 60m: 60分钟 15m:15分钟
10+
#1d:1DAT 4h:4HOUR 60m: 60MIN 15m:15MIN
1111
def get_price(code, end_date=None, count=1,frequency='1d', fields=['close']):
1212
code=code.replace('.','')
1313
frequency=frequency.replace('d','day').replace('m','min').replace('h','hour')
1414
url = f'https://{huobi_domain}/market/history/kline?period={frequency}&size={count}&symbol={code}'
1515
res = requests.get(url,verify=False).text
16-
df=pd.DataFrame(json.loads(res)['data']); df=df.iloc[::-1] #排序翻转
17-
df["time"] = pd.to_datetime(df["id"]+8*3600, unit='s') #时间戳转时间,北京时间+8小时
18-
df=df[['time','open','close','high','low','vol']] #更正排序
19-
df.set_index(["time"], inplace=True); df.index.name='' #处理索引
16+
df=pd.DataFrame(json.loads(res)['data']); df=df.iloc[::-1]
17+
df["time"] = pd.to_datetime(df["id"]+8*3600, unit='s')
18+
df=df[['time','open','close','high','low','vol']]
19+
df.set_index(["time"], inplace=True); df.index.name=''
2020
return df
2121

22-
def get_last_price(code): #获取某只股票最新价格函数04-25
22+
def get_last_price(code):
2323
return get_price(code,count=1,frequency='1m', fields=['close']).close[0]
2424

25-
def attribute_history(security, count, unit='1d', fields=['open', 'close', 'high', 'low', 'volume', 'money']): #获取历史行情
25+
def attribute_history(security, count, unit='1d', fields=['open', 'close', 'high', 'low', 'volume', 'money']):
2626
return get_price(security = security, end_date = context.current_dt, frequency=unit, fields=fields, fq = fq, count = count)[:-1]
2727

2828

0 commit comments

Comments
 (0)