iqfeed/dtn下载数据
iqfeed的Python项目详细描述
这个项目提供命令行工具和python库来访问dtn /iqfeed的股票历史数据。提供的命令行工具 (“iqfeed”)能够从iqfeed下载1分钟的历史数据 客户端并以.csv.gz格式存储。
先决条件
- python 2.7(建议使用pypy),docopt,pytz, backports.functools_lru_缓存
- iqfeed帐户
- iqfeed客户端(例如bratchenko’s ‘iqfeed-docker’)
安装
$ pip install iqfeed
从命令行使用
提供的iqfeed实用程序可用于从 DTN/IQFEED。
帮助屏幕:
iqfeed: Data downloader for Iqfeed/DTN Tibor Kiss <tibor.kiss@gmail.com> - Copyright (c) 2012-2016 All rights reserved Usage: iqfeed process-file <filename> <start_year> <end_year> [-d DIR] [-i CON] [-t TZ] [-D] iqfeed download <instrument> <start_year> <end_year> [-d DIR] [-i CON] [-t TZ] [-D] iqfeed -h | --help Commands: download Download the specified instrument get-from-file Download instruments listed in the specified file Options: -d DIR --download-dir DIR Directory where the files will be downloaded [default: .] -i CON --iqfeed CON IQFeed host & port [default: localhost:9100] -t TZ --tz TZ Time zone [default: US/Eastern] -D Debug mode -h Help screen Note: Date format for end_date and start_date: YYYYMMDD
启动iqfeed客户端
$ docker run -eLOGIN='<username>'-ePASSWORD='<password>'-p 5009:5010 -p 9100:9101 bratchenko/iqfeed
下载2010-2016年期间的单一仪器(Spy)
$ iqfeed download SPY 2010 2016
下载文本文件中列出的多个仪器
$ iqfeed process-filerussell-3000.lst 2016 2016
来自python的用法
使用以下代码段获取bar对象的列表。
importpytzfromiqfeedimportget_barsinstrument='GLD'start_date='20150101'end_date='20151231'tz=pytz.timezone('US/Eastern')seconds_per_bar=60# For 1M dataiqfeed_host='localhost'iqfeed_port=9100bars=get_bars(instrument,start_date,end_date,tz,seconds_per_bar,iqfeed_host,iqfeed_port)
bar对象是一个命名元组,它包含open、high、low、close 以及给定时间的音量值:
IQFeedBar(datetime=datetime.datetime(2015,1,2,9,30,tzinfo=<DstTzInfo'US/Eastern'EST-1day,19:00:00STD>),open=112.46,high=112.46,low=112.45,close=112.46,volume=192104)