开云体育

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

Does tickOptionComputation callback always come after all tickPrice() callbacks have been made for snapshot?

 

开云体育

I pull option quotes for single strikes by calling reqMktData() described here:


Regulatory Snapshots. The fifth argument to reqMktData specifies a regulatory snapshot request to US stocks and options. Regulatory snapshots require TWS/IBG v963 and API 973.02 or higher and specific market data subscriptions.. For stocks, there are individual exchange-specific market data subscriptions necessary to receive streaming quotes.
interactivebrokers.github.io

I receive bid,ask, and last/close via calls the callback method tickPrice().? After that, the option greeks are sent to another call back called?tickOptionComputation() described here:


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.
interactivebrokers.github.io

Is there any guarantee that the tick option callback will only arrive after all tickPrice() callbacks have been made?? The reason that I ask is because I usually only request snapshots and as mentioned in the first link, the?() call only comes 11 seconds after the request is made.? Why 11 seconds?? I have no idea, but I want to move on after I have all the callbacks.? Some strikes might be missing a bid or ask quote so I'll never know for sure how many tickPrice() calls to expect.? But if the tickOptionComputation() is only called after all tickPrice calls have been completed, then I know that I'm done after receiving the tickOptionComputation().? Is that the case?


Re: Help for an old coder. API 10.17 Bar class.

 

开云体育

Carlos

?

Good. It didn’t help that I left out the vital keyword!

?

Regarding my ?modified version of the IB ActiveX API that I mentioned earlier, I will bring it up to date (really just for my own purposes) and then I’ll let you have it if you still want it. But there’s probably not much point if you’re succeeding with IB’s ActiveX.

?

Richard

?

From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 19 August 2022 01:41
To: [email protected]
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

?

Hi Richard,

?

Unbelievable, worked.

?

I just did not follow the instructions correctly.

?

Thank you very much to you and joanmarcel.

?

Now I will continue from here and see what else maybe a problem but I think that is it.

?

Thank you

?

Carlos

?

-----Original Message-----
From: Richard L King <
rlking@...>
To:
[email protected]
Sent: Thu, Aug 18, 2022 8:25 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Carlos

?

Looking at the VBA code for the Excel demo, you probably need to use this:

?

?Set O.totalQuantity = CreateDecimalObject(quantity)

Sorry, I should have realised this before. Too many things happening today…

?


Re: How to check connection to TWS?

 

What if the lag of the tick data over 3 or 10 min?(1 or 2 K-bars)


--


------
Forex trader
David Liao


Re: Help for an old coder. API 10.17 Bar class.

 

Hi Richard,

Unbelievable, worked.

I just did not follow the instructions correctly.

Thank you very much to you and joanmarcel.

Now I will continue from here and see what else maybe a problem but I think that is it.

Thank you

Carlos


-----Original Message-----
From: Richard L King <rlking@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 8:25 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Carlos
?
Looking at the VBA code for the Excel demo, you probably need to use this:
?
?Set O.totalQuantity = CreateDecimalObject(quantity)

Sorry, I should have realised this before. Too many things happening today…
?
?
From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 19 August 2022 00:15
To: [email protected]
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.
?
Hi joanmarcel

Thank for the help
You correct the Collection exist, but still does not work.
?O.totalQuantity = CreateDecimalObject(quantity)

Comes back Error 424, Object required

The CreateDecimalObject function is working as if I do a print CreateDecimalObject(2).item(1) it does come back 2

I found this other idea where you create a type decimal and then copy the memory to a variant and uses that, also does not work
Option Explicit
 ?
Private Declare Sub RtlMoveMemory Lib "kernel32" (Dst As Any, Src As Any, ByVal BLen As Long)
 ?
'Struct translated from: 
Private Type DecimalStruct 'a Struct definition with a length of 16Bytes
? 'the first 4 Bytes
? wReserved As Integer '<- reserved, to act as the vt-Member when sitting in a 16Byte-Variant
? bScale As Byte
? bSign As Byte
? 'and the last 12 Bytes for the (96Bit) Integer-Value
? Hi32 As Long
? Lo32 As Long
? Mid32 As Long
End Type
Const DECIMAL_NEG As Byte = 128
 ?
Private Sub Form_Load()
 ?'let's say we want to express the negative value -1.23456 using the above DecimalStruct
? Dim MyDec As DecimalStruct
????? MyDec.Lo32 = 123456 'store the pure Integer (omitting both, the decimalpoint and the sign)
????? MyDec.Mid32 = 0 'not relevant (remaining at 0) since 123456 fits into .Lo32 entirely
????? MyDec.Hi32 = 0? '... dito here ...
????? 
??????MyDec.bSign = DECIMAL_NEG 'set the highest bit of the bSign-Byte (to signify neg. numbers)
????? MyDec.bScale = 5 '<- because of the 5 digits after the decimalpoint in case of our example
????? 
??????MyDec.wReserved = vbDecimal '<- only needed, when handing it over for "Ops using VB"
? 
??Dim V As Variant
? RtlMoveMemory V, MyDec, 16 'copy the 16 Bytes from MyDec over into the empty Variant V
? 
??'check what's inside V now - and whether the content is interpreted correctly by VB
? Debug.Print TypeName(V), V
End Sub
the O.totalQuantity does not like any of that, is always Object required or?Invalid procedure call errors, depending what you doing.


Re: Help for an old coder. API 10.17 Bar class.

 

开云体育

Carlos

?

Looking at the VBA code for the Excel demo, you probably need to use this:

?

?Set O.totalQuantity = CreateDecimalObject(quantity)

Sorry, I should have realised this before. Too many things happening today…

?

?

From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 19 August 2022 00:15
To: [email protected]
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

?

Hi joanmarcel

Thank for the help
You correct the Collection exist, but still does not work.
?O.totalQuantity = CreateDecimalObject(quantity)

Comes back Error 424, Object required

The CreateDecimalObject function is working as if I do a print CreateDecimalObject(2).item(1) it does come back 2

I found this other idea where you create a type decimal and then copy the memory to a variant and uses that, also does not work

Option Explicit
?
Private Declare Sub RtlMoveMemory Lib "kernel32" (Dst As Any, Src As Any, ByVal BLen As Long)
?
'Struct translated from: 
Private Type DecimalStruct 'a Struct definition with a length of 16Bytes
? 'the first 4 Bytes
? wReserved As Integer '<- reserved, to act as the vt-Member when sitting in a 16Byte-Variant
? bScale As Byte
? bSign As Byte
? 'and the last 12 Bytes for the (96Bit) Integer-Value
? Hi32 As Long
? Lo32 As Long
? Mid32 As Long
End Type
Const DECIMAL_NEG As Byte = 128
?
Private Sub Form_Load()
 ?'let's say we want to express the negative value -1.23456 using the above DecimalStruct
? Dim MyDec As DecimalStruct
????? MyDec.Lo32 = 123456 'store the pure Integer (omitting both, the decimalpoint and the sign)
????? MyDec.Mid32 = 0 'not relevant (remaining at 0) since 123456 fits into .Lo32 entirely
????? MyDec.Hi32 = 0? '... dito here ...
????? 
??????MyDec.bSign = DECIMAL_NEG 'set the highest bit of the bSign-Byte (to signify neg. numbers)
????? MyDec.bScale = 5 '<- because of the 5 digits after the decimalpoint in case of our example
????? 
??????MyDec.wReserved = vbDecimal '<- only needed, when handing it over for "Ops using VB"
? 
??Dim V As Variant
? RtlMoveMemory V, MyDec, 16 'copy the 16 Bytes from MyDec over into the empty Variant V
? 
??'check what's inside V now - and whether the content is interpreted correctly by VB
? Debug.Print TypeName(V), V
End Sub

the O.totalQuantity does not like any of that, is always Object required or?Invalid procedure call errors, depending what you doing.


Re: Help for an old coder. API 10.17 Bar class.

 

Hi joanmarcel

Thank for the help
You correct the Collection exist, but still does not work.
?O.totalQuantity = CreateDecimalObject(quantity)

Comes back Error 424, Object required

The CreateDecimalObject function is working as if I do a print CreateDecimalObject(2).item(1) it does come back 2

I found this other idea where you create a type decimal and then copy the memory to a variant and uses that, also does not work

Option Explicit

Private Declare Sub RtlMoveMemory Lib "kernel32" (Dst As Any, Src As Any, ByVal BLen As Long)

'Struct translated from: https://msdn.microsoft.com/en-us/library/windows/desktop/ms221061.aspx
Private Type DecimalStruct 'a Struct definition with a length of 16Bytes
  'the first 4 Bytes
  wReserved As Integer '<- reserved, to act as the vt-Member when sitting in a 16Byte-Variant
  bScale As Byte
  bSign As Byte
  'and the last 12 Bytes for the (96Bit) Integer-Value
  Hi32 As Long
  Lo32 As Long
  Mid32 As Long
End Type
Const DECIMAL_NEG As Byte = 128

Private Sub Form_Load()
  'let's say we want to express the negative value -1.23456 using the above DecimalStruct
  Dim MyDec As DecimalStruct
      MyDec.Lo32 = 123456 'store the pure Integer (omitting both, the decimalpoint and the sign)
      MyDec.Mid32 = 0 'not relevant (remaining at 0) since 123456 fits into .Lo32 entirely
      MyDec.Hi32 = 0  '... dito here ...
      
      MyDec.bSign = DECIMAL_NEG 'set the highest bit of the bSign-Byte (to signify neg. numbers)
      MyDec.bScale = 5 '<- because of the 5 digits after the decimalpoint in case of our example
      
      MyDec.wReserved = vbDecimal '<- only needed, when handing it over for "Ops using VB"
  
  Dim V As Variant
  RtlMoveMemory V, MyDec, 16 'copy the 16 Bytes from MyDec over into the empty Variant V
  
  'check what's inside V now - and whether the content is interpreted correctly by VB
  Debug.Print TypeName(V), V
End Sub
the O.totalQuantity does not like any of that, is always Object required or?Invalid procedure call errors, depending what you doing.


Re: Help for an old coder. API 10.17 Bar class.

 

OK, looks like I am wrong let me try it again, first time did not work.

Thank you the help.

Carlos



-----Original Message-----
From: joanmarcel119 <joanmarcel@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 6:45 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Hola Carlos, mira he encontrado esto:



Quizás Collection sí existe (en mayúscula la primera letra)

El vie, 19 ago 2022 a las 0:22, carlos via (<ctalmeida=[email protected]>) escribió:
Hello joanmarcel

Thank you for the help.

The collection does not exist in VB6, at least as far as I know.

I have try that on 2010 compile as an activeX, was able to access that from the VB6 code, same problem.

Invalid procedure call or Object required errors.

depending how I change the code.

Thank you

Carlos


-----Original Message-----
From: joanmarcel119 <joanmarcel@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 5:40 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Carlos, place this function Richard sent to you:

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function


Directly in your VB code and call it from the same VB, don't create an ActiveX object nor class or new module, just try the function on your code.
Maybe this way will work or maybe not.

El jue, 18 ago 2022 a las 22:27, carlos via (<ctalmeida=[email protected]>) escribió:
Hi Richard,

If I understood I will need to edit the IB ativex API to include that function and then recompile it?

Is that what you mean?

I created and activeX using 2010 version put this code in

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function

It did not work. I tried?to change the function to decimal with no collection, did other combinations nothing seem to work.
I get Invalid procedure call or Object required errors.

If you mean to put the CreateDecimalObject inside my VB6 code not sure how that will work. As far as I know VB6 has no collection class.


I am just confuse here what you want me to try.

Yes, sure if you have a code that will work I would love to have it.

Again thank you very much for your time on this

Carlos



Re: Help for an old coder. API 10.17 Bar class.

 

Hola Carlos, mira he encontrado esto:



Quizás Collection sí existe (en mayúscula la primera letra)

El vie, 19 ago 2022 a las 0:22, carlos via (<ctalmeida=[email protected]>) escribió:
Hello joanmarcel

Thank you for the help.

The collection does not exist in VB6, at least as far as I know.

I have try that on 2010 compile as an activeX, was able to access that from the VB6 code, same problem.

Invalid procedure call or Object required errors.

depending how I change the code.

Thank you

Carlos


-----Original Message-----
From: joanmarcel119 <joanmarcel@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 5:40 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Carlos, place this function Richard sent to you:

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function


Directly in your VB code and call it from the same VB, don't create an ActiveX object nor class or new module, just try the function on your code.
Maybe this way will work or maybe not.

El jue, 18 ago 2022 a las 22:27, carlos via (<ctalmeida=[email protected]>) escribió:
Hi Richard,

If I understood I will need to edit the IB ativex API to include that function and then recompile it?

Is that what you mean?

I created and activeX using 2010 version put this code in

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function

It did not work. I tried?to change the function to decimal with no collection, did other combinations nothing seem to work.
I get Invalid procedure call or Object required errors.

If you mean to put the CreateDecimalObject inside my VB6 code not sure how that will work. As far as I know VB6 has no collection class.


I am just confuse here what you want me to try.

Yes, sure if you have a code that will work I would love to have it.

Again thank you very much for your time on this

Carlos



Re: Help for an old coder. API 10.17 Bar class.

 

Hello joanmarcel

Thank you for the help.

The collection does not exist in VB6, at least as far as I know.

I have try that on VB.NET 2010 compile as an activeX, was able to access that from the VB6 code, same problem.

Invalid procedure call or Object required errors.

depending how I change the code.

Thank you

Carlos


-----Original Message-----
From: joanmarcel119 <joanmarcel@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 5:40 pm
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

Carlos, place this function Richard sent to you:

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function


Directly in your VB code and call it from the same VB, don't create an ActiveX object nor class or new module, just try the function on your code.
Maybe this way will work or maybe not.

El jue, 18 ago 2022 a las 22:27, carlos via (<ctalmeida=[email protected]>) escribió:
Hi Richard,

If I understood I will need to edit the IB ativex API to include that function and then recompile it?

Is that what you mean?

I created and activeX using 2010 version put this code in

Public Function CreateDecimalObject(value As Variant) As Object
??? Dim collection As New collection
??? collection.Add CDec(value)
??? Set CreateDecimalObject = collection

End Function

It did not work. I tried?to change the function to decimal with no collection, did other combinations nothing seem to work.
I get Invalid procedure call or Object required errors.

If you mean to put the CreateDecimalObject inside my VB6 code not sure how that will work. As far as I know VB6 has no collection class.


I am just confuse here what you want me to try.

Yes, sure if you have a code that will work I would love to have it.

Again thank you very much for your time on this

Carlos



reqTickByTickData - AllLast examples

 

In?reqTickByTickData there is an option to request "AllLast" and here is explanation quote: "AllLast has additional trade types such as combos, derivatives, and average price trades which are not included in Last"

Does anybody know where I can find an illustration for combos, derivatives and average price trades and related price for all them? It would be great to have it for simple ticker like SPY.


Re: Help for an old coder. API 10.17 Bar class.

 

Carlos, place this function Richard sent to you:

Public Function CreateDecimalObject(value As Variant) As Object

??? Dim collection As New collection

??? collection.Add CDec(value)

??? Set CreateDecimalObject = collection

End Function


Directly in your VB code and call it from the same VB, don't create an ActiveX object nor class or new module, just try the function on your code.
Maybe this way will work or maybe not.


El jue, 18 ago 2022 a las 22:27, carlos via (<ctalmeida=[email protected]>) escribió:
Hi Richard,

If I understood I will need to edit the IB ativex API to include that function and then recompile it?

Is that what you mean?

I created and activeX using 2010 version put this code in

Public Function CreateDecimalObject(value As Variant) As Object

??? Dim collection As New collection

??? collection.Add CDec(value)

??? Set CreateDecimalObject = collection

End Function

It did not work. I tried?to change the function to decimal with no collection, did other combinations nothing seem to work.
I get Invalid procedure call or Object required errors.

If you mean to put the CreateDecimalObject inside my VB6 code not sure how that will work. As far as I know VB6 has no collection class.


I am just confuse here what you want me to try.

Yes, sure if you have a code that will work I would love to have it.

Again thank you very much for your time on this

Carlos



Re: Timestamp of reqTickByTickData and timezone in TWS

 

开云体育

Editing posts is nearly always a bad idea. It’s much better to send another (as a reply to the original one) one pointing out what you want to say differently, so that the full history of what’s been said is preserved. Otherwise you get can replies to posts that have changed from what the replier was actually responding to, and other ills.

?

As a matter of fact, although the Group settings in theory don’t allow users to edit their posts, I believe that you CAN actually do this because the developers of the groups.io software received legal advice that not permitting this was dubious under GDPR rules.

?

However I urge people not to do this unless it’s a trivial change that doesn’t affect the sense of the original post. Adding new stuff would be a bad idea. Fixing a typo or adding a missing word, less so.

?

So what you’ve actually done here is just fine.

?

Richard King

Moderator

?

?

From: [email protected] <[email protected]> On Behalf Of GreenGreen via groups.io
Sent: 18 August 2022 21:51
To: [email protected]
Subject: Re: [TWS API] Timestamp of reqTickByTickData and timezone in TWS

?

Sorry, I just want to clarify that my question about different IBGM settings was about time zone settings. It would be great to see how choosing EST time zone would generate different code response.?

P.S. Too bad it is not possible to edit the post.


Re: Timestamp of reqTickByTickData and timezone in TWS

 

Correct, but Coordinated Universal Time (UTC) is not a time zone, but a reference time standard:

  • .

All TWS API objects that return absolute time strings will be impacted by your configuration selection. One that comes to mind immediately is , where you can select the returned time format as epoch time stamp or absolute time. Absolute time will follow your IBGW/TWS time zone configuration.

We stay away from absolute times as much as we can since time zones get complicated very quickly even before you bring in daylight saving time. Epoch time is unambiguous and the same number defines exactly the same point on the time line anywhere on earth regardless how the locals refer to that point in time.

闯ü谤驳别苍


Re: Timestamp of reqTickByTickData and timezone in TWS

 

Sorry, I just want to clarify that my question about different IBGM settings was about time zone settings. It would be great to see how choosing EST time zone would generate different code response.?

P.S. Too bad it is not possible to edit the post.


Re: Help for an old coder. API 10.17 Bar class.

 

Hi Richard,

If I understood I will need to edit the IB ativex API to include that function and then recompile it?

Is that what you mean?

I created and activeX using VB.NET 2010 version put this code in

Public Function CreateDecimalObject(value As Variant) As Object

??? Dim collection As New collection

??? collection.Add CDec(value)

??? Set CreateDecimalObject = collection

End Function

It did not work. I tried?to change the function to decimal with no collection, did other combinations nothing seem to work.
I get Invalid procedure call or Object required errors.

If you mean to put the CreateDecimalObject inside my VB6 code not sure how that will work. As far as I know VB6 has no collection class.


I am just confuse here what you want me to try.

Yes, sure if you have a code that will work I would love to have it.

Again thank you very much for your time on this

Carlos



Re: Timestamp of reqTickByTickData and timezone in TWS

 

Thank you so much, 闯ü谤驳别苍!

I was under impression that Epoch Time is number of second counted from UTC datetime.?

Do you by any chance have an example of how differente IBGM settings are reflected in API code?

Regards


Re: Help for an old coder. API 10.17 Bar class.

 

开云体育

I’m not sure whether I understand you correctly. Yes, you could certainly create an ActiveX wrapper around the IB ActiveX API that includes the function, but that would be a lot of work because you’d have to expose all the classes, methods, properties and events via the wrapper.

?

If you want to do this sort of thing, a much better approach would be what I offered to IB: I’ve already done the code for that and I have a working sample application. It would be relatively straightforward to maintain as the C# AI evolves. In fact it only requires very little change in the C# and ActiveX APIs, nearly all the work involved was in fixing up the VBA code in the Excel sample to use the revised properties and method/event signatures.

?

I’d be happy to supply you with that code and the sample program, though it was back in February that I produced it so it might need to be brought up-to-date a little.

?

But by far the easiest thing to do is simply to include that CreateDecimalObject function in your code base.

?

?

From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 18 August 2022 18:42
To: [email protected]
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

?

Thank you Richard,

?

Then the solution could be create an activex in C# or VB.NET with that function that returns this object, then from the VB6 code I call this function?

?

Do you think that would work?

?

Thank you

?

Carlos

-----Original Message-----
From: Richard L King <rlking@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 12:54 pm
Subject: Re: [TWS API] 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,

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: Timestamp of reqTickByTickData and timezone in TWS

 

Time stamps have no time zone. They are relative measures of time (integer values such as 1660847370) often referred to as "". And since they are independent of time zones, they are also independent of daylight saving times or other local adjustments. But you are free to convert them to an absolute time in any time zone you prefer. You just have to let your conversion or print function know which time zone to convert to.

Time zone selections in IBGW and TWS relate only to data with absolute date/time strings, such as "20220818 10:21:33". Here you must know the timezone (and daylight saving compensation) in order to know the exact described time, unless the time zone name or offset is attracted to the end of the string (such as "20220818 10:21:33 US/Eastern").

闯ü谤驳别苍


Timestamp of reqTickByTickData and timezone in TWS

 

In IB Gateway, I selected timezone: "(UTC-05:00) America/New York", but in my?reqTickByTickData, I am still getting UTC.?

Here is my code:?

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
import time
import datetime
import threading
?
class TestApp(EWrapper, EClient):
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? ? ? ? ?
?
? ? def error(self, reqId, errorCode, errorString):
? ? ? ? print("Error: ", reqId, " ", errorCode, " ", errorString)
?
? ? def tickByTickAllLast(self, reqId, tickType, time, price, size, tickAtrribLast, exchange, specialConditions):
? ? ? ? print("Tick Price. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType),
? ? ? ? ? ? ? "tickTypeNumeric:", tickType,
? ? ? ? ? ? ? "Price:", price,
? ? ? ? ? ? ? "Exchange", exchange,
? ? ? ? ? ? ? "market_time:", datetime.datetime.fromtimestamp(time) ,? "server time :", datetime.datetime.now())
? ? ? ? print("_______________________")
? ??
contract2 = Contract()
contract2.symbol = "SPY"
contract2.secType = "STK"
contract2.exchange = "SMART"
contract2.currency = "USD"
contract2.primaryExchange = "ARCA"

app = TestApp()
app.connect("127.0.0.1", 4002, 0)
time.sleep(1)
app.reqTickByTickData(1 ,contract2, "Last", 0, True)
api_thread = threading.Thread(target=app.run)
api_thread.start()
time.sleep(5)
app.cancelTickByTickData(1)
app.disconnect()

Here is output

Error:? -1? ?2104? ?Market data farm connection is OK:usfarm
Error:? -1? ?2106? ?HMDS data farm connection is OK:ushmds
Error:? -1? ?2158? ?Sec-def data farm connection is OK:secdefil
Tick Price. Ticker Id: 1 tickType: BID tickTypeNumeric: 1 Price: 426.96 Exchange CHX market_time: 2022-08-18 18:05:59 server time : 2022-08-18 18:05:59.622034
_______________________
Tick Price. Ticker Id: 1 tickType: BID tickTypeNumeric: 1 Price: 426.96 Exchange ARCA market_time: 2022-08-18 18:06:00 server time : 2022-08-18 18:06:00.587073
_______________________
Tick Price. Ticker Id: 1 tickType: BID tickTypeNumeric: 1 Price: 426.96 Exchange ISLAND market_time: 2022-08-18 18:06:00 server time : 2022-08-18 18:06:00.590668
? ?
?
The EST timestamp should be something like 13:06:00.xxxxxx. Am I missing something?


Re: Help for an old coder. API 10.17 Bar class.

 

Thank you Richard,

Then the solution could be create an activex in C# or VB.NET with that function that returns this object, then from the VB6 code I call this function?

Do you think that would work?

Thank you

Carlos


-----Original Message-----
From: Richard L King <rlking@...>
To: [email protected]
Sent: Thu, Aug 18, 2022 12:54 pm
Subject: Re: [TWS API] 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,

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