t******o 发帖数: 1470 | 1 想下载详细的数据。比如每分钟甚至更详细的股票的bid/ask price, vol ,
有谁有经验指点一下?
如果能够从broker那里下载更好。 | f**********r 发帖数: 2137 | | c**y 发帖数: 419 | 3 只有每天end of day的HLOC
日内的没有 | t******o 发帖数: 1470 | 4 能详细展开说说么?谢谢
或者告诉我哪里有以前讨论的内容可以学习?
ib是不是能够自己做一些接口,然后获得数据?
【在 f**********r 的大作中提到】 : ib
| f**********r 发帖数: 2137 | 5 http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.ht
【在 t******o 的大作中提到】 : 能详细展开说说么?谢谢 : 或者告诉我哪里有以前讨论的内容可以学习? : ib是不是能够自己做一些接口,然后获得数据?
| P******l 发帖数: 1648 | 6 google "ib amibroker"
30 day tick by tick
【在 t******o 的大作中提到】 : 能详细展开说说么?谢谢 : 或者告诉我哪里有以前讨论的内容可以学习? : ib是不是能够自己做一些接口,然后获得数据?
| a*****e 发帖数: 1717 | 7 Here's python one I used before,
drawbacks:
1. data pacing violation, limit on size of each quote, interval etc.
2. futures symbols are less standardized
3. IB data sucks, but ok for median to long term backtest
4. the ibpy is out-dated, you have to update yourself to get new
features.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
from time import sleep
from datetime import date
import pyodbc, os, sys
# print all messages from TWS
def watcher(msg):
print msg
def makeStkContract(contractTuple):
newContract = Contract()
newContract.m_symbol = contractTuple[0]
newContract.m_secType = contractTuple[1]
newContract.m_exchange = contractTuple[2]
newContract.m_currency = contractTuple[3]
newContract.m_expiry = contractTuple[4]
newContract.m_strike = contractTuple[5]
newContract.m_right = contractTuple[6]
print 'Contract Values:%s,%s,%s,%s,%s,%s,%s:' % contractTuple
return newContract
def makeESContract(expiry):
newContract = Contract()
newContract.m_symbol = 'ES'
newContract.m_secType = 'FUT'
newContract.m_exchange = 'GLOBEX'
newContract.m_currency = 'USD'
newContract.m_expiry = expiry
#newContract.m_strike = ''
#newContract.m_right = ''
return newContract
def printHistoricalData(msg):
global fout
if msg.date.find("finish") == -1:
timeline = msg.date[:4] + '-' + msg.date[4:6] + '-' +
msg.date[6:]
print '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (contractTuple[0],
timeline
, msg.open, msg.high, msg.low, msg.close, msg.volume, msg.count,
msg.WAP,
str(msg.WAP*msg.volume))
fout.writelines('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' %
(contractTuple[0
], msg.date, msg.open, msg.high, msg.low, msg.close, msg.volume,
msg.count,
msg.WAP, str(msg.WAP*msg.volume)))
if __name__ == '__main__':
cnxn = pyodbc.connect('DSN=Stock')
cursor = cnxn.cursor()
con = ibConnection()
con.port = XXX
#con.registerAll(watcher)
#con.unregister(watcher, message.HistoricalData)
#con.register(printHistoricalData, message.HistoricalData)
con.connect()
sleep(1)
tickId = 1
fout = open("IB_Hist/onemin_temp.txt", 'w')
getsymbol = "SELECT DISTINCT Symbol\
FROM Stock.dbo.stock_onemin"
cursor.execute(getsymbol)
rows = cursor.fetchall()
for row in rows:
symbol = row[0]
if symbol == 'MOT':
continue
#symbol = 'MSI'
#if symbol == 'MSI':
#break
#symbol = row
contractTuple = (symbol, 'STK', 'SMART', 'USD', '', 0.0, '')
stkContract = makeStkContract(contractTuple)
getdays = "SELECT b.TradingHour\
FROM [Stock].[dbo].[trading_days_2011] b\
LEFT JOIN (SELECT [Time] From [Stock].[dbo].[stock_onemin]
WHERE
Symbol = '" + symbol + "') a\
ON CONVERT(VARCHAR(10),b.TradingHour,111) =
CONVERT(VARCHAR(10),
a.[Time],111)\
WHERE a.[Time] IS NULL"
cursor.execute(getdays)
days = cursor.fetchall()
for day in days:
endday = str(day[0]).replace('-', '')
print endday
con.register(printHistoricalData, message.HistoricalData)
con.reqHistoricalData(tickId, stkContract, endday, '1 D', '1
min
', 'TRADES', 1 , 1)
sleep(10)
con.unregisterAll(printHistoricalData)
sleep(10)
con.disconnect()
fout.close()
sqlupdate = "sqlcmd -S XXX-DESKTOP\XXX -d Stock -Q \
"BULK INSERT Stock.dbo.stock_onemin\
FROM 'C:\Stock\IBATM\IB_Hist\onemin_temp.txt' \
WITH (FIELDTERMINATOR =',', \
ROWTERMINATOR ='\n')""
os.system(sqlupdate)
【在 t******o 的大作中提到】 : 想下载详细的数据。比如每分钟甚至更详细的股票的bid/ask price, vol , : 有谁有经验指点一下? : 如果能够从broker那里下载更好。
| t******o 发帖数: 1470 | | t******o 发帖数: 1470 | 9 太谢谢了。我仔细研究。
【在 a*****e 的大作中提到】 : Here's python one I used before, : drawbacks: : 1. data pacing violation, limit on size of each quote, interval etc. : 2. futures symbols are less standardized : 3. IB data sucks, but ok for median to long term backtest : 4. the ibpy is out-dated, you have to update yourself to get new : features. : #! /usr/bin/env python : # -*- coding: utf-8 -*- : from ib.ext.Contract import Contract
|
|