使用Python获取股票数据的API接口教程

(一)获取当前 K线 对应时间的时间戳函数ContextInfo.get_ bar_timetag()

用法: ContextInfo.get_bar_timetag (index)。

释义:获取当前K线对应时间的时间戳。

参数:number:K线索引号。

返回:number。

示例:

def handlebar(ContextInfo):
  index = ContextInfo.barpos
  print(ContextInfo.get_bar_timetag (index))

(二)获取指数成份股函数 ContextInfo.get_ sector()

用法:ContextInfo.get_ sector(sector, realtime)。

释义:获取板块成份股,只支持取指数成份股。

参数:

string:必须是’stock.market’形式,如 ‘000300.SH’可取如沪深300(000300.SH)、中

证500(000905.SH)、上证 50(000016.SH) 等指数的历史成份股。

realtime:亳秒级时间戳。

返回:list:内含成份股代码,里面股票代码为 ‘000002.SZ’形式。

示例:

def handlebar (ContextInfo):
  index = ContextInfo.barpos
  realtime = ContextInto.get_bar_timetag(index)
  print(ContextInfo.get_sector ('000300.SH', realtime))

(三) 获取合约乘数 ContextInfo.get_contract_multiplier()

用法:ContextInfo.get_contract_multiplier(contractcode)。

释义:获取合约乘数。

参数:string:合约代码,形式如‘code.market’,如 ‘IF1707.IF’

返回:number。

示例:

def handlebar (ContextInfo):
  print (ContextInfo.get_contract_multiplier('IF1707.IF'))

(四)获取财务数据 ContextInfo.get_ financial_data( )

用法:ContextInfo.get_financial_data(tabname, colname, market, code, barpos)。

释义:获取财务数据。

参数:

tabname:表格名称。

colname:字段名称。

market:市场。

code: 股票代码。

barpos: 当前 bar 的索引。

返回:number。

示例:

def handlebar (ContextInfo);
  index = ContextInfo.barpos    ContextInfo.get_financial_data('ASHAREINCOME','net_profit_incl_ min_int_inc 'SH','600000', index)

(五)获取历史行情数据 ContextInfo.get_history _ data()

用法:ContextInfo.get_history_data(len, period,field ,dividend _type = 0,skip_paused = TRUE)

释义:获取历史行情数据。

注意:必领先通过 ContexInfo.set _universe(),设定基础股票池,获取历史行情数据是获取的是股票池中的历史行情数据。

参数:

len:number,需获取的历史数据长度。

period: string,需获取的历史数据的周期。

field:string,需获取的历史数据的类型。

dividend_type: 默认参数,number,除复权,默认不复权,可选值:0(不复权);1(向前复

权);2(向后复权);3(等比向前复板);4(等比向后复权)。

skip_paused:默认参数,bool,是否停牌填充,默认填充。

注意:可缺省参数:dividend_type, skip_ paused.

返回:一个字典 dict 结构,ley 为stockcode.market, value 为行情数据 list,list 中第

0位为最早的价格,第1位为次早价格,依次下去。

有误之处请理解

物联沃分享整理
物联沃-IOTWORD物联网 » 使用Python获取股票数据的API接口教程

发表评论