700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【Python】通过新浪财经接口获取实时价格卖一买一价格

【Python】通过新浪财经接口获取实时价格卖一买一价格

时间:2019-11-17 08:57:21

相关推荐

【Python】通过新浪财经接口获取实时价格卖一买一价格

import reimport requests# 买一价def get_buy_one_price(str_ticker):""":param item传入需要股票代码,形式为 item = 'sz600030'"""# 发送请求price_all = requests.get('/list=' + str_ticker).textprice_ticker = re.findall(r'var hq_str_(.*?);', price_all)price_tick = price_ticker[0].split(',') # 实时股价的list# 买一价,其实是第11个,除掉第一个'sz002463="沪电股份'后,就是第10个了buy_one_price = price_tick[11]# b_p bid price 买# b_v bid volume 买的数量# a_p ask price卖# a_v ask volume 卖的数量# 返回的结果代表的意思'''0 今开,1 昨收,2 实时价格,3 今日最高,4 今日最低,5 竞买价,即“买一”报价;6 竞卖价,即“卖一”报价;7 成交数量8 成交金额9 买一数量10 买一价格后续依次 买二数量,买二价格....到买五数量,买五价格然后卖一数量,卖一价格....卖五数量,卖五价格''''''columns=['open', 'pre_close', 'price', 'high', 'low','bid', 'ask', 'volume', 'amount', 'b1_v', 'b1_p','b2_v', 'b2_p', 'b3_v', 'b3_p', 'b4_v', 'b4_p','b5_v', 'b5_p', 'a1_v', 'a1_p', 'a2_v', 'a2_p','a3_v', 'a3_p', 'a4_v', 'a4_p', 'a5_v', 'a5_p']'''return buy_one_price# 卖一价def get_sell_one_price(str_ticker):""":param item传入需要股票代码,形式为 item = 'sz600030'"""# 发送请求price_all = requests.get('/list=' + str_ticker).textprice_ticker = re.findall(r'var hq_str_(.*?);', price_all)price_tick = price_ticker[0].split(',') # 实时股价的listsell_one_price = price_tick[21] # 20+1 买一价return sell_one_price# 实时价格def get_realtime_price(str_ticker):""":param item传入需要股票代码,形式为 item = 'sz600030'"""# 发送请求price_all = requests.get('/list=' + str_ticker).textprint(price_all)price_ticker = re.findall(r'var hq_str_(.*?);', price_all)print(price_ticker)price_tick = price_ticker[0].split(',') # 实时股价的listrealtime_price = price_tick[3] # 实时股价的listreturn realtime_priceif __name__ == "__main__":xx = 'sz002463'yy = get_realtime_price(xx)print(yy)zz = get_sell_one_price(xx)print(zz)hh = get_buy_one_price(xx)print(hh)

新浪财经返回的结果,可以对比新浪财经

具体股票的页面,

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。