开云体育

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

Re: Discrepancies between real-time and historical market data

 

Time and sales forensics is your best friend here. This kind of mismatch is not infrequent but I'm not sure any regular pattern could be established. AFAIK IB do not disclose how exactly they source and aggregate their price data so it essentially can only be guessed with some limited certainty what any of these figures mean.

пт, 6 дек. 2024 г., 02:09 xb via <kcbsbo=[email protected]>:

Attached are the logs from my subscription to real-time and historical bar data yesterday. As you can see, there are discrepancies between the 'high' and 'Wap' values in the two datasets. I'm wondering if anyone can explain why this might be occurring. Any insights would be helpful.
?
RealTimeBars: JD,Time:1733404940,Open:36.28,High:36.28,Low:36.28,Close:36.28,Volume:500000000000,Wap:36280000000,Count:1
HistoricalBars: JD,BarData(date=datetime.datetime(2024, 12, 5, 8, 22, 20, tzinfo=backports.zoneinfo.ZoneInfo(key='US/Eastern')), open=36.28, high=36.29, low=36.28, close=36.28, volume=500.0, average=36.282, barCount=1)
?
Thanks?
xb


--
Best,
DS


Re: what time EST is it safe to assume that IB have printed the final close for all symbols EOD

 

thank you. That's the time I am running the cron job to get the historical data.


Re: what time EST is it safe to assume that IB have printed the final close for all symbols EOD

 

Depends on what one deems reasonable here. Anything earlier than 20:00 i.e. the time when the listing exchanges post their definitive closing prints, will not be completely reliable.


чт, 5 дек. 2024 г., 11:28 comicpilsen via <comicpilsen=[email protected]>:

Makes sense but the group would know, through experience, when it's reasonable to see that the US exchanges are printed. I am only interested in the PRINT after the close. It would be nice to think all is done by 16:00 EST but is that reality? Is it 16:05, 16:15... you get the idea. Thanks for the heads up though


--
Best,
DS


Re: Multiple strategies in one account

 

My approach is to use OrderRef's exclusively. I need not and do not trace executions live since my order placements occur regularly within a short time interval each day using various conditional execution features, after which my trading app disconnects from the api and any executions are consequently collected from email flex reports. This approach is super lean and effective unless very quick response to executions is required that cannot be programmed ahead using broker provided conditionals.


пт, 6 дек. 2024 г., 10:54 Edward via <ed.gonen=[email protected]>:

In my?opinion Gordon's suggestion to build your own Position management is the best approach. We've been using that for almost a couple of decades now and it proves itself. I would recommend relying on order status (filled amount etc.) but I guess execDetails is appropriate as well. We chose to use order status call back as it is the most broker-agnostic approach - so if you one day decide to move to another broker, you can reuse your code.

The Position management is a very simple approach - just an in-memory dictionary of positions that you update on order?status change.Just make sure the appropriate semaphores are in place. You may also periodically serialize it to a XML or something file which you can load whenever?you restart your software.

On Fri, Dec 6, 2024 at 6:28?PM Gordon Eldest via <hymagik=[email protected]> wrote:
A "Position" amount could be the aggregated result of multiples orders from multiples strategies. (that is probably your issue)
Seems like you look for a specific "Position" for each strategies on same symbol
This is not a concept that I saw IBKR supporting nor that I see easy to manage from TWS side (TWS handle aggregation of Position)
?
What I do is listen to execDetails to trace how each order did executed (it may execute in slice)
and there you can use orderId to consolidate a "Position" increment/decrement for each strategies. (you can use orderRef too, I use orderId just a safer choice as an index, it avoid mistakes filling custom orderRef that I consider as a "for Human use")
?
execDetails? is pretty powerful, alas transient you have to listen to the call back and store them, and its nearly the only safe method I know to understand what is happening /happened
it work in tandem with completedOrder call back that also report the orderId to better understand your orders completion.
Recommended practice is to crosscheck your execDetails analysis from time to time by fetching your position.
?
If this is just for forensic analysis, take a look at Flex reports, it may allow you to rebuild what happened.
but IMHO I recommend you familiarize yourself with execDetails , you most probably will need it soon.
?
I didn't saw IBRK granulating the API to handle every cases there are too many, but gives all the tools needed to do it yourself.
?
Note:
To better understand why I doubt IBKR will ever handle "sub position" it's interesting to mention the taxes optimization system IBKR offer, that said to avoid looking pedantic.
The underlying mechanism of BUY is more complex than it looks because you become owner of shares (for stocks LONG) that have unique id and this is done at specific purchase dates.
when you SELL, for sake of the example I assume you are LONG, IBKR elegantly does sell starting using the older shares you purchased (you can influence that but default mechanism is tuned for taxes optimization)
This is a hidden level of complexity, that may be to manage as part of your multiple strategies case because as the case maybe, your profit after taxes may depend upon your holding period. (in North America)
So to make your own taxes report matching IBKR taxes report you need to understand that too.
Generally IBKR mechanism improve your work, bad surprise happen mainly when using pyramidal strategies over various period.
?
?
?


--
Best,
DS


Re: Multiple strategies in one account

 

In my?opinion Gordon's suggestion to build your own Position management is the best approach. We've been using that for almost a couple of decades now and it proves itself. I would recommend relying on order status (filled amount etc.) but I guess execDetails is appropriate as well. We chose to use order status call back as it is the most broker-agnostic approach - so if you one day decide to move to another broker, you can reuse your code.

The Position management is a very simple approach - just an in-memory dictionary of positions that you update on order?status change.Just make sure the appropriate semaphores are in place. You may also periodically serialize it to a XML or something file which you can load whenever?you restart your software.

On Fri, Dec 6, 2024 at 6:28?PM Gordon Eldest via <hymagik=[email protected]> wrote:
A "Position" amount could be the aggregated result of multiples orders from multiples strategies. (that is probably your issue)
Seems like you look for a specific "Position" for each strategies on same symbol
This is not a concept that I saw IBKR supporting nor that I see easy to manage from TWS side (TWS handle aggregation of Position)
?
What I do is listen to execDetails to trace how each order did executed (it may execute in slice)
and there you can use orderId to consolidate a "Position" increment/decrement for each strategies. (you can use orderRef too, I use orderId just a safer choice as an index, it avoid mistakes filling custom orderRef that I consider as a "for Human use")
?
execDetails? is pretty powerful, alas transient you have to listen to the call back and store them, and its nearly the only safe method I know to understand what is happening /happened
it work in tandem with completedOrder call back that also report the orderId to better understand your orders completion.
Recommended practice is to crosscheck your execDetails analysis from time to time by fetching your position.
?
If this is just for forensic analysis, take a look at Flex reports, it may allow you to rebuild what happened.
but IMHO I recommend you familiarize yourself with execDetails , you most probably will need it soon.
?
I didn't saw IBRK granulating the API to handle every cases there are too many, but gives all the tools needed to do it yourself.
?
Note:
To better understand why I doubt IBKR will ever handle "sub position" it's interesting to mention the taxes optimization system IBKR offer, that said to avoid looking pedantic.
The underlying mechanism of BUY is more complex than it looks because you become owner of shares (for stocks LONG) that have unique id and this is done at specific purchase dates.
when you SELL, for sake of the example I assume you are LONG, IBKR elegantly does sell starting using the older shares you purchased (you can influence that but default mechanism is tuned for taxes optimization)
This is a hidden level of complexity, that may be to manage as part of your multiple strategies case because as the case maybe, your profit after taxes may depend upon your holding period. (in North America)
So to make your own taxes report matching IBKR taxes report you need to understand that too.
Generally IBKR mechanism improve your work, bad surprise happen mainly when using pyramidal strategies over various period.
?
?
?


Re: Multiple strategies in one account

 

A "Position" amount could be the aggregated result of multiples orders from multiples strategies. (that is probably your issue)
Seems like you look for a specific "Position" for each strategies on same symbol
This is not a concept that I saw IBKR supporting nor that I see easy to manage from TWS side (TWS handle aggregation of Position)
?
What I do is listen to execDetails to trace how each order did executed (it may execute in slice)
and there you can use orderId to consolidate a "Position" increment/decrement for each strategies. (you can use orderRef too, I use orderId just a safer choice as an index, it avoid mistakes filling custom orderRef that I consider as a "for Human use")
?
execDetails? is pretty powerful, alas transient you have to listen to the call back and store them, and its nearly the only safe method I know to understand what is happening /happened
it work in tandem with completedOrder call back that also report the orderId to better understand your orders completion.
Recommended practice is to crosscheck your execDetails analysis from time to time by fetching your position.
?
If this is just for forensic analysis, take a look at Flex reports, it may allow you to rebuild what happened.
but IMHO I recommend you familiarize yourself with execDetails , you most probably will need it soon.
?
I didn't saw IBRK granulating the API to handle every cases there are too many, but gives all the tools needed to do it yourself.
?
Note:
To better understand why I doubt IBKR will ever handle "sub position" it's interesting to mention the taxes optimization system IBKR offer, that said to avoid looking pedantic.
The underlying mechanism of BUY is more complex than it looks because you become owner of shares (for stocks LONG) that have unique id and this is done at specific purchase dates.
when you SELL, for sake of the example I assume you are LONG, IBKR elegantly does sell starting using the older shares you purchased (you can influence that but default mechanism is tuned for taxes optimization)
This is a hidden level of complexity, that may be to manage as part of your multiple strategies case because as the case maybe, your profit after taxes may depend upon your holding period. (in North America)
So to make your own taxes report matching IBKR taxes report you need to understand that too.
Generally IBKR mechanism improve your work, bad surprise happen mainly when using pyramidal strategies over various period.
?
?
?


Multiple strategies in one account

 

Hello,
I need to run several strategies in one account. How do I best keep them apart, unknowing of each other?
I can tag orders using the orderRef field, but as of now, all I can think of is to keep a local database with all information (and maybe reconcile it with IB now and then).
How else can I know which position belongs to which strategy?
Do you have any best practices, or tips, to share?
Thanks,
Peter


Re: No Security definition has been found for the request when running cpp sample code

 

开云体育

Some suggestions:

?

  1. Stop posting these screenshots: they’re almost impossible to read. Try to make life easy for recipients if you want help. Instead, copy the text from the terminal and paste it into your post, or into an attachment. If you really need to show a screenshot, take a high-resolution image and attach the image file.
  2. Make sure your log entries have timestamps. It’s impossible to tell whether all these things happened immediately consecutively, or spread out over time.
  3. The error 1100 means what it says: TWS/Gateway has lost its connection to the IBKR servers. Therefore it can’t process API requests until that connection is restored. It looks like your request was submitted while the connection was broken, so of course you get an error response.
  4. Note that the IBKR test clients are bare minimum demo code, and not production quality, so they don’t handle situations like this. When writing ‘real’ code, you have to pay attention to error conditions and act according – for example, don’t make API calls when there is no connection to TWS, or no connection from TWS to IBKR.

?

Richard

?

From: [email protected] <[email protected]> On Behalf Of xz2872 via groups.io
Sent: 06 December 2024 02:51
To: [email protected]
Subject: Re: [TWS API] No Security definition has been found for the request when running cpp sample code

?

runnig the test client multiple times gives different results..


Re: No Security definition has been found for the request when running cpp sample code

 

It might be my eyes, but the pictures you post are too small to read. And when zooming in they become blurry, thus unreadable.


Discrepancies between real-time and historical market data

 

Attached are the logs from my subscription to real-time and historical bar data yesterday. As you can see, there are discrepancies between the 'high' and 'Wap' values in the two datasets. I'm wondering if anyone can explain why this might be occurring. Any insights would be helpful.
?
RealTimeBars: JD,Time:1733404940,Open:36.28,High:36.28,Low:36.28,Close:36.28,Volume:500000000000,Wap:36280000000,Count:1
HistoricalBars: JD,BarData(date=datetime.datetime(2024, 12, 5, 8, 22, 20, tzinfo=backports.zoneinfo.ZoneInfo(key='US/Eastern')), open=36.28, high=36.29, low=36.28, close=36.28, volume=500.0, average=36.282, barCount=1)
?
Thanks?
xb


Re: reqRealTimeBars: data stops receiving for after-hour session

 

Please DO NOT delete messages. This topic is now useless for anyone searching the archives since your original problem statement and part of the discussion is gone.

闯ü谤驳别苍

?

On Fri, Dec 6, 2024 at 01:17 AM, xb wrote:

Thank you all guys, this issue has been resolved.


Re: reqRealTimeBars: data stops receiving for after-hour session

 

Thank you all guys, this issue has been resolved.


Re: No Security definition has been found for the request when running cpp sample code

 

runnig the test client multiple times gives different results..


Re: No Security definition has been found for the request when running cpp sample code

 

Thanks for the reply richard.
? When I send requests to the ib server, sometimes the data returns just fine, sometimes I get error 'Connectivity between IBKR and Trader Workstation has been lost' followed by? 'No security defintion has been found for the request'. I'm wondering what's causing this? and how should I handle this?


Re: Purebasic and TWS

 

开云体育

Tradiator writes:

?

‘What has happened since then that interfacing to IB has become as difficult as climbing the Everest mountain!’

?

I think that’s a little unfair. If you use the ActiveX API, it’s still just as easy, except that you don’t host it on a form – thankfully, because that was never sensible. You just have to instantiate it like any other object with the New operator. Wiring up events in Visual Basic.Net is just as easy as it was in VB6, and more flexible. You can see all this in the ActiveX sample I linked to earlier.

?

The ActiveX API also has the benefit that events are fired on the main program thread, so that there is no need to be concerned with threading issues, and the UI can be accessed and modified directly. Though of course you can easily offload processing onto another thread where needed, and the async facilities in .Net make asynchronous working a delight.

?

It’s certainly true that it’s more complex when using the CSharp API. I think there were some bad design decisions back in 2015, and I was fairly vocal about them on the GitHub repository, but my arguments fell on deaf ears. But it’s all water under the bridge, and it’s really not that hard to get it going. Certainly not in the Everest league (I went trekking there in 1984, up to 18000 feet, just mindblowing…).

?

Richard


Re: Purebasic and TWS

 

@Richard L King
?
> So if no-one objects, I’ll post that response here in due course (in case it might be useful for someone else in future), and I can then follow up privately with @Tradiator if he wants to try my suggestion.

? ? ? ? Richard, I would be very happy to try your solution.
? ? ? ? Thanking you in advance.
?


Re: Purebasic and TWS

 


@Gordon Eldest
?
> ...I feel the need to share the feeling that you are "swimming against the flow".
? ? About 20 years ago I played a bit with the IB interface with VB6. It was as simple as dropping an .OCX control on a form and then calling its procedures. As simple as that!
? ? I had been able to request data and place orders in a very short time.
What has happened since then that interfacing to IB has become as difficult as climbing the Everest mountain!
For now, I just expected things to be as simple, or just slightly more complicated.
?
> 2- Although this business require well designed and safe code, a loosely type language like Basic is not a way to make your future life simple.
> You also increase the odd of uncontrolled polymorphic calls that could create hard to diagnose side effect.
> If your aren't familiar with C++ from your embedded system experience, go for Java, surely a strongly type language and also the best portable solution (I wonder why do you need to design a cross platform, solution)
? ? I am just beginning with Purebasic but I have read that it could use "strongly typed variables". As I am a C programmer I prefer those type of variables of course.
?
> 3- I don't understand your terminology, what IBKR codes are you calling the "windows socket solution" ?
> hints: the IBKR Client code sample ?
? ? Portions of code that I have found here and there, not supplied by IB.
> Where did you get the "TWSlib.dll" ? I just don't remember if IBKR does supply a precompiled binary.
> note: this may show how difficult it could be to give help if you don't comply with a standardized terminology, by default the IBKR API convention
? ? 2 precompiled files were supplied with the TWS API version that I recently downloaded (one for CPP I think).
?
> Last:
> Why don't you consider a mix with another REST data oriented vendor and using IBKR Web API (a REST API) ?
? ? This is the first time I hear about REST. Unfortunately for my current project, I am an electronician and not a computer scientist. There have been so many evolutions for the past 20-30 years.


Re: Purebasic and TWS

 

开云体育

@TRadiator

?

This is in response to your post earlier today. Your statements are quoted in blue, followed by my replies.

?

I am sorry to be a bit stubborn but I prefer to start in Purebasic. Might change later eventually.

?

Well, all the advice you’ve received so far is DON’T. And that’s good advice. I think you should take it. Having said that, I’ll try to provide some responses to your statements that might help.

?

“However I am struggling using the TWSlib.dll. I can connect to this lib but I am having problems to calling a function.

What I would like to know is if TWSlib is the best option or is it better to use the windows socket solution ?

I am not sure but it seems that the source code suppplied with TWS API of the other languages use the socket version ?”

?

What do you mean when you say you can connect to TWSLib.dll? Do you mean you can reference the library, instantiate a TWS object and successfully call the eConnect() method? If so, that’s actually quite encouraging. If PureBasic can properly deal with ActiveX technology, then you should be able to use it quite successfully.

?

What do you mean by ‘the windows socket solution’? I presume you mean the CSharpAPI.dll library? ?Every API implementation, no matter what language, use a socket connection to communicate with TWS/Gateway: there is no other way to communicate. Every API sends the same message in response to an API call. The TWSLib.dll (also known as the ActiveX API) is basically just a wrapper around CSharpAPI.dll. This wrapper uses Microsoft’s ActiveX technology to enable it to be used in environments that ‘speak’ ActiveX, such as Excel and other Office apps, Delphi, even Visual Basic 6. This version of the API is in some respects easier to program with than the CSharpAPI.dll, but it also has quite a few ‘gotchas’ that make it rather confusing.

?

So assuming that PureBasic is a fully fledged ActiveX host, you should be able to use the full power of the API fairly straightforwardly, once you’ve got over the initial confusion.

?

The other day I sent you a link to two sample programs written in Visual Basic .Net and C#, both using the CSharpAPI. As it happens, I also have a version that uses the ActiveX API. It does exactly the same things as the other two, but uses TWSLib.dll rather than CSharpAPI.dll. I’ve now uploaded that sample to the same location (see the SimpleTWSActiveXDemo folder, or SimpleTWSActiveXDemo.zip which is easier to download):

?

().

?

Hopefully you’ll be able to use that code as a basis for something in PureBasic. I imagine the main differences will be in how you reference the project, the syntax for handling events, and of course the UI creation which would no doubt be quite an effort to port. I’d suggest starting with a much reduced version that has a button to connect/disconnect and handles the connectAck and errMsg events. Once that’s working you can build up with the reqMktData call and the tickPrice and tickSize events, etc.

?

I should add that this version is also not using the latest API, but it works perfectly well. It doesn’t include the change from Double type to Decimal type for sizes, but that won’t matter for the moment (unless you want to trade crypto-currency contracts). I’ll try to get round to bringing these samples up-to-date? at some point.

?

If you get stuck, email me privately (you can do this using the Reply to Sender facility). I’ll do what I can to help, but only if it looks like there’s a chance it can be made to work.

?

?

“And I also have the impression that the socket version is more generic and makes the program independent of changes made by IB to TWSlib.

What do you think ?”

?

No, not really. The ActiveX API provides pretty much exactly the same capabilities as the CSharpAPI.dll (I think there are a couple of things that IBKR haven’t been able to provide for technical reasons, but I can’t remember what they are without going and looking – certainly not things that you’re likely to need any time soon). Changes to TWSLib always affect the client program one way or another.

?

“Please help me, I really would like to start making TWSAPI calls and start working on the interesting part of the program.”

?

??????????????? I’ll try!...

?

?

Richard

?


Re: Purebasic and TWS

 

I have no objections at all, Richard, and documenting such a path may even be helpful for people who want to integrate other languages in the future.

I just want to avoid that the entire group will be exposed to the long and painful TWS API re-implementation process from scratch in PureBasic.

Looking forward to seeing what you came up with.

闯ü谤驳别苍

?

On Thu, Dec 5, 2024 at 12:54 PM, Richard L King wrote:

Can I just say that @Tradiator’s earlier post today has actually opened up a possibility to move forward with PureBasic. I’m in the middle of drafting a response to it that will indicate a way to proceed. It’ll be a while before I’m ready to post it though.

?

So if no-one objects, I’ll post that response here in due course (in case it might be useful for someone else in future), and I can then follow up privately with @Tradiator if he wants to try my suggestion.

?

闯ü谤驳别苍. If you’d rather I didn’t, let me know and I’ll just send it direct to him.

?

Richard

?

?


Re: Purebasic and TWS

 

开云体育

Can I just say that @Tradiator’s earlier post today has actually opened up a possibility to move forward with PureBasic. I’m in the middle of drafting a response to it that will indicate a way to proceed. It’ll be a while before I’m ready to post it though.

?

So if no-one objects, I’ll post that response here in due course (in case it might be useful for someone else in future), and I can then follow up privately with @Tradiator if he wants to try my suggestion.

?

闯ü谤驳别苍. If you’d rather I didn’t, let me know and I’ll just send it direct to him.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of Tradiator
Sent: 05 December 2024 18:38
To: [email protected]
Subject: Re: [TWS API] Purebasic and TWS

?

Thank you all very much for your responses.

?

I will carefully study all the information received and try not to bother too much in the future.