Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Is it able to auto reconnect?
If the API shows the error messages,is it able to auto reconnect by code?
I used to detect the gap between now and the last data received time and?raise EOFError. I am seeking new method to do it.Any ideas is welcome. -------error message------- 2022-08-18 20:06:28 Error: ?-1 ? 2157 ? Sec-def data farm connection is broken:secdefnj
2022-08-18 20:06:28 Error: ?-1 ? 2105 ? HMDS data farm connection is broken:ushmds
2022-08-18 20:06:32 Error: ?-1 ? 2103 ? Market data farm connection is broken:cashfarm
2022-08-18 20:06:33 Error: ?-1 ? 2103 ? Market data farm connection is broken:eufarm
2022-08-18 20:07:09 Error: ?-1 ? 2105 ? HMDS data farm connection is broken:cashhmds
2022-08-18 20:07:09 Error: ?3 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?6 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?2 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?1 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?7 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?5 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?0 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 20:07:10 Error: ?4 ? 10182 ? Failed to request live updates (disconnected).
2022-08-18 22:43:27 Error: ?-1 ? 2103 ? Market data farm connection is broken:usfarm
2022-08-18 22:43:52 Error: ?-1 ? 2103 ? Market data farm connection is broken:usfarm
2022-08-18 22:43:54 Error: ?-1 ? 2103 ? Market data farm connection is broken:eufarm
2022-08-18 22:43:55 Error: ?-1 ? 2103 ? Market data farm connection is broken:cashfarm
2022-08-18 22:43:56 Error: ?-1 ? 2157 ? Sec-def data farm connection is broken:secdefnj
2022-08-18 22:43:58 Error: ?-1 ? 2105 ? HMDS data farm connection is broken:ushmds
2022-08-18 22:45:21 Error: ?-1 ? 2157 ? Sec-def data farm connection is broken:secdefnj
2022-08-18 22:45:21 Error: ?-1 ? 2103 ? Market data farm connection is broken:cashfarm
2022-08-18 22:46:06 Error: ?-1 ? 2105 ? HMDS data farm connection is broken:cashhmds
2022-08-18 22:46:11 Error: ?-1 ? 2103 ? Market data farm connection is broken:eufarm
-- ------ Forex trader David Liao |
|
Re: Help for an old coder. API 10.17 Bar class.
开云体育Sorry Carlos, I’ve been through all this before but I’d forgotten how to do this. ? IB’s handling of the decimal problem in the ActiveX API is sadly lacking. It has to be supplemented by additional functions which should be in the API but aren’t. If you look at the VBA code in the Excel ActiveX demo, you’ll find a code module called Utils.bas that has a couple of relevant functions, in particular one called SetVariantDecimal. This that takes a string and returns the required object to use in properties like totalQuantity. ? The following function is based on that, but I think it’s better named and is more applicable because it can take any variant as an argument: ? Public Function CreateDecimalObject(value As Variant) As Object ??? Dim collection As New collection ??? collection.Add CDec(value) ??? Set CreateDecimalObject = collection End Function ? Ideally you’d add this function to a module (not a class module) so that it would be accessible everywhere within your code. But if you only need it within a single class, you could just add it to that class (in which case it should be Private rather than Public). ? So now your failing piece of code would look like this: ? ??????? O.totalQuantity = CreateDecimalObject(quantity) ? ? [Comment: if you think this CreateDecimalObject function looks very strange, you’re right! I modified IB’s API code to use a new class called BoxedDecimal, so that everywhere where IB has a Variant to hold a size value, there is instead a BoxedDecimal instead: this is much more documentary, because you can see exactly what you’re dealing with without having to guess. It also makes the ActiveX API much easier to use from C# or Visual Basic .Net. I offered this to IB as an improvement? (see if you have access to the API repository), but they have shown no interest…] ? ? From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 18 August 2022 15:00 To: [email protected] Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class. ? Hi Richard, Run-time Error '424' Object required |
|
Re: Help for an old coder. API 10.17 Bar class.
Hi Richard,
Yesterday after I email here I found this option and try that. The same error happens O.totalQuantity = CDec(quantity) returns Run-time Error '424'
Object required Somehow I need to create an object that is a C# decimal or so. If you guys have any other ideas let me know. Thank you very much for all the help. Carlos |
|
Re: Help for an old coder. API 10.17 Bar class.
开云体育Try this: ? ??????? O.totalQuantity = CDec(quantity) ? ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 18 August 2022 05:58 To: [email protected] Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class. ? Hello, ? Well, here is the problem number 2. Data coming from the API to VB as a variant works but from VB to the API I got this problem ? The IOrder class that I create using the call CreateOrder has a property totalQuantity. ? The API wants to receive a decimal or an object. ? I try to create the variable as variant, as object cannot figure how to make it work. ? ? ? ? ? Dim O As TWSLib.IOrder ? ? ? ? Set O = ORDERFORM.Tws1.CreateOrder ? ? ? ?? ? ? ? ? O.orderType = orderType 'LMT,MKT ? ? ? ? O.lmtPrice = price ? ? ? ? O.auxPrice = 0 ? ? ? ? If orderType = "STP" Then ? ? ? ? ? ? O.auxPrice = Price2 ? ? ? ? ? ? O.outsideRth = True ? ? ? ? End If ? ? ? ? O.action = action ? ? ? ? O.totalQuantity = quantity? (here is the crash) ? totalQuantity wants a decimal, actually the error message says? ? Run-time Error '424' Object required ? The API activeX code shows the toralQuantity as decimal ? Any idea how to go around this problem? ? Thank you for the help. ? |
|
Re: Help for an old coder. API 10.17 Bar class.
Hello,
?
Well, here is the problem number 2.
Data coming from the API to VB as a variant works but from VB to the API I got this problem
?
The IOrder class that I create using the call CreateOrder has a property totalQuantity.
?
The API wants to receive a decimal or an object.
?
I try to create the variable as variant, as object cannot figure how to make it work.
?
? ? ? ? Dim O As TWSLib.IOrder
? ? ? ? Set O = ORDERFORM.Tws1.CreateOrder
? ? ? ??
? ? ? ? O.orderType = orderType 'LMT,MKT
? ? ? ? O.lmtPrice = price
? ? ? ? O.auxPrice = 0
? ? ? ? If orderType = "STP" Then
? ? ? ? ? ? O.auxPrice = Price2
? ? ? ? ? ? O.outsideRth = True
? ? ? ? End If
? ? ? ? O.action = action
? ? ? ? O.totalQuantity = quantity? (here is the crash)
?
totalQuantity wants a decimal, actually the error message says?
?
Run-time Error '424'
Object required
?
The API activeX code shows the toralQuantity as decimal
?
Any idea how to go around this problem?
?
Thank you for the help.
? |
|
Re: Help for an old coder. API 10.17 Bar class.
Thank you very much joanmarcel119 and Richard.
For now the variant type use on histvolume and WAP worked, it did compile and the part that gets real time data and historical data seems to be working OK. I will do more testing make sure all works and then go to the order processing part that is more complicate, hope the variant solution will work there also. The for now the decimal type using variant type is a solution for this problem. Thank so much for the help on this. Richard, thank you for clarifying this "Regarding the Bar class, there is no such thing in the ActiveX API (there never has been). This is in the C# API, but is not exposed via the ActiveX API." I was confuse on where was the Bar class, now I know. Thank you. Carlos 2 abd |
|
Re: Help for an old coder. API 10.17 Bar class.
开云体育In order to support crypto contracts, IB have changed many ‘size’ parameters and properties (for example in TickSize and HistoricalData events) from 32-bit integers (ie Long in VB6) to Decimal type. ? In .Net, the Decimal type can be easily used exactly the same as any other numeric type. So if you’re using the C# API from Visual Basic.Net you can declare decimal variables, and use them, in the obvious way: ? Dim size As Decimal = 499.7366214562341954 ? But VB6, although it provides some support for Decimal values, is less friendly. Here’s what the VB6 documentation has to say about the Decimal type: ? Decimal variables are stored as 96-bit (12-byte) signed integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28. With a scale of 0 (no decimal places), the largest possible value is +/-79,228,162,514,264,337,593,543,950,335. With a 28 decimal places, the largest value is +/-7.9228162514264337593543950335 and the smallest, non-zero value is +/-0.0000000000000000000000000001. ? Note?? At this time the Decimal data type can only be used within a Variant, that is, you cannot declare a variable to be of type Decimal. You can, however, create a Variant whose subtype is Decimal using the CDec function. ? For example, the equivalent to the above Visual Basic .Net statement would be: ? Dim size As Variant : size = CDec(499.7366214562341954) ? So the ActiveX API now has lots of Variant values scattered through it wherever there used to be a Long size value (other non-size Long values such as request ids are still Longs). ? So your HistoricalData event handler should now be declared like this: ? Private Sub TWS_historicalData(reqId As Long, date As String, open As Double, high As Double, low As Double, close As Double, volume, barCount As Long, WAP, hasGaps As Long) . . . End Sub ? You’ll need to check all the various events you handle to discover where Longs have been replaced with Variants. The easiest way to do this is either to simply recreate the event handlers in the usual way, or you can use the Object Browser (press F2) to inspect all the various classes and events. ? You don’t have to do anything special to actually use these values in VB6. You can do all the usual arithmetic operations on them, and because Variants carry the actual data type internally the VB6 runtime always knows what kind of value it’s dealing with. ? Regarding the Bar class, there is no such thing in the ActiveX API (there never has been). This is in the C# API, but is not exposed via the ActiveX API. ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of carlos almeida via groups.io
Sent: 17 August 2022 20:39 To: [email protected] Subject: [TWS API] Help for an old coder. API 10.17 Bar class. ? Hello, This looks odd but I have been using the IB API on Visual Basic 6 forever. I have an app that collects data, historical and put orders in the market and works great. I saw this new API 10.17 and as I always do I try it to see what will happen. It is broken now, I did look on the forum here trying to find something about it but could not find. ? Problem is on this new Bar class. For example on the Api 9.7X the function like historicalData would return (ByVal reqId As Long, ByVal date1 As String, ByVal open1 As Double, ByVal high As Double, ByVal low As Double, ByVal close1 As Double, ByVal volume As Long, ByVal barCount As Long, ByVal WAP As Double, ByVal hasGaps As Long) ? Using API 10.17 when I go to the events list and select historicalData event it show a broken all in red historicalData(ByVal reqId As Long, ByVal date1 As String, ByVal open1 As Double, ByVal high As Double, ByVal low As Double, ByVal close1 As Double, ByVal volume As Long, ByVal barCount As Long, ByVal WAP As Double, ByVal hasGaps As Long) ? There is nothing with Bar. Naturally the code does not work. ? The API documentation shows the historicalData event as void historicalData(int reqid, Bar bar) ? I change the event return to historicalData(ByVal reqId As Long, bar1 as Bar), the red disappear, but I cannot find class bar in the API. ? For example on contract I use IContract and then the function createContract to create and and use that contract class. ? On Bar I cannot find nothing for BAr inside the API. ? I try to create a Bar class inside the VB code with the definition on the API documentation but naturally it did not work, I think I need to use the Bar class from the API, but do not see how to get it. ? Anyone has any clue what is going on here? I know that is not much information but maybe someone had to deal with something similar. ? Thank you ? |
|
Re: Help for an old coder. API 10.17 Bar class.
Carlos, prueba esto, try this: (ByVal reqId As Long, ByVal histDate As String, ByVal histOpen As Double, ByVal histHigh As Double, ByVal histLow As Double, ByVal histClose As Double, ByVal histVolume As Variant, ByVal barCount As Long, ByVal WAP As Variant, ByVal hasGaps As Long) I took a look into how the?historicalData wrapper method is declared in the activex sample provided by IB and maybe this also works with visual basic as they are related. Hope this helps El mié, 17 ago 2022 a las 21:38, carlos almeida via (<ctalmeida=[email protected]>) escribió:
|
|
Help for an old coder. API 10.17 Bar class.
Hello,
This looks odd but I have been using the IB API on Visual Basic 6 forever.
I have an app that collects data, historical and put orders in the market and works great.
I saw this new API 10.17 and as I always do I try it to see what will happen.
It is broken now, I did look on the forum here trying to find something about it but could not find.
?
Problem is on this new Bar class.
For example on the Api 9.7X the function like historicalData would return (ByVal reqId As Long, ByVal date1 As String, ByVal open1 As Double, ByVal high As Double, ByVal low As Double, ByVal close1 As Double, ByVal volume As Long, ByVal barCount As Long, ByVal WAP As Double, ByVal hasGaps As Long)
?
Using API 10.17 when I go to the events list and select historicalData event it show a broken all in red historicalData(ByVal reqId As Long, ByVal date1 As String, ByVal open1 As Double, ByVal high As Double, ByVal low As Double, ByVal close1 As Double, ByVal volume As Long, ByVal barCount As Long, ByVal WAP As Double, ByVal hasGaps As Long)
?
There is nothing with Bar. Naturally the code does not work.
?
The API documentation shows the historicalData event as void historicalData(int reqid, Bar bar)
?
I change the event return to historicalData(ByVal reqId As Long, bar1 as Bar), the red disappear, but I cannot find class bar in the API.
?
For example on contract I use IContract and then the function createContract to create and and use that contract class.
?
On Bar I cannot find nothing for BAr inside the API.
?
I try to create a Bar class inside the VB code with the definition on the API documentation but naturally it did not work, I think I need to use the Bar class from the API, but do not see how to get it.
?
Anyone has any clue what is going on here?
I know that is not much information but maybe someone had to deal with something similar.
?
Thank you
? |
|
Re: Which Java version to use?
Thank you for the recommendations. I'm using Netbeans 8.2 (yes, a very old version). But I fear that Ubuntu somehow changed the Java version when it upgraded from 20.04 to 22.04. Maybe a tool like Maven is able to prevent this in the future. I would have to investigate Maven as I have only heard the name, but am totally unaware of what it is and does.
|
|
Increasing the permitted number of simultaneous tick-by-tick subscriptions
Hi,?
I'm currently making use of the Tick-by-tick API in a program I'm working on.
At the moment I believe I'm able to have 5 simultaneous subscriptions. But would like to increase this to 20.
?
I read that the maximum number of simultaneous tick-by-tick subscriptions allowed for a user is determined by the same formula used to calculate maximum number of market depth subscriptions Limitations.
?
Am I right in thinking that to obtain an additional 15 simultaneous subscriptions I would need 1500 more market data lines and that it would ultimately cost greater than 300 euro per month?
?
Also, if the above is correct are there any cheaper alternatives that would allow me to have 20 simultaneous subscriptions?
?
Thanks,?
Bryan
? |
|
Re: How do I get portfolio delta and theta values via the TWS API
开云体育"Probably
check the tickId you use: 10,11,12 or 13. One of them is documented that it should return the same as what is shown on TWS."
I
was not checking the field.? I had assumed that there was only one Greek computation.? Turns out, as your link shows, there's actually multiple and the callback is called several time for each request.? 13 looks like the one I want to use and ignore the others.?
That gives me numbers almost identical to what I see in TWS.
From: [email protected] <[email protected]> on behalf of bart decanne.com <bart@...>
Sent: Tuesday, August 16, 2022 3:44 PM To: [email protected] <[email protected]> Subject: Re: [TWS API] How do I get portfolio delta and theta values via the TWS API ?
Probably check the tickId you use: 10,11,12 or 13. One of them is documented that it should return the same as what is shown on TWS. See:
|
On Aug 16, 2022, at 3:20 PM, Crow via groups.io <aaroncook394@...> wrote:
Thanks?Bart,??????It sounds like what IB calls "Portfolio Delta", referring to the column that can be added to the position window is not really "portfolio" delta, but rather just position delta.??
Greeks Columns. To add Greeks columns to the Quote Monitor or other window, hold your mouse over an existing Market Data column heading and click the green "+" sign to insert column.
Near the upper right corner of the screen, I also have a portfolio delta and theta which I think represents those components for my entire portfolio.? Computing the position greeks is straight-forward, but I guess my question is why is the tick computation returning infinity when TWS is showing non-infinite Greeks.? You might be right that it could be looking at something else, but I should be able to get the exact same greeks from the API as TWS is showing.? For positions that are not so worthless / out of the money, the result of the API greeks from tick calculation is close to what TWS shows.
From:?[email protected]?<[email protected]> on behalf of bart??<bart@...>
Sent:?Tuesday, August 16, 2022 2:55 PM
To:?[email protected]?<[email protected]>
Subject:?Re: [TWS API] How do I get portfolio delta and theta values via the TWS API?More likely probably is that they call most recent historical data to show in TWS if no current data is available…
I believe TWS somehow stores the last data so that when it does not receive current valid data it displays the buffered data.It seems on days with big moves at market open especially, greeks are not available even up to an hour into trading.Similar also for market value or bid/ask prices outside trading hours: you won’t get anything via the API, but TWS still shows it.
On your question for portfolio greeks, I don’t think it’s returned from the API since you get greeks from ticker data (which does not take into account your position in the contract). So you need to calculate portfolio greeks yourself based off the ticker data greeks and your positions. I do this and the result comes out identical to what TWS shows.
I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?
The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.
<Screenshot at 2022-08-16 12-54-56.png>