IB TWS contracts list?
- quantz
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
any ideas for where I could find a list of all contracts traded on IB and the relevant details for accessing them through the API? their website has the contract lookup page but that is not too useful. ideally would like to be able to download the info as a csv or something.
- dgn2
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
I use the contract lookup, but I only needed to extract 200 instruments or so. I couldn't find anything like a downloadable csv. Perhaps the API supports instrument search. I thought about writing a quick script in Perl, but never got around to it (too much other stuff to do)
...WARNING: I am an optimal f'er
- macrotrader
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
If you are talking about futures AFAIK you can infer the symbol by hand. If you are talking about equities the easiest way is probably to get the symbols through Bloomberg or some other source (for example through the SPRDs website) and then ping the server for requests. To my knowledge there is no product search feature. Perhaps the market scanner could be customized for this purpose.
"he, who has the power over the ingenius, is he not more ingenius than the ingenius?" Karl Marx
- goldorak
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
Do it by hand. wget, curl and perl are your best friends on that one. First download the available contracts for the exchanges you are interested in and second launch requests to the contract lookup to get the details. Maximum one day of work to implement it.
If you are not living on the edge you are taking up too much space.
- macrotrader
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
I have found a workaround for equities. They have a complete list for shortable and non-shortable stocks: link.
"he, who has the power over the ingenius, is he not more ingenius than the ingenius?" Karl Marx
- quantz
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
thanks macrotrader, that is pretty useful. they have it for a couple non-US stock markets too. i also found that I could use the product listing page to find contract names, which is a bit better than the contract lookup.
http://www.interactivebrokers.com/en/p.php?f=products
should be able to scrape by with those for now. some time when I get a chance I may try to write a script to collect them all Smiley
http://www.interactivebrokers.com/en/p.php?f=products
should be able to scrape by with those for now. some time when I get a chance I may try to write a script to collect them all Smiley
- macrotrader
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
Not so easy to scrape the site, because it's not plain HTML. Let me know when you have found a solution.
"he, who has the power over the ingenius, is he not more ingenius than the ingenius?" Karl Marx
- tptspecial
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am
IB TWS contracts list?
It was pretty easy to scrape the whole thing. Here is a small matlab script that you could use to get the list of all stocks for AMEX. NOT optimized for speed.
RowExpression = ']*>(.*?)' ;
ColumnExpression = ']*>(.*?)';
NameExpression = ']*>(.*?)';
NumPages = 100
700;
FinalTableData = [];
for PageIdx = 1:length(NumPages)
url = ['http://www.interactivebrokers.com/en/trading/exchanges.php?exch=amex&showcategories=STK&showproducts=&sequence_idx=' num2str(NumPages(PageIdx)) '&sortproducts=&ib_entity=llc#show'];
data = urlread(url);
[tmatch,ttokens]=regexp(data,RowExpression,'match','tokens');
[tmatch2,ttokens2]=regexp(tmatch,ColumnExpression,'match','tokens');
tokenlengths = cellfun('length',ttokens2);
ThoseWith4Columns = find(tokenlengths==4);
ThoseWith4Columns(1)=[];
%%
TableData = cell(length(ThoseWith4Columns),4);
for idx = 1:length(ThoseWith4Columns);idx
jdx = ThoseWith4Columns(idx);
[ttoken3]=regexp(ttokens2{1,jdx}{2}{:},NameExpression,'tokens');
ttoken3 = regexprep(ttoken3{:},'&','');
TableData(idx,:) = [ttokens2{1,jdx}{:}];
TableData(idx,2) = ttoken3;
end
FinalTableData = [FinalTableData;TableData]; %#ok
end
RowExpression = ']*>(.*?)' ;
ColumnExpression = ']*>(.*?)';
NameExpression = ']*>(.*?)';
NumPages = 100
FinalTableData = [];
for PageIdx = 1:length(NumPages)
url = ['http://www.interactivebrokers.com/en/trading/exchanges.php?exch=amex&showcategories=STK&showproducts=&sequence_idx=' num2str(NumPages(PageIdx)) '&sortproducts=&ib_entity=llc#show'];
data = urlread(url);
[tmatch,ttokens]=regexp(data,RowExpression,'match','tokens');
[tmatch2,ttokens2]=regexp(tmatch,ColumnExpression,'match','tokens');
tokenlengths = cellfun('length',ttokens2);
ThoseWith4Columns = find(tokenlengths==4);
ThoseWith4Columns(1)=[];
%%
TableData = cell(length(ThoseWith4Columns),4);
for idx = 1:length(ThoseWith4Columns);idx
jdx = ThoseWith4Columns(idx);
[ttoken3]=regexp(ttokens2{1,jdx}{2}{:},NameExpression,'tokens');
ttoken3 = regexprep(ttoken3{:},'&','');
TableData(idx,:) = [ttokens2{1,jdx}{:}];
TableData(idx,2) = ttoken3;
end
FinalTableData = [FinalTableData;TableData]; %#ok
end
- dgn2
- Posts: 0
- Joined: Thu Jan 01, 2004 12:00 am