Folks,<br><br>Sorry for delay, I only caught the thread now - even with a security-card-active account, the web service does not require login at all.<br><br>It works like this:<br><br>- in Account Management, you set up the Flex service, and generate a &quot;token&quot; of some ~30 characters.<br>

- you also set up a report(s) with desired fields, and IB associates an ID(s) with it.<br>- With this token and query ID, you access a xml URL, which starts the report execution and gives a &quot;resultset-ID&quot;.<br>- After waiting a bit for execution, you then access a different URL, with the resultset-ID, and retrieve the results<br>

<br>so after setting up the Flex service and report(s), no login is needed at all, security is handled with the &quot;token code&quot;.  I believe there is also an option to limit access to specific originating IPs<br><br>

below is my python code which may make the process clearer (sorry I&#39;m a beginner Python writer, so it may not be the most elegant - specifically, I write to a local file and then import to a database, I could not get Python to read directly to sqlite)<br>

<br><br><br><br>updateDB.py<br>-------------------------------------------------------------------------------------------------------------------------------------------------------------<br>import sqlite3, csv, urllib.request, urllib.parse, urllib.error, re, time<br>

<br>conn = sqlite3.connect(&quot;mydb9.sqlite&quot;)<br>cur = conn.cursor()<br><br>token = 632xxxxxxxxxxxxxxxx53730 ; query = 20xxx # this is the token issued by IB<br><br>url = &quot;<a href="https://www.interactivebrokers.com/Universal/servlet/FlexStatementService.SendRequest?t=%s&amp;q=%s">https://www.interactivebrokers.com/Universal/servlet/FlexStatementService.SendRequest?t=%s&amp;q=%s</a>&quot; % (token, query)<br>

ibfile = urllib.request.urlopen(url).read().decode(&#39;utf-8&#39;) <br><br>pattern = re.compile(r&#39;\d{10}&#39;)  #Search for 10-digit reference code  (resultset code)<br>m = pattern.search(ibfile)<br>reference_code = (m.group()) #retrieve reference code<br>

<br>url = &quot;<a href="https://www.interactivebrokers.com/Universal/servlet/FlexStatementService.GetStatement?q=%s&amp;t=%s&amp;v=2">https://www.interactivebrokers.com/Universal/servlet/FlexStatementService.GetStatement?q=%s&amp;t=%s&amp;v=2</a>&quot; % (reference_code, token)   <br>

<br>pattern = re.compile(r&#39;in progress&#39;)  #If report is not completed, IB returns an &lt;in progress&gt; message<br>for i in range(5): #try 5 times, 40s apart<br>    print(&#39;Try &#39;, i,)<br>    time.sleep(40)<br>

    ibfile = urllib.request.urlopen(url).read().decode(&#39;utf-8&#39;)<br>    if pattern.search(ibfile) == None:<br>        break<br>print(&#39;Succesfully retrieved report&#39;)<br><br>ibfile_object = open(&#39;ib.csv&#39;, &#39;w&#39;)<br>

ibfile_object.write(ibfile.replace(&#39;,&#39;,&#39;&#39;))<br>ibfile_object.close()<br>print(&#39;Saved file&#39;)<br><br>time.sleep(2) # Give the OS time to close the file<br><br><br># Create table<br>cur.execute(&#39;&#39;&#39;drop table IF EXISTS tbIB&#39;&#39;&#39;)<br>

sql = &#39;&#39;&#39;create table IF NOT EXISTS tbIB (<br>Symbol          TEXT,<br>Description     TEXT,<br>AssetClass      TEXT,<br>TradeID         INTEGER,<br>TradeDate       INTEGER,<br>TradeTime       INTEGER,<br>Quantity        INTEGER,<br>

Multiplier       INTEGER,<br>TradePrice       REAL,<br>TradeMoney       REAL,<br>NetCash          REAL,<br>Taxes            REAL,<br>IBCommission     REAL,<br>CostBasis        REAL,<br>FifoPnlRealized  REAL,<br>NotesCodes       TEXT<br>

)&#39;&#39;&#39;<br><br>cur.execute(sql)<br><br>cur.execute(&#39;&#39;&#39;create unique index IF NOT EXISTS idx_TradeID ON tbIB(TradeID)&#39;&#39;&#39;)<br><br><br>ibfile_object = open(&#39;ib.csv&#39;, &#39;rt&#39;)<br>

<br>csvread = csv.reader(ibfile_object, delimiter=&#39;|&#39;, quotechar=&#39;&quot;&#39;)<br>for line in csvread:<br>    if line != []:<br>        cur.execute(&#39;insert OR IGNORE into tbIB values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)&#39;, line)<br>

<br>conn.commit()<br><br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN oldSymbol           TEXT&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN Underlying          TEXT&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN OptionType          TEXT&#39;)<br>

cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyInShares         INTEGER&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyOpening          INTEGER    DEFAULT 0&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyClosing          INTEGER    DEFAULT 0&#39;)<br>

cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyCumulative       INTEGER    DEFAULT 0&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyStillOpenTrx     INTEGER    DEFAULT 0&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN QtyWashMatched      INTEGER    DEFAULT 0&#39;)<br>

cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN BasisAdjWash        Real       DEFAULT 0&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN BasisAdjOption      Real       DEFAULT 0&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN Trace               Text&#39;)<br>

cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN TraceWash           Text&#39;)<br>cur.execute(&#39;ALTER TABLE tbIB ADD COLUMN TraceOption         Text&#39;)<br><br><br>cur.close()<br>conn.close()<br>----------------------------------------------------------------------------------------------------------------------------------<br>

<br><br><br><br><br><br><div class="gmail_quote">On Thu, Sep 17, 2009 at 06:35, Ken Feng <span dir="ltr">&lt;<a href="mailto:kfmfe04@gmail.com">kfmfe04@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im">On 9/17/09, Paul C &lt;<a href="mailto:paulq2o0@yahoo.co.uk">paulq2o0@yahoo.co.uk</a>&gt; wrote:<br>
&gt;<br>
&gt; If the TWS is already running, it seems you can get to the IB website<br>
&gt; Account Management without logging in again (i.e. without using the<br>
&gt; security device a second time) by choosing &quot;View-&gt;Account Management&quot;<br>
&gt; from the *TWS* menu.  It should then just appear in your browser (albeit<br>
&gt; you may not know it, until you go find the browser window).  So if<br>
&gt; you&#39;re running all week, maybe you&#39;re ok? - unless I&#39;m misunderstanding<br>
&gt; something.<br>
&gt;<br>
&gt; ( nb, I&#39;ve just managed to automate retrieval of Trade Records from<br>
&gt; the TWS &#39;Trades&#39; page using the perl/ X11::GUITest approach, but it&#39;s<br>
&gt; probably not robust, and is maybe asking for trouble, so I won&#39;t<br>
&gt; elaborate here - it&#39;s not really shim related anyway.  The fact that<br>
&gt; it&#39;s wrapped in html tags I don&#39;t see as a problem, and you can get<br>
&gt; the Order_ID/Ref too, so presumably can associate a commission with an<br>
&gt; order sent via the shim [and hence in a MySql table]. But it involves<br>
&gt; sending keystrokes to the running TWS, which I don&#39;t much like. )<br>
<br>
</div>That&#39;s great!  I wasn&#39;t aware of that feature - I thought I had to do<br>
it through the website by hand!<br>
<br>
Since I am already using Jemmy to manage the perpetual log-in, I can<br>
use it to bring up the browser - I need to figure out how to scrape it<br>
at that point.  I will try to use Jemmy or some java-related tool<br>
since I&#39;m using it to drive TWS.<br>
<br>
Anyhow, thank you for pointing to a way out of this conundrum!<br>
<font color="#888888"><br>
- Ken<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
ts-general mailing list<br>
<a href="mailto:ts-general@trading-shim.org">ts-general@trading-shim.org</a><br>
<a href="http://www.trading-shim.org/mailman/listinfo/ts-general" target="_blank">http://www.trading-shim.org/mailman/listinfo/ts-general</a><br>
</div></div></blockquote></div><br>