hqchartPy2 data docking tutorial 5-reference specified stock data function

Effect picture

Insert picture description here
Insert picture description here

Quote specified stock data

Tongda letter $ operator

For example: "000014$CLOSE" means to take the closing price of 000014, pay attention to adding double quotes. You
can add SZ (Shenzhen), SH (Shanghai), or market_, "SZ000001$CLOSE" means Ping An Bank,"

example

Such as: draw a K-line chart of Ping An Bank

收盘价:"000001$CLOSE",NODRAW;
开盘价:"000001$OPEN",NODRAW;
最高价:"000001$HIGH",NODRAW;
最低价:"000001$LOW",NODRAW;

DRAWKLINE(最高价,开盘价,最低价,收盘价);

hqchart refers to the specified stock data function

CLOSE (variety code)/C (variety code)

Closing price

VOL (variety code)/V (variety code)

Volume

OPEN (variety code)/O (variety code)

Opening price

HIGH (variety code)/H (variety code)

Highest price

LOW (variety code)/L (variety code)

Lowest price

AMOUNT (variety code)/AMO (variety code)

Turnover

VOLINSTK (variety code)

Open interest (only available in futures)

example

Draw a line graph K PAB 
script:

收盘价:C("000001.SZ"),NODRAW;
开盘价:O("000001.SZ"),NODRAW;
最高价:H("000001.SZ"),NODRAW;
最低价:L("000001.SZ"),NODRAW;

DRAWKLINE(最高价,开盘价,最低价,收盘价);

Interface function format

 # 获取其他K线数据
 def GetKLineData2(self, symbol, period, right, callInfo, kdataInfo, jobID) :
 	pass

Parameter Description

symol

Stock code

period

Cycle
0=daily line 1=weekly line 2=monthly line 3=annual line 4=1 minute 5=5 minutes 6=15 minutes 7=30 minutes 8=60 minutes 9=seasonal line 10=minutes

right

Restoration
0=No restoration 1=Previous restoration 2=Post restoration

callInfo

Call function information '000001$CLOSE'

jobID

Task id

kdataInfo

Current k-line information dictionary type

Return data format

Return a dictionary type data

name

Stock name string

period

Periodic Numerical

right

Complex weighted value

yclose

Numerical array of previous closing prices

open

Open price numeric array

high

Highest price numeric array

low

Lowest price numeric array

close

Numerical array of closing prices

vol

Volume numeric array

amount

Turnover

Tushare data docking example

Use pro_bar data interface to get K-line data, see https://waditu.com/document/2?doc_id=146 for interface description

class TushareHQChartData(IHQData) :
	# 获取其他K线数据
    def GetKLineData2(self, symbol, period, right, callInfo, kdataInfo, jobID) :
        if (callInfo.find('$')>0) : #没有后缀的股票要加上后缀
            if (symbol.find(".")<=0) :
                if (symbol[:3]=='600' or symbol[:3]=="688") :
                    symbol+=".SH"
                elif (symbol[:3]=="000" or symbol[:2]=="30") :
                    symbol+=".SZ"

        return self.GetKLineAPIData(symbol, period, right, kdataInfo["StartDate"], kdataInfo["EndDate"])
        
    # 获取K线API数据
    def GetKLineAPIData(self, symbol, period, right, startDate, endDate) :
        # 复权 0=不复权 1=前复权 2=后复权
        fq=None # 复权
        if (right==1) : # 前复权
            fq="qfq"
        elif (right==2) :   # 后复权
            fq="hfq"

        # 周期 0=日线 1=周线 2=月线 3=年线 4=1分钟 5=5分钟 6=15分钟 7=30分钟 8=60分钟 9=季线 10=分笔
        freq='D'
        if (period==1) :
            freq="W"
        elif (period==2):
            freq="M"
        elif (period==4):
            freq="1MIN"
        elif (period==5):
            freq="5MIN"
        elif (period==6):
            freq="15MIN"
        elif (period==7):
            freq="30MIN"
        elif (period==8):
            freq="60MIN"

        try :
            print("[TushareHQChartData::GetKLineAPIData] ts.pro_bar(ts_code={0}, adj={1}, start_date={2}, end_date={3}, freq={4})".format(symbol, fq, startDate, endDate, freq))
            df = ts.pro_bar(ts_code=symbol, adj=fq, start_date=str(startDate), end_date=str(endDate),freq=freq)
            # df = self.TusharePro.daily(ts_code=symbol, start_date='20200101', end_date='20201231')
            
        except Exception as e:
            print('[TushareHQChartData::GetKLineAPIData] Error. throw exception {0},'.format(e))
            return {
    
     "error":str(e) }

        df=df.sort_index(ascending=False) # 数据要降序排
        print(df)

        cacheData={
    
    }
        if (period in (0,1,2,3,9)) :
            # 日期转int
            aryDate=df["trade_date"]
            aryDate[aryDate == ''] = 0
            aryDate = aryDate.astype(np.int)
            dataCount=len(aryDate) 
            cacheData['count']=dataCount    # 数据个数
            cacheData["date"]=aryDate.tolist()
        else :
            aryDateTime=df["trade_time"]
            dataCount=len(aryDateTime) 
            cacheData['count']=dataCount    # 数据个数
            aryDateTime= pd.to_datetime(aryDateTime, format="%Y-%m-%d %H:%M:%S")
            print(aryDateTime)
            aryDate=[]
            aryTime=[]
            for item in aryDateTime :
                aryDate.append(item.year*10000 + item.month* 100  + item.day)
                aryTime.append(item.hour*100+item.minute)
            cacheData["time"]=aryTime
            cacheData["date"]=aryDate

        
        cacheData['name']=symbol        # 股票名称
        cacheData['period']=period      # 周期
        cacheData['right']=right       # 不复权

        cacheData["yclose"]=np.array(df["pre_close"]).tolist()
        cacheData["open"]=np.array(df["open"]).tolist()
        cacheData["high"]=np.array(df["high"]).tolist()
        cacheData["low"]=np.array(df["low"]).tolist()
        cacheData["close"]=np.array(df["close"]).tolist()
        cacheData["vol"]=np.array(df["vol"]).tolist()
        cacheData["amount"]=np.array(df["amount"]).tolist()


        log="K线:{0} - period={1} right={2} count={3} date=[{4}, {5}]".format(symbol,period,right,dataCount, startDate, endDate)
        print(log)

        return cacheData

Exchange QQ group

If you have any questions or needs, you can join the exchange QQ group: 950092318** Contact the owner (QQ48274798)

hqchartPy dynamic library address

https://github.com/jones2000/HQChart/tree/master/C++ indicator calculation engine/py version

HQChart code address

Address: https://github.com/jones2000/HQChart

Personal hobbies (modeling/photography)

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/jones2000/article/details/112335307