¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: updateAccountValue callbacks received but not accountDownloadEnd

 

Details depend on your application architecture, your framework(s), and to some degree the programming language you use.

In the simplest case you could use a model (as in Model-View-Controller) with read-only fields for the account values you are interested in. Callbacks from the initial request and from ongoing incremental updates simply change the corresponding fields in the model. The various client parts read the most recent value from the model when they need a value.

In case you can use "Observable" data objects or some kind of "Data Binding" framework for fields in your model, updates from TWS API callbacks can trigger chains of notifications and method calls in your client. That can work in single-threaded and multi-threaded designs.

I assume when you mention "thread event object" you refer to Python. I am not fluent enough in Python to give you concrete advice and "thread event objects" may very well all you need. But there are Python libraries and frameworks available that implement "observable patterns" or more general "data binding" services that may provide more features and more convenient APIs with less programming effort.

´³¨¹°ù²µ±ð²Ô


Re: updateAccountValue callbacks received but not accountDownloadEnd

 

¿ªÔÆÌåÓý

Excellent, thanks ´³¨¹°ù²µ±ð²Ô. ?So in terms of live monitoring of account/order updates, a separate thread event object (for the incremental updates) is best.

?

Dave

?

?

?

From: [email protected] <[email protected]> On Behalf Of ´³¨¹°ù²µ±ð²Ô Reinold via groups.io
Sent: Friday, 15 July 2022 11:11 AM
To: [email protected]
Subject: Re: [TWS API] updateAccountValue callbacks received but not accountDownloadEnd

?

In general, you should expect one and only one "end" callback for each request call. If the request also subscribes you to future updates, in general, do not expect any additional "end" calls.

When your client initially connects and requests (for example) account or order updates, you receive an immediate "current" or "historical" complete snapshot of the relevant data. The end of that complete download is indicated by the corresponding "end" callbacks.

From that point on, only incremental updates to the initial download are sent for values that actually change. Since these are incremental, "end" callbacks really make no sense and, consequently, are not sent.

Hope that helps,

´³¨¹°ù²µ±ð²Ô


Re: updateAccountValue callbacks received but not accountDownloadEnd

 

In general, you should expect one and only one "end" callback for each request call. If the request also subscribes you to future updates, in general, do not expect any additional "end" calls.

When your client initially connects and requests (for example) account or order updates, you receive an immediate "current" or "historical" complete snapshot of the relevant data. The end of that complete download is indicated by the corresponding "end" callbacks.

From that point on, only incremental updates to the initial download are sent for values that actually change. Since these are incremental, "end" callbacks really make no sense and, consequently, are not sent.

Hope that helps,

´³¨¹°ù²µ±ð²Ô


Re: updateAccountValue callbacks received but not accountDownloadEnd

 

¿ªÔÆÌåÓý

Can anyone help on this one?? Would just like to know if accountDownloadEnd is sent by the API at the end of each (3 min) accountDownload subscription set, or only after the initial request is returned?? I assume it¡¯s the End signal is sent each time (and therefore the problem is actually in my code), but just want to eliminate the possibility that the End signal is not sent each time ¨C the documentation is ambiguous.

?

In a similar vein, when orders are executed (or cancelled) is the openOrderEnd/completedOrderEnd callback sent automatically?

?

I am trying to monitor live for changes in the orders and account, but my thread events are not being set because the respective End callbacks are not being received.

?

Dave

?

?

From: [email protected] <[email protected]> On Behalf Of David Walker
Sent: Thursday, 30 June 2022 6:31 PM
To: [email protected]
Subject: [TWS API] updateAccountValue callbacks received but not accountDownloadEnd

?

Hi Everyone,

I'm subscribing to account updates with reqAccountUpdates(True, account_id) and receiving both?updateAccountValue and?accountDownloadEnd on the initial callback; however following that I only receive updateAccountValue?callbacks (every 3 minutes as expected) but with no accountDownloadEnd?callback. I though accountDownloadEnd?callbacks are also provided every 3 minutes, but it appears to not be so?? Anyone understand this behaviour?

Thanks in advance...

Dave


VIX weekly settlement price

 

Is it somehow possible to retrieve the weekly settlement price of the VIX via the API? And if so when is it available??

So far I fetch it directly from ?but I hoped to get it via the API little earlier.


Cannot connect to Production API, test is OK.

 

´³¨¹°ù²µ±ð²Ô,

The "q" netstat option in not supported on my Win7 machine.? Thanks for suggesting, though.

All's well so far ...

Thanks, as always, and Be Well,
Lou Dudka


Re: Cannot connect to Production API, test is OK.

 

Nothing is impossible, Lou, but my money is still on some application (real or defunct) holding the port. And it could simply be the old TWS during restart in case it does not completely terminate.

Next time, use a slightly different option for the netstat command. Use "netstat -qno -p tcp" instead of "netstat -ano -p tcp"

  • -a displays all connections and listening ports
  • -q? displays all connections, listening ports, and bound nonlistening TCP ports. Bound nonlistening ports may or may not be associated with an active connection.

On my Windows10 laptop, -a shows 88 ports in use, while -q shows 111 ports in use. Each port can only be used once and when some process uses 9707 as a "bound nonlistening port", TWS cannot get it as a listening port.

´³¨¹°ù²µ±ð²Ô


On Tue, Jul 12, 2022 at 05:33 PM, Lou Dudka wrote:
´³¨¹°ù²µ±ð²Ô,

OK, so Friday evening 07/08/22 I shut down everything and re-booted.? All times NYC.

I brought up both test and prod TWS.? Everything went fine, as expected, and there were no port conflicts.

Saturday, however, on the auto-reboot at 5:20 pm there was a port "conflict" on the test TWS this time.? I had a problem with prod last time.? "netstat -ano -p tcp " did not reveal any conflicts.

I brought down the test TWS and then up again.? No conflicts.? Both running on same machine.

I've been running with no conflicts ever since (Tuesday 07/12/22) with auto-reboots.

I'm leaning to a problem with TWS/auto-restart, and not a "real" networking port conflict.? I've had sporadic problems with TWS not coming up clean (thread #49333) and/or hanging on auto-restarts (no port conflicts) in the past.?? I've been trying to "watch" the auto-reboot live, but like a watched teapot, it never seems to boil ...

To the best of my knowledge I've changed nothing else (yeah, I know, we've all heard that one, LOL).

´³¨¹°ù²µ±ð²Ô, if I get another conflict I might take your suggestion to upgrade from 981.? I'm really short on time right now, so it would be a burden.

If all else fails I'll have to hang my head in shame from Richard and re-install IBC "on the sneak" and use Scheduler ... ah, those were the days, absolutely NO problems!

Thanks, as always, and Be Well,
Lou Dudka


Cannot connect to Production API, test is OK.

 

´³¨¹°ù²µ±ð²Ô,

OK, so Friday evening 07/08/22 I shut down everything and re-booted.? All times NYC.

I brought up both test and prod TWS.? Everything went fine, as expected, and there were no port conflicts.

Saturday, however, on the auto-reboot at 5:20 pm there was a port "conflict" on the test TWS this time.? I had a problem with prod last time.? "netstat -ano -p tcp " did not reveal any conflicts.

I brought down the test TWS and then up again.? No conflicts.? Both running on same machine.

I've been running with no conflicts ever since (Tuesday 07/12/22) with auto-reboots.

I'm leaning to a problem with TWS/auto-restart, and not a "real" networking port conflict.? I've had sporadic problems with TWS not coming up clean (thread #49333) and/or hanging on auto-restarts (no port conflicts) in the past.?? I've been trying to "watch" the auto-reboot live, but like a watched teapot, it never seems to boil ...

To the best of my knowledge I've changed nothing else (yeah, I know, we've all heard that one, LOL).

´³¨¹°ù²µ±ð²Ô, if I get another conflict I might take your suggestion to upgrade from 981.? I'm really short on time right now, so it would be a burden.

If all else fails I'll have to hang my head in shame from Richard and re-install IBC "on the sneak" and use Scheduler ... ah, those were the days, absolutely NO problems!

Thanks, as always, and Be Well,
Lou Dudka


Re: Sample code for most common use cases?

 

¿ªÔÆÌåÓý

Getting back on this topic, I found a website providing useful code samples for common use cases of TWI API:?

Some contents:

Just wanted to share and hope it can help others too.



From: [email protected] <[email protected]> on behalf of PurpleIce <clone8080@...>
Sent: Monday, July 4, 2022 4:25 AM
To: [email protected] <[email protected]>
Subject: [TWS API] Sample code for most common use cases?
?
Hi all,

I wonder if there are sample codes of recommended methods for the most common use cases. I know IB API has sample code, but it's on very low level (e.g. get price of a stock). Sample codes of such use cases can be very helpful:
  1. monitor the price of stock XYZ. If the price reaches x1, send a limit order of price x2. If the price drops to x3, cancel the order if not executed yet.
  2. get option chain of SPX, filter the expirations and strikes by some defined rules, and monitor the prices (bid/ask) for the options filtered. If some condition is met, send an order to buy a spread (buy x and sell y)
I know IB API takes an async approach and implementing the above use cases can have various ways. I think any method from an experienced programmer would be good to start. It teaches newbies how to organize all pieces into a functional trading software.

Thank you!


can two clients for the same ibgateway share market data?

 

I have 2 clients connecting to the same ibgateway and both of them subscribe to some market data. The 2nd connected client has error - "Code: 10197, Msg: No market data during competing live session".

Is this normal? I kinda remember api clients of the same ibgateway can share market data before...maybe ib changed policy?


Tws Vs Gateway Api

 

Does anyone happen to know??

I use the Gateway API for placing orders using my python script. In?the gateway settings there are a few options to set specific order conditions, However in the settings of the Regular Desktop TWS, there are far more options to set specific order conditions. My question is, will the order settings in my TWS apply to orders I place using the gateway API? Assuming I'm using the same instrument and the same account??

Thank you for any help
Adam


Strange Glitch When Requesting PNL

 

This took me forever to diagnose, but here is the glitch.? When request PNL message is sent there is no PNL response if you've already asked before.? Let me explain.

This only happens under certain conditions:
  • PNL is 0.0, no trades have been made
  • TWS only this does not happen with IB gateway
So basically if I start TWS turn on my program it request PNL and receives response just fine.? However, if I turn off my program and restart it, I will never get a PNL response again.? So my code will just freeze waiting for PNL response.? When I restart TWS it resets, so I can request PNL and will receive a response once and not again.

This does not happen with IB gateway, I can request PNL as often as I'd like.? Also this does not happen if my PNL is not zero, so if I've made or lost money it will send my my daily PNL over and over again.

I'm using TWS version 10.15


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Thanks again, Jurgen
E

On Sat, 9 Jul 2022 at 7:49 ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:

No problem, Ed.

If you follow the call path in the Java API source code you will find that either option (null or "") is fine and yields the same result. The Order class uses Order.EMPTY_STR to initialize manualOrderTime and you could use that, since it is a public constant. It happens to be defined as "".

´³¨¹°ù²µ±ð²Ô

On Fri, Jul 8, 2022 at 10:40 PM, Edward wrote:
Thanks a lot for such an elaborated answer. I guess you're right.?
?
I was wondering if anybody is really using 10.16 API and what do they pass as this parameter. There are two options-empty string ot null.
?
Ed

?
?

--
Ed Gonen


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

No problem, Ed.

If you follow the call path in the Java API source code you will find that either option (null or "") is fine and yields the same result. The Order class uses Order.EMPTY_STR to initialize manualOrderTime and you could use that, since it is a public constant. It happens to be defined as "".

´³¨¹°ù²µ±ð²Ô

On Fri, Jul 8, 2022 at 10:40 PM, Edward wrote:

Thanks a lot for such an elaborated answer. I guess you're right.?
?
I was wondering if anybody is really using 10.16 API and what do they pass as this parameter. There are two options-empty string ot null.
?
Ed

?
?


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Thanks a lot for such an elaborated answer. I guess you're right.?

I was wondering if anybody is really using 10.16 API and what do they pass as this parameter. There are two options-empty string ot null.

Ed

On Sat, 9 Jul 2022 at 1:01 ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:

Just guessing here, Edward, but this is probably related to the new field and feels like a regulatory thing for brokers and advisors. So I guess unless you are a broker or advisor, pass the empty string.

´³¨¹°ù²µ±ð²Ô

From:

Limit Order With Manual Order Time

The Limit Order With Manual Order Time is a with ManualOrderTime property.

Order order = OrderSamples.LimitOrder(action, quantity, limitPrice);

Placing a Limit Order With Manual Order Time
The Manual Order Time field is required for, and becomes editable for, "manual" orders, which are orders that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system. The Manual Order Time field is not used for client orders received electronically, nor for orders that originate from the account manager (with discretion) in the client's accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Util.StringToDecimal("100"), 111.11, "20220314 13:00:00"));

Canceling a Limit Order With Manual Order Time
The Manual Order Cancel Time field is required for, and becomes editable for, "manual" order cancelations, which are order cancelations that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system. The Manual Order Cancel Time field is not used for client orders cancelations received electronically, nor for orders that originate from the account manager (with discretion) in the client's accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

client.cancelOrder(nextOrderId - 1, "20220314 19:00:00");

--
Ed Gonen


Cannot connect to Production API, test is OK.

 

´³¨¹°ù²µ±ð²Ô,

?I'd first like to thank you for the time and effort you put into this site, we are very fortunate to have you.
?
?Secondly, I like to especially thank you for the same time and effort you put into this particular problem I had on this topic.

Your technical knowledge is so immense it sometimes can overwhelm me.? I have 35 years professional IT experience, but I started with Mainframe IBM/Cobol.? Anything else has be self taught.
?
Having said that, I re-booted the computer, bought up TWS (Prod and Test with the same port that gave me trouble) and successfully connected.? I ran "netstat -ano -p tcp " and the port showed up, as it should.? Your " lsof -iTCP -n" and "cat /proc/nettcp" would not run on Win7, though thanks for the info.

?Somewhere in the cobwebs of my aging mind I seem to remember encountering this problem before? ...
.
?I have no reason to doubt your expertise so I will pay close attention to the ports that are in use and see if there is a conflict.
?
?Thanks, as always, and Be Well,
?Lou Dudka


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Just guessing here, Edward, but this is probably related to the new field and feels like a regulatory thing for brokers and advisors. So I guess unless you are a broker or advisor, pass the empty string.

´³¨¹°ù²µ±ð²Ô

From:

Limit Order With Manual Order Time

The Limit Order With Manual Order Time is a with ManualOrderTime property.

Order order = OrderSamples.LimitOrder(action, quantity, limitPrice);

Placing a Limit Order With Manual Order Time
The Manual Order Time field is required for, and becomes editable for, "manual" orders, which are orders that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system. The Manual Order Time field is not used for client orders received electronically, nor for orders that originate from the account manager (with discretion) in the client's accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Util.StringToDecimal("100"), 111.11, "20220314 13:00:00"));

Canceling a Limit Order With Manual Order Time
The Manual Order Cancel Time field is required for, and becomes editable for, "manual" order cancelations, which are order cancelations that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system. The Manual Order Cancel Time field is not used for client orders cancelations received electronically, nor for orders that originate from the account manager (with discretion) in the client's accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

client.cancelOrder(nextOrderId - 1, "20220314 19:00:00");


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Any answers to this? I've replaced my 9.x API with the 10.16 and, naturally I had to add this parameter. Having added it as just DateTime.Now led to a problem that the submitted orders are not always cancelled... Should it be the time when the order was submitted?


Re: ERROR -1 2104 Market data farm connection is OK:usfarm.nj

 

¿ªÔÆÌåÓý

Found the answer on


2104
Market data farm connection is OK A notification that connection to the market data server is ok. This is a notification and not a true error condition, and is expected on first establishing connection.
2158
Sec-def data farm connection is OK A notification that connection to the Security definition data server is ok. This is a notification and not a true error condition, and is expected on first establishing connection.
2105
A historical data farm is disconnected. Indicates a connectivity problem to an IB server. Outside of the nightly IB server reset, this typically indicates an underlying ISP connectivity issue.
2106
A historical data farm is connected. A notification that connection to the market data server is ok. This is a notification and not a true error condition, and is expected on first establishing connection.


Sorry for bothering; thanks!



From: [email protected] <[email protected]> on behalf of PurpleIce <clone8080@...>
Sent: Friday, July 8, 2022 4:00 PM
To: [email protected] <[email protected]>
Subject: [TWS API] ERROR -1 2104 Market data farm connection is OK:usfarm.nj
?
Hi all,

Each time I started my TWS api program (python) these messages show up. They start with "ERROR" but seems connection status report. Anyone knows why they show up?


Using args Namespace(global_cancel=False, port=7496)
serverVersion:173 connectionTime:b'20220708 03:54:17 EST'
NextValidId: 1
Executing requests
? ?doing accountOperations_req
? ?done w/ accountOperations_req
Executing requests ... finished
ERROR -1 2104 Market data farm connection is OK:usfarm.nj
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm.nj
ERROR -1 2104 Market data farm connection is OK:hfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:hfarm
ERROR -1 2104 Market data farm connection is OK:usfuture
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfuture
ERROR -1 2104 Market data farm connection is OK:cashfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:cashfarm
ERROR -1 2104 Market data farm connection is OK:usopt
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usopt
ERROR -1 2104 Market data farm connection is OK:usfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:hkhmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:hkhmds
ERROR -1 2106 HMDS data farm connection is OK:ushmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:ushmds
ERROR -1 2106 HMDS data farm connection is OK:fundfarm
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:fundfarm
ERROR -1 2158 Sec-def data farm connection is OK:secdefhk
Error. Id: -1 Code: 2158 Msg: Sec-def data farm connection is OK:secdefhk



ERROR -1 2104 Market data farm connection is OK:usfarm.nj

 

¿ªÔÆÌåÓý

Hi all,

Each time I started my TWS api program (python) these messages show up. They start with "ERROR" but seems connection status report. Anyone knows why they show up?


Using args Namespace(global_cancel=False, port=7496)
serverVersion:173 connectionTime:b'20220708 03:54:17 EST'
NextValidId: 1
Executing requests
? ?doing accountOperations_req
? ?done w/ accountOperations_req
Executing requests ... finished
ERROR -1 2104 Market data farm connection is OK:usfarm.nj
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm.nj
ERROR -1 2104 Market data farm connection is OK:hfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:hfarm
ERROR -1 2104 Market data farm connection is OK:usfuture
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfuture
ERROR -1 2104 Market data farm connection is OK:cashfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:cashfarm
ERROR -1 2104 Market data farm connection is OK:usopt
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usopt
ERROR -1 2104 Market data farm connection is OK:usfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:hkhmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:hkhmds
ERROR -1 2106 HMDS data farm connection is OK:ushmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:ushmds
ERROR -1 2106 HMDS data farm connection is OK:fundfarm
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:fundfarm
ERROR -1 2158 Sec-def data farm connection is OK:secdefhk
Error. Id: -1 Code: 2158 Msg: Sec-def data farm connection is OK:secdefhk