从网络获取股票K线数据---Python

import pandas
from datetime import date, time, datetime, timedelta
import numpy
import matplotlib.pyplot as pp
import mpl_finance as mpl
import pandas_datareader.data as web
import tushare as ts
import tool
x=pp.figure(figsize = (12,8))
ax=x.add_subplot(1,1,1)
begin_time='20190101'
end_time='20190201'
index = pandas.date_range(begin_time, end_time, freq='D')
columns = ['open', 'close', 'high', 'low']

#从股市获取数据
token=tool.get_stock_stoken()
d=ts.pro_api(token)
x=d.daily(ts_code='002557.SZ',start_date=begin_time,end_date=end_time,fields='open,high,low,trade_date,close,change,pct_change')
#x=web.DataReader('000001.SS','google',begin_time,end_time)
print(x)
open=x['open']
close=x['close']
high=x['high']
low=x['low']
mpl.candlestick2_ochl(ax,open,close,high,low,width=0.5,colorup='r',colordown='b')
ax.set_xlim(1,index.__len__())
ax.set_xticks(numpy.arange(0,index.__len__(),1))
ax.set_xticklabels(index.strftime('%m-%d'),rotation=45)
ax.set_xlabel('date',fontsize=10)
ax.set_ylabel('price',fontsize=10)
pp.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

geniusNMRobot引流专家

你最少得给我一个亿

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值