Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Market depth data has been RESET. Error Code: 317, C++ Program
Any clue you can give on which instrument generate it ? At what time ? |
Market depth data has been RESET. Error Code: 317, C++ Program
Hi All,
Lately, I have been seeing the error code: 317 periodically appear when streaming reqMktDepth() repeatedly, in my main trade logic loop. Currently, I am building the order book through the updateMktDepth() callback one reception at a time and storing it in a pair of sorted vectors for bid/ask. Why might this message pop up? How can I avoid it (different designs, etc.)? If it does continue to pop up, how can I empty the deep book contents before applying new entries? Right now, I am trying to avoid using another thread to stream this separately, so I can get a simple application up and running before going to a multi-threaded design. How would someone recommend avoiding this error message in a simple 1 thread design? Thank you, Brendan |
Re: Code samples
/g/insync/message/9550
Think you need to join the ib -insync group. There more code examples there. |
Code samples
Hi all,
?
Have a newbie question here. I've gone through the notebooks and code recipes on the ib-insync page but needing more example code. Where can I find more extensive code samples based on ib-insync?
?
Below is an outline of what I'm trying to achieve:
?
A) Update bar every minute
?
B) Separately:
1) request reqMktData
2) on event receiving ask/bid price, perform calculations using these as well as latest data from bars. Based on calculations, decide whether to send order
3) Continue receving ask/bid prices
4) If order sent in 2) above did not fill after 5 minutes, cancel order
?
I'm coding in Spyder/VS Code |
Re: Duplicate OrderID
¿ªÔÆÌåÓýThe latest order ids for each client id are stored, on the client computer, in the xml settings files for TWS and Gateway For example my tws.xml has this: ? ??????????? <MapOfStrings varName="ddeIdMap"> ????????????????? <Entry key="123" val="2"/> ????????????????? <Entry key="906564398" val="268435468"/> ????????????????? <Entry key="4739156" val="268435456"/> ????????????????? <Entry key="69744289" val="268565542"/> ????????????????? <Entry key="49723415" val="268575547"/> ????????????????? <Entry key="11344589" val="268435456"/> ????????????????? <Entry key="938945948" val="268435462"/> ????????????????? <Entry key="537090480" val="268435472"/> ??????????? </MapOfStrings> ? I placed an order using clientId 49723415 a few minutes ago, and you can see that the order id was 268575547. ? So when an API connection is made, the value for the chosen clientId is retrieved from the settings file and incremented, and sent via the nextValidId() callback. ? But the thing is, my recent order id is only visible because the settings file has been saved since the order was placed: I saved it manually using the ¡®File | Layout Settings | Save settings¡¯ menu entry. ? Thus the question is, when is this file actually saved? Certainly it is saved when you do a tidy exit from TWS/Gateway but certainly not immediately after the placeOrder() call. (The settings file is also uploaded to the IB servers at this point, unless otherwise configured) ? So there is a period, and it may be long, after an order is filled, where closing TWS untidily might mean that the settings file doesn¡¯t get saved. And so next time you connect to the API, the nextValidId() will be incorrect. Killing the process rather than using the normal exit method would do it. ? Of course one doesn¡¯t normally close down TWS/Gateway in this undisciplined fashion (I hope!), but I¡¯ve hit this problem a couple of times with the paper-trading TWS due to carelessness, power failures etc. My protection when connecting is to round up the nextValidId() to a number that couldn¡¯t conceivably have been reached in the previous session: I add 10000 to it, because I¡¯m very certain I will never exceed 10000 orders in a single day. ? By the way, the settings file also contains a mass of other stuff, for example layouts, open charts etc, and if the program is shut down untidily any such changes during the session are lost. That¡¯s why IBC can be configured to automatically save the settings on a user-specified schedule. ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of bespalex
Sent: Tuesday, November 28, 2023 4:02 PM To: [email protected] Subject: [TWS API] Duplicate OrderID ? IB doesn't cease to amuse. I am baffled. |
Re: Order rejected - reason:Message must contain field # 44
Yes I can see now LMT BUY 100.000000@0?zero price somehow. Thank you!
|
Re: Order rejected - reason:Message must contain field # 44
"" in the error message refers to the FIX protocol TWS/IBGW use when they communicate with IBKR. It's a "price" field, so you need to check your order objects for any missing or malformed price value. ´³¨¹°ù²µ±ð²Ô On Tue, Nov 28, 2023 at 10:31 AM, bespalex wrote:
|
Re: Duplicate OrderID
We don't have enough detail about your setup to give you a definitive answer, but my best guess is that your client does not properly manage the next valid orderId. It is not sufficient that you simply start at the "nextValidId" you receive during connection and increment from there. That is necessary but not sufficient. Take another look at the "", especially the second paragraph where the other (and often overlooked) condition is described as:
When your client connects to TWS/IBKR, TWS API sends you the next valid orderId based upon the client ID you use. If that clientId has previously been used (does not matter how long ago), nextValidId will be one larger than the orderId of the last order that clientId has placed (whenever that was). If the clientId has never been used or no orders have been placed with that clientId, nextValidId will likely be 1. You can now place orders by keeping an internal nextOrderId that you increment for each order you place. Until you receive an openOrder or orderStatus callback for an order that was placed by a different client or manually in TWS. At that point in time you have to set your internal nextOrderId counter to:
So your next orderId must be higher than the id for any order your client has placed or has been related to. ´³¨¹°ù²µ±ð²Ô On Tue, Nov 28, 2023 at 10:02 AM, bespalex wrote: IB doesn't cease to amuse. I am baffled. |
Order rejected - reason:Message must contain field # 44
Got multiple errors like this lately: ibapi.client: SENDING placeOrder b'\x00\x00\x01Z3\x00161494\x000\x00UVXY\x00STK\x00\x000.0\x00\x00\x00SMART\x00\x00USD\x00\x00\x00\x00\x00BUY\x00100.0\x00LMT\x000.0\x00\x00\x00\x00\x00\x000\x00\x001\x000\x000\x000\x000\x000\x000\x000\x00\x000\x00\x00\x00\x00\x00\x00\x00\x000\x00\x00-1\x000\x00\x00\x001\x00\x00\x000\x000\x00\x000\x00\x00\x00\x00\x00\x000\x00\x00\x00\x00\x000\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000\x00\x00\x000\x000\x00\x00\x000\x00\x000\x000\x000\x000\x00\x001.7976931348623157e+308\x001.7976931348623157e+308\x001.7976931348623157e+308\x001.7976931348623157e+308\x001.7976931348623157e+308\x000\x00\x00\x00\x001.7976931348623157e+308\x00\x00\x00\x00\x000\x000\x000\x00\x002147483647\x002147483647\x000\x00\x00\x00' ? |
Re: Duplicate OrderID
¿ªÔÆÌåÓýFirst of all this is really weird case. I never seen this type of issue. Are you waiting for next valid order id event before starting with other things? ? But if you really want to Hack it then use Different Client ID every day, so that they can never collide for a week. ? From: [email protected] <[email protected]> On Behalf Of bespalex
Sent: Wednesday, November 29, 2023 12:02 AM To: [email protected] Subject: [TWS API] Duplicate OrderID ? IB doesn't cease to amuse. I am baffled. |
Duplicate OrderID
IB doesn't cease to amuse. I am baffled.
Yesterday, the last executed orderId was 161178. Today,??ibapi.wrapper: ANSWER nextValidId {'orderId': 161044} No need to say, this caused a major headache today, as orderIds eventually started to coincide with already executed yesterday's ones that are still in my open position. How is this possible? What can be done to prevent this? |
interested in your experience migrating to .NET
I ran unattended for a few years to 2020 and I am interested in doing so again with a different algorithm and substantially different code-base. I used to use Linode, Ubuntu + ubuntu desktop, vnc4server, and Java. As you can see my costs were low. This arrangement was suitable but a little unsatisfactory. To list some disadvantages, I would say that this arrangement seemed risky to me since Linode didn¡¯t offer the GUI desktop for Ubuntu by default and if I recall correctly, IB Gateway and IB TWS didn¡¯t work without them. Defaults are important to me since defaults are better supported and I know I am making a generalization but sometimes generalizations are a guide to risk. The other disadvantage, and I only say this from a personal point of view, is that I like the Visual Studio C# combination better than the Eclipse Java combination. One of the positives is that Linode pricing seemed easier to understand than AWS and Azure. I am researching a switch to .NET. If the community has any experience with making a change like this, I would appreciate comments from the community on how much your costs increased on a percentage basis. Linode has some general cost guidance but of course a community that uses TWS/Gateway unattended would have more specific knowledge that would help me. |
Delay up to 5 minutes after FX order is filled for balance to be updated in TWS
I'm used to TWS reporting the position sizes and position lists in a delayed manner, say 2-3 seconds after reporting that an entry or exit order was filled, but recently it's been more like 5 minutes when trading FX in a paper trading account. Does it normally take up to 5 minutes for TWS to report changes to FX balances?
|
Re: Edge browser says Client Portal API is not secure
Nevermind... Apparently the documentation folder in the unzipped file is not the only documentation. Elsewhere IB says... "It is important to note that the connection is only insecure between the user to their own localhost. In other words, only the connection on the local computer is insecure. However, requests sent from the locahost to Interactive Brokers will maintain a secure connection." |