开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

How to get - Account Number


multicen2002
 

I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX


bee_jay_61
 

--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX
I am not sure, but isn?t the account number display in the window
caption of the "Account"-Window?

If so, than I would read the Window Caption.


marinindextrader
 

This is an interesting question, and one I was intending at some
point to explore.

Based on a cursory review of the methods and calls, there is no way
to retrieve an account number.

But on a little deeper look I believe I have a solution for you.

Apparentley the TWS platform remembers the socket port you called
with the account you called.

In other words you must log onto to each account from a different
socket port with seperate instance of TWS, and then from within your
program you can call the connection from a seperate instance of the
Active X componenet for each account.

An array of controls would do the job...

TWS1(0).Connect "", 7496
TWS1(1).Connect "", 7497

or perhaps just renaming the controls

TWS1.Connect "", 7496
TWS2.Connect "", 7497

I am an array kind of guy so I would go the array route...

Lastley, perhaps you dont even need the second instance and can call
direct..

TWS1.Connect "", 7496
TWS1.Connect "", 7497

But this looks like your asking for trouble and corupted data...IMHO

Either Way....

From there, you can then refrence your calls and segregate returns
based on the source of the call

TWS1(0).reqMktData(da dee da)
TWS1(1).reqMktData(da dee da)

Thats how I see it.

Again, I havn't explored this in detail and perhaps I am wrong.

Give that a shot and then report back here what you find so we can
all benefit from your experience.

Scott
Owner TWSAPI

--- In twsapi@y..., bee_jay_61 <no_reply@y...> wrote:
--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX
I am not sure, but isn?t the account number display in the window
caption of the "Account"-Window?

If so, than I would read the Window Caption.


marinindextrader
 

Anyone know how to get account number >>?

I think you need to control this yourself and keep a cross refrence
with which instance you are calling the connect from.

In this case you need to either capture the port and compare it when
you call it, or better yet keep an array that mirrors your API object
array interms of indecies

Such as a Long, 2 dimensional array that has as many lead indecie as
you have API objects and as many columns as you feel fit to
include...2 in this case...that would look something like this


Dim arrAccount()
ReDim arrAccount(UBound(TWS1), 1)

arrAccount(0,0) = 7496
arrAccount(0,1) = 'some account number
arrAccount(UBound(arrAccount),0) = 7497
arrAccount(UBound(arrAccount),1) = 'some other account number

Then when you call any TWS you can refrence the array as well and
return the account number easily based on the index API object.

You could add a third element to the array and make the array variant
and put a string value in the third slot such as "Stocks"
or "Futures" to further expand its utility.

Hope this helps as well

Scott

PS I will be exploring this subject in depth some time in the coming
couple of weeks and will be posting example code...

Unless of course you beat me to it



--- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote:
This is an interesting question, and one I was intending at some
point to explore.

Based on a cursory review of the methods and calls, there is no way
to retrieve an account number.

But on a little deeper look I believe I have a solution for you.

Apparentley the TWS platform remembers the socket port you called
with the account you called.

In other words you must log onto to each account from a different
socket port with seperate instance of TWS, and then from within
your
program you can call the connection from a seperate instance of the
Active X componenet for each account.

An array of controls would do the job...

TWS1(0).Connect "", 7496
TWS1(1).Connect "", 7497

or perhaps just renaming the controls

TWS1.Connect "", 7496
TWS2.Connect "", 7497

I am an array kind of guy so I would go the array route...

Lastley, perhaps you dont even need the second instance and can
call
direct..

TWS1.Connect "", 7496
TWS1.Connect "", 7497

But this looks like your asking for trouble and corupted data...IMHO

Either Way....

From there, you can then refrence your calls and segregate returns
based on the source of the call

TWS1(0).reqMktData(da dee da)
TWS1(1).reqMktData(da dee da)

Thats how I see it.

Again, I havn't explored this in detail and perhaps I am wrong.

Give that a shot and then report back here what you find so we can
all benefit from your experience.

Scott
Owner TWSAPI






--- In twsapi@y..., bee_jay_61 <no_reply@y...> wrote:
--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX
I am not sure, but isn?t the account number display in the window
caption of the "Account"-Window?

If so, than I would read the Window Caption.


marinindextrader
 

That was an excellent question

--- In twsapi@y..., bee_jay_61 <no_reply@y...> wrote:
--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX
I am not sure, but isn?t the account number display in the window
caption of the "Account"-Window?

If so, than I would read the Window Caption.


tripack44
 

--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.
Anyone know how to get account number >>?
An example vb code line will do just fine.

ThanX
This issue may be more complex than just parsing the acct # from the
title bar because you don't know which socket # is associated with
which account #. But if you want to find all the windows title bars
that contain the words "Interactive Brokers Trader Workstation" then
the following VB source code from Karl Peterson will get you started.

Web Site:


Sample code: