php optionchain MSFT
You could get the same result by typing 'MSFT' and hitting the
Download button at http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx
Since a few days the script doesn't work anymore. :-( . I suspect that
something changed on the website. I am not familiar with php and I
can't fix things myself. I was wondering if there was any kind soul
willing to help.
Thanks in advance.
Arturo.
=======================
<?php
// cookie and error log path - SET THIS BEFORE TESTING
define(TMPFILEPATH, "/mf/home/unicorn/shell/tmp");
/*
* This script gets option chain data in a comma-delimited text file
* from the Chicago Board of Options web site www.cboe.com.
*
* Example for Microsoft (MSFT) stock options:
*
* URL syntax: http://example.com/optionchain.php?ticker=MSFT
*
* Commandline: % php optionchain.php MSFT
*/
$tickersymbol = isset($_GET['ticker']) ? $_GET['ticker']
: $_SERVER['argv'][1]; // get argument from commandline if no $_GET
$ch = curl_init(); // initialize curl
curl_setopt($ch, CURLOPT_VERBOSE, true); // verbose errors
$er = fopen(TMPFILEPATH.'/curl_err.txt', 'w'); // error log file
curl_setopt($ch, CURLOPT_STDERR, $er); // log the errors
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, TMPFILEPATH.'/cboe_cookie.txt');
curl_setopt($ch, CURLOPT_REFERER,
'http://www.cboe.com/delayedQuote/QuoteTableDownload.aspx');
curl_setopt($ch, CURLOPT_URL,
'http://www.cboe.com/delayedQuote/QuoteTableDownload.aspx');
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
// "log in" to web site by accessing first page (sets cookie)
$discard = curl_exec($ch);
// now post the form. The result will come after setting more
// cookies and receiving a redirect to a different URL,
// http://www.cboe.com/delayedQuote/QuoteData.dat
// which returns data using the query data contained in a cookie.
// AFTER that we get redirected back to the original page,
// so limit redirects to 1
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_POST, true); // enable HTTP POST
curl_setopt($ch, CURLOPT_POSTFIELDS,
'__EVENTTARGET='
.'&__EVENTARGUMENT='
.'&__VIEWSTATE='.urlencode('dDwtODQ5MjIyNjc7Oz5rmegY+4O27l7uWcpGd4iU
+1RpAA==')
.'&ucHeader:ucCBOEHeaderLinks:ucCBOEHeaderSearch:searchtext='
.'&ucHeader:ucCBOEHeaderLinks:ucCBOEHeaderSearch:Button1=Search'
.'&ucQuoteTableDownloadCtl:txtTicker='.$tickersymbol
.'&ucQuoteTableDownloadCtl:cmdSubmit=Download');
// Get data (RETURNS NULL FROM BROWSER, WORKS FROM COMMANDLINE ??)
$content = curl_exec($ch);
// Close resources
curl_close ($ch);
fclose($er);
// display result
print "<pre>Data:\n{$content}\nEnd</pre>\n";
?>
Oops. I forgot to post the output I get. This is it:
php optionchain_test.php MSFT
<pre>Data:
Invalid request.
End</pre>
If you can't fix it yourself, I'd recommend you hire someone to find the
problem and fix it. It shouldn't take too long for someone to do it
(no, I am not advertising, and I am not available).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
I hope I am not breaking any rule here, but I thought that this was
the right place to ask such a question. Please, note that I am not a
trader nor I belong to any high profile hedge-fund or the likes (as
you can imagine they have their own professional, real time data feed
and don't need to resort to quickly hacked scripts). I am mainly using
this script for hobbystic purposes and I just wanted to get a pointer
to what is wrong with it.
Arturo
>Since a few days the script doesn't work anymore. :-( . I suspect that
>something changed on the website.
Well yes, if the script has previously been working. Is there any
documentation you can refer to?
--
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.4theweb.co.uk/rfdmaker
Thanks for your answer. Unfortunately, the CBOE web site doesn't
mention any specific change made recently to their web site. No
documentation is provided by them either.
Thanks anyhow.
Arturo.
This is the correct place to ask such a question - but this is a place
to get user-to-user help, not free consulting services. We help each
other get something to work - not provide free consulting services.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
>Thanks for your answer. Unfortunately, the CBOE web site doesn't
>mention any specific change made recently to their web site. No
>documentation is provided by them either.
Oh, I thought this was an official interface and would be documented.
Don't suppose you know who wrote the original script?
Unfortunately, the email address of the author was hidden in the
message from which I got the script. May be I can search the web a
little deeper.
Arturo
BTW, the first line has a typo. Where it says:
define(TMPFILEPATH, "/mf/home/unicorn/shell/tmp");
if should say:
define('TMPFILEPATH', "/mf/home/unicorn/shell/tmp");
But this should not be an issue.
This message comes from curl_exec() and this function would return FALSE
is there was an error in the transmission itself. It isn't the case so
it's the remote server the one that is sending such error message. You
should check with the Chicago Board of Options and see if they changed
something in their API. However, the page it fetches has this warning:
PLEASE NOTE: IT IS STRICTLY PROHIBITED TO DOWNLOAD DELAYED QUOTE TABLE
DATA FROM THIS WEB SITE BY USING AUTO-EXTRACTION PROGRAMS/QUERIES AND/OR
SOFTWARE. CBOE WILL BLOCK IP ADDRESSES OF ALL PARTIES WHO ATTEMPT TO DO
SO. THIS DATA IS PROPERTY OF THOMSON FINANCIAL/ILX. DOWNLOADING THIS
DATA IN ANY OTHER WAY THAN BY MANUAL TICKER SYMBOL ENTRY IS STRICTLY
PROHIBITED.
It looks like you are not allowed to do this and you've been banned.
--
-- http://alvaro.es - �lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaci�n web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Thanks for your answer, Alvaro. I will check with CBOE people if this
PHP script infringes their rules. Usually, I use this script for just
a few tickers during off-peak hours. I guess this is OK, but I'll
check with them. BTW, I don't think that my IP has been banned since I
can still fetch chains using my browser.
I took a look at the web page and some of the field names have
changed. Also the __VIEWSTATE value is rather different from what you
are using.
Thanks for your time, Captain. You might be paralitic, but still have
a sharp eye! :-) I'lll try to fix the script according to your
suggestions.
Thanks again.
Arturo
You may find that the __VIEWSTATE value is dynamically generated and
you may need to capture it from the returned data from the "login"
curl_exec() step which you currently discard.
Thanks again. This is letting a bit too complicate for little me. May
be I should really hire someone to do the job or find alternative
sources for option chains.
Thanks anyhow for your help and patience.
> The following 'optionchain.php' script used to work pretty well in
> downloading an option chain from CBOE. For example, you could get a
> whole Microsoft option chain by typing :
>
> php optionchain MSFT
>
> You could get the same result by typing 'MSFT' and hitting the Download
> button at http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx
>
> Since a few days the script doesn't work anymore. :-( . I suspect that
> something changed on the website. I am not familiar with php and I can't
> fix things myself. I was wondering if there was any kind soul willing to
> help.
What part of the following from that URI don't you understand?