activetick http代理的pandas包装器
activetick-http的Python项目详细描述
动态勾号http
连接到activetick http代理并提供pandas数据帧的python模块。 需要对quotestream和redis的请求才能进行缓存。
目前情况不稳定,可能最终会改变方法,从骆驼病例到pep8蛇形病例。
使用pytest
运行测试使用方法:
运行 由ActiveTick提供的http代理 并实例化activetick,默认值显示为启用了redis缓存:
from activetick_http import ActiveTick # Import the StrictRedis client to enable local persistent caching from redis import StrictRedis # ActiveTick initialized with Redis caching enabled (requires Redis) at = ActiveTick(host='127.0.0.1', port=5000, cache=StrictRedis(host='127.0.0.1'))
>;通过activetick实例,我们可以通过以下方法访问http代理提供的所有功能:
引用日期
quoteData(symbols, fields)
返回符号的即时引号信息(字段) 检查quote\u fields.py以获取可用选项。:
fields = ['LastPrice', 'BidPrice', 'AskPrice'] df = at.quoteData(('SPY', 'TLT', 'TVIX'), fields) print(df[fields].head())
LastPrice | BidPrice | AskPrice | |
---|---|---|---|
SPY | 216.3 | 216.46 | 216.55 |
TLT | 137.51 | 137.02 | 137.5 |
TVIX | 18.15 | 18.2 | 18.25 |
报价团队
quoteStream(symbols)
返回实时更新的报价流迭代器:
stream = at.quoteStream(('NUGT','DUST')) for tick in stream: print(tick)
TOdo:示例df
巴达塔
barData(symbol, historyType='I', intradayMinutes=60, beginTime=datetime, endTime=datetime)
返回单数符号的ohlcv数据:
df = at.barData('INTC', historyType='I', beginTime=datetime(datetime.now().year, 9, 27)) print(df.head())
open | high | low | close | volume | |
---|---|---|---|---|---|
2016-09-28 09:00:00 | 37.52 | 37.52 | 37.25 | 37.395 | 1.79294e+06 |
2016-09-28 10:00:00 | 37.4 | 37.46 | 37.27 | 37.31 | 1.59818e+06 |
2016-09-28 11:00:00 | 37.31 | 37.32 | 37.15 | 37.28 | 1.32702e+06 |
2016-09-28 12:00:00 | 37.28 | 37.32 | 37.2 | 37.27 | 2.39398e+06 |
2016-09-28 13:00:00 | 37.275 | 37.39 | 37.22 | 37.37 | 1.23249e+06 |
滴答数据
tickData(symbol, trades=False, quotes=True, beginTime=datetime, endTime=dateime) 返回符号的历史刻度级报价和交易数据:
df = at.tickData('GDX', trades=True, quotes=False) print(df.head())
type | last | lastz | lastx | cond1 | cond2 | cond3 | cond4 | |
---|---|---|---|---|---|---|---|---|
2016-09-28 09:30:00.091000 | T | 26.27 | 52073 | P | 0 | 0 | 17 | 0 |
2016-09-28 09:30:00.091000 | T | 26.27 | 52073 | P | 16 | 0 | 0 | 0 |
2016-09-28 09:30:00.182000 | T | 26.25 | 211 | T | 0 | 12 | 0 | 0 |
2016-09-28 09:30:00.184000 | T | 26.25 | 89 | T | 37 | 12 | 14 | 0 |
2016-09-28 09:30:00.185000 | T | 26.25 | 500 | T | 0 | 12 | 14 | 0 |
选项链
optionChain(symbol)
返回构成底层选项链的符号:
df = at.optionChain('SPY') print(df.head())
0 | OPTION:SPY—161014P00186000 |
1 | OPTION:SPY—161012C00197000 |
2 | OPTION:SPY—161014C00187000 |
3 | OPTION:SPY—161014P00192000 |
4 | OPTION:SPY—161012P00193000 |