Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: TestCppClient doesn't compile for Ubuntu 20.04 (focal)
This fix works but only if I upgrade to Ubuntu 22.04.3 LTS.
libintelrdfpmath-dev isn't available for older versions of Ubuntu. |
Re: TWS api multiple similar orders submission delays
? @amar
I do not wait for anything, the only thing I do is my order send function is synchronized: static synchronized void sendOrderAndIncrement(Order order, EWrapperImpl wrapper, Contract contract, EClientSocket m_client, int tickerId) { ?
? ? ? ? if (order != null) {
? ? ? ? ? ? int currentOrder = wrapper.currentOrderId;
? ? ? ? ? ? LAST_ORDER = currentOrder;
? ? ? ? ? ? m_client.placeOrder(currentOrder, contract, order);
? ? ? ? ? ? wrapper.currentOrderId++;
? ? ? ? ? ? logAndPrintInfo(contract.symbol() + " PLACING " + tickerId + " ORDER - COMPLETED");
? ? ? ? } else {
? ? ? ? ? ? log("ORDER IS NULL FOR: " + contract.symbol());
? ? ? ? }
?
? ? } This happens all within 5ms for all orders, but first??"open order:" message appears only after 1.5s+ I do not trade stocks, but options, maybe thats a difference?? This is my api client log for one option: 21:59:55:624 <- 3-44-0-SPX-OPT-20231005-4250.0-C-100-SMART--USD--SPXW---BUY-3.0-LMT-15.2--DAY---O-0--1-0-0-0-0-0-0-0--1.7976931348623157E308--------0---1-0---0---0-0--0------0--2147483647---0-2147483647----------0---0-0---0--0-0-0-0--1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-0---------0-0-0-- 21:59:56:835 -> --v5-44-652138644-SPX-OPT-20231005-4250-C-100-SMART-USD-SPXW? 231005C04250000-SPXW-BUY-3-LMT-15.2-0.0-DAY--UXXXXX-O-0--36-1246696869-0-0-0--1246696869.0/UXXXXX/100----------0---1-0-------0-0-0--3-0-0--0-0--0-None--0----?-0-0--0-0------0-0-0-----0--IB-0-0--0-0-PreSubmitted-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308------0-0-0-None-1.7976931348623157E308-6.2-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-0----0-1-0-0-0-----3-44-PreSubmitted-0-3-0-1246696869-0-0-36--0- 21:59:58:159 -> --r5-44-652138644-SPX-OPT-20231005-4250-C-100-SMART-USD-SPXW? 231005C04250000-SPXW-BUY-3-LMT-15.2-0.0-DAY--UXXXXX--0--36-1246696869-0-0-0--1246696869.0/UXXXXX/100----------0---1-0-------0-0-0--3-0-0--0-0--0-None--0----?-0-0--0-0------0-0-0-----0--IB-0-0--0-0-Submitted-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308------0-0-0-None-1.7976931348623157E308-6.2-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-1.7976931348623157E308-0----0-1-0-0-0----*3-44-Submitted-0-3-0-1246696869-0-0-36--0- so after I call placeOrder, it takes 1200ms to make it into PreSubmitted status, then another 1300ms to move it into submitted status |
TestCppClient doesn't compile for Ubuntu 20.04 (focal)
Running make on the newly-downloaded TWS SDK produces the following:
g++ -pthread -Wall -Wno-switch -Wpedantic -Wno-unused-function -std=c++11 -I../../../source/cppclient/client -I../../../source/cppclient ../../../source/cppclient/client/*.cpp ./*.cpp ../../../source/cppclient/client/lib/libbid.a -oTestCppClientStatic collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped compilation terminated. /home/linuxbrew/.linuxbrew/bin/ld: BFD (GNU Binutils) 2.37 assertion fail reloc.c:8489 ../../../source/cppclient/client/lib/libbid.a(bid64_string.o):bid64_string.c:(.pdata+0x0): dangerous relocation: make: *** [makefile:11: TestCppClientStatic] Error 1 I've seen a few threads (i.e. this and ) that recommend swapping the IBKR bundled libbid.a or libbid.so with libintelrdfpmath-dev . The only problem is that that library isn't available for Ubuntu 20.04 (focal). Is there any way I can build with something else, or with the attached libraries? |
Re: Implied Volatility of an EXPIRY
开云体育Sorry, I just realise that I misread your mail.
I thought that you were asking about IV, but you are talking about historical volatility. You get the 21 trading trailing days return standard deviation. I have calculated and it matches.
|
Re: Implied Volatility of an EXPIRY
开云体育Hi Bart D,I think there is an error there. HV stands for historical volatility, and historical volatility is calculated as the standard deviation of returns.? So you get price data, for TRADES bars = reqHistoricalData(contract,endDateTime="",durationStr="2 Y", barSizeSetting="1 day", whatToShow=“TRADES", useRTH=True, formatDate=1, keepUpToDate=False,chartOptions=[]) Then HV is? log_returns =?np.log(df.close?/?df.close.shift(1)).dropna() hv = log_returns.rolling(window=21).std() * np.sqrt(252) Hope it makes sense.
|
Re: Implied Volatility of an EXPIRY
开云体育Hi,
Wha do you mean by IV of a specific chain? You get IB by asset, expiration and strike, that’s calculated using a model, I don’t know ?what model uses IBKR, but it’s not a “model free” calculation like VIX
|
Re: Implied Volatility of an EXPIRY
开云体育You can get IVs directly from the API and calculate any HV you want from that.?
Here is how I calculate various HVs, eg for S&P500 (I am using ib_insync so some calls may look different than the native API calls):
How IB calculates the option-implied-volatility is not clear to me but in any case the various HVs I calculate correspond well to what is shown in TWS.
On Oct 3, 2023 at 1:26?AM -0700, ebtrader via groups.io <jsiddique@...>, wrote:
|
Re: How to estimate order execution impact on excess liquidity?
Does the "Check Margin" feature in the TWS Order Entry form give you the information you are looking for? In that case, take a look at the documentation for via TWS API and the flag of the class. 闯ü谤驳别苍 On Mon, Oct 2, 2023 at 05:43 PM, Lipp F. wrote:
Assuming that an order execution has $cash_balance_delta?impact on cash balance and $margin_delta?on margin, is it correct to assume that the impact on?excess liquidity is$excess_liquidity_delta =? $cash_balance_delta - $margin_delta?Is this accurate? Is there any way to have IB estimate?excess liquidity prior to the order execution instead? TIA. |
Re: Implied Volatility of an EXPIRY
I would save options prices each week before they expire as well as the underlying prices.? That way you should be able to get a historical IV over time using Black Scholes to back into to the IV.? If you need help with the code, feel free to email me and I am happy to help with that.? Ebtrader On Mon, Oct 2, 2023 at 9:07 AM Michael Sutton <mikesutton@...> wrote: Resurrecting an old thread as I have a similar question. |
Re: C++ preventing EReader reading when socket is closed
@Gordon, @Buddy,
"mountain"?? : hardly. There is no impact to existing code with this proposed change (tested). I am simply adding functionality that allows users to manually stop the thread that they started manually.? In fact I can leave the destructor of EReader the same as it was without swapping anything and just create a new function "stop()" which will allow users to disconnect cleanly if they desire to, (Note to Gordon on your concern about the initial use of EReader during the connection, this is what the "if (m_hReadThread)" statement takes care of in the original TWS API code which is still there in my proposed change.) Let me remind you that the current situation results in a 509 error, which is basically the API's way of saying something bad happened and I do not know what it is. Your code must be bad, which is not the case here. It is the API code that is bad. Now that we know what causes it, we can probably live with it and safely ignore it, but personally I don't like that sort of situation. If the developers intended to use this way of disconnecting the socket, then they should have properly taken care of the error message it creates. The fact that they didn't means that what they coded was unintentional and therefore is clearly a bug. A bug needs to be fixed. However, I realise changing (adding to) the interface will make the C++ interface different than the other languages which is probably not desirable. The only way to correct this and make the existing interface the same is to create an EMutex variable which is shared by both EReader and EClientSocket (suggest using a composition pattern here). Changes to the m_isAlive variable need to be locked by the mutex as well as inside the "while(m_isAlive)" loop. This is a larger code change and needs more care to be done right but it is not that difficult and I have implemented it successfully as well. In fact using EMutex here does not slow the loop down (checking the mutex is as simple as reading a flag) since the only time it is ever locked is when we are disconnecting which means speed is not a "critical trading" issue. I agree it is good to have this thread capture this discussion for the record but I will definitely raise this problem to the coders as I still firmly believe this to be a bug. I do not wish to have to fix this myself every time there is a new API update. |
Re: C++ preventing EReader reading when socket is closed
Yeah, I see most of this as making a mountain out of a molehill. It strikes me, largely, as a misunderstanding; much like issuing a SIGKILL but expecting SIGTERM. If you are familiar with unix signal processing you know that SIGKILL is immediately forced upon the process by the OS and the process my be left in an untidy state. SIGTERM, on the other hand, gives the process an opportunity to clean up and exit gracefully. Since the API code is readily available, folks can implement their own version of EReader which suits their preference in this regard. Therefore the distinction becomes moot. There may be some chance of acceptance for a minor pull request which, e.g., swaps the calls to the thread join and socket disconnect. But, even this could be seen as a dog chasing it's own tail since the argument would merely come down to the dislike of a default. Moreover though, when you consider that the code for EReader hasn't changed in years... even a small change becomes unlikely. And, the suggestion of anything "major", like an intermediate "stop" method, becomes far fetched IMHO. It's certainly an interesting nuance but probably better addressed by documentation alone. At least we have this thread of conversation now for reference :-) |
How to estimate order execution impact on excess liquidity?
Assuming that an order execution has $cash_balance_delta?impact on cash balance and $margin_delta?on margin, is it correct to assume that the impact on?excess liquidity is
$excess_liquidity_delta =? $cash_balance_delta - $margin_delta?Is this accurate? Is there any way to have IB estimate?excess liquidity prior to the order execution instead? TIA. |
Re: C++ preventing EReader reading when socket is closed
I like evolution, so I may be wrong but here I am not sure I would flag this as a bug. |
Re: Implied Volatility of an EXPIRY
Resurrecting an old thread as I have a similar question.
I think I've convinced myself that the way the "IV of a specific chain" is calculated is the same way that the VIX is calculated as illustrated in this white paper:??There is no Black-Scholles of any sort going on with this calculation.? That means that from the API, it's possible to calculate the _current_ IV of a specific expiry; but not the _history_ of the IV that's shown in Volatility Lab. Has anyone figured out a way to do that?? (I suspect the answer is it's not possible.? If that's the case, are people using IVolatility.com, which looks like there is no longer any free component.? What about getvolatility.com?) My other question is what exactly is returned when you request historical volatility from the API?? My assumption is that it is something similar to the VIX calculation where the two expiries closet to 30 days are interpolated to that 30 day mark, although I haven't tried to do a sample calculation to confirm. |
Re: APIPending status?
Colin Beveridge
Thanks, 闯ü谤驳别苍, being less of a doofus with the contract definition seems to have helped.
?
(I had seen that documentation -- I stand by my opinion that it could be better documented; I think that "Uncommonly received" is a less helpful message than, say, "if this occurs repeatedly, check you are sending a properly-defined contract". In any case, I hope future people hitting the same problem[^0] will find this thread and find it helpful.)[^0]: Even if it's just me, I'm ok with that. |