Results 1 to 11 of 11

Thread: [RESOLVED] Issue with accessing data from what I assume is a collection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Resolved [RESOLVED] Issue with accessing data from what I assume is a collection

    My source for the VB.NET code is https://interactivebrokers.github.io...and_sales.html

    They give this code, which I am attempting to convert to VB6 for use in my app

    Code:
            Public Sub historicalTickBidAsk(reqId As Integer, ticks As HistoricalTickBidAsk(), done As Boolean) Implements EWrapper.historicalTicksBidAsk
                For Each tick In ticks
                    Console.WriteLine("Historical Tick Bid/Ask. Request Id: {0}, Time: {1}, Price Bid: {2}, Price Ask: {3}, Size Bid: {4}, Size Ask: {5}, Bid/Ask Tick Attribs: {6}",
                        reqId, Util.UnixSecondsToString(tick.Time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(tick.PriceBid), Util.DoubleMaxString(tick.PriceAsk),
                        Util.DecimalMaxString(tick.SizeBid), Util.DecimalMaxString(tick.SizeAsk), tick.TickAttribBidAsk.ToString())
                Next
            End Sub
    Now, firstly I know to use VB6 to get the event trigger line from, rather than trying to convert it all...so the VB6 version of this code (or at least the public sub line) would be:

    Code:
    Private Sub Tws1_historicalTicksBidAsk(ByVal reqId As Long, ByVal ticks As TWSLib.IHistoricalTickBidAskList, ByVal done As Boolean)
    Tws1 is the object that receives the event, and it receives something so is fired but I can't seem to work out how to access the data within "ticks". If I type "debug.print ticks." it shows "add", "add empty", "count" and "item" like a listbox does.

    If I try to use the "for each tick in ticks" I get the "Object required" error...assumedly because "tick" is set as nothing. If I do ticks.Count (as is suggested as one of the options above) it says "Object variable or with block variable not set"...not logical!

    I normally use sites like http://holowczak.com/ib-api-vbasic-historical-data/12/ (often that site specifically as it's a VB6 based source for what I need) but you might notice their API access method is different as they were probably using an older version of the API...so I need to work out how to access the data within the list, whatever format or method is required to do so.

    I should also point out that TWSLib *is* in the project, I use it elsewhere in the code for different things and even posted here with another issue using it...I thought it might have been the same issue, but couldn't work out how "tick" needed to be set :-)

    I should also point out that most people here wouldn't be able to test their code if they wanted to help me with code they know is working, you need an active subscription to get historical market data...but I'm willing to take suggestions for things to try!


    Anyone got any ideas? I rarely work with lists/collections and usually just use an array for sending masses of data across to a sub/function like this :-)
    Last edited by SmUX2k; Dec 3rd, 2022 at 07:40 AM.

  2. #2
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Issue with accessing data from what I assume is a collection

    I would probably consume their fancy types from a .NET dll using their sample code and then
    forward the data on to my vb6 code in a way I could control explicitly and understand intrinsically.

    probably the shortest path anyway. (at least would be for me)

    Someone more familiar with .net might have a better answer.

    to research it, disassemble the library they provide and see how its implemented on their end.
    Maybe see how .NET IEnumerable works when made COMVisible = true (if thats what the disassembly shows)

    You could also take the basic structure and create your own small mock up of the function returning the data
    to experiment with in a smaller more controlled manner.

    .NET is not my favorite good luck

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: Issue with accessing data from what I assume is a collection

    I would prefer to access it from within VB6 as it's sent through the control I have within my app...if I had a second app in .NET doing this it would use up another connection and I only get so many connections per user. I have very limited experience of .NET so wouldn't know what I am looking at when looking at the library's source code

    Is there no way to disassemble the incoming data into text so it can at least be viewed and I could then find a way to parse it into data I am able to use? There's probably complicated ways to "peek" the incoming data though I am guessing that would be particularly slow :-)

  4. #4
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Issue with accessing data from what I assume is a collection

    Looks like itís an array of classes from the web page sample
    Sometimes .count and .count() can give different results
    You can add a watch expression to the object in the vb ide and it can dump all the properties and values magically

    If you arenít getting an object reference though 🤷*♂️
    You could try outputting an objptr for the object and examining it in a native debugger to see whatís there

    If itís a paid library I would not hesitate to ask them for more info.

  5. #5
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Issue with accessing data from what I assume is a collection

    The object browser should give you a better idea of what your dealing with as well

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: Issue with accessing data from what I assume is a collection

    Changing ticks.count to ticks.count() didn't do anything, but I put a watch on ticks and it triggered as expected. "_NewEnum" as an object with no variables within, and a Count of 234. I don't know the usefulness of that information, not much experience of using the watch TBH...

    ...but typing "?ticks.count" in the immediate window now returns the number 234 (like the watch reported). Trying "?ticks(234)" (it's out of bounds, the count is 0-233) gives the error you would expect, but "?ticks(233)" returns "Object doesn't support this property or method"...there must be more to this than I'm seeing.

    I am slowly getting somewhere though...and the object browser didn't really tell me much, from what I could see (possibly I don't know what I am looking for :-) )

    I don't always get data sent...perhaps it is something to do with the DLL for the API, not sure how old it is and if it needs updating

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: Issue with accessing data from what I assume is a collection

    I have a response to the objptr for ticks also, but 111672048 (the number it returned) means nothing to me :-)

    I assume it's a pointer in memory to where the object's data is, but I wouldn't know what to do with that...or at least I wouldn't know the right way, I'd probably go directly into memory and find the data byte by byte when there are probably better ways

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: Issue with accessing data from what I assume is a collection

    I also have ascertained that "objptr(ticks(0))" returns a different number, and assumedly all the different "objects" in this collection will be different (surprisingly not concurrent, it's almost random). I know you don't want or need to see all the numbers as an example, but here's the first 11...


    0 111659824
    1 111672656
    2 111660976
    3 111660912
    4 111672304
    5 111670960
    6 111662256
    7 111662192
    8 111661776
    9 111662096
    10 111662032

  9. #9
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Issue with accessing data from what I assume is a collection

    try

    Code:
    Dim o as object
    set o = ticks(1)
    msgbox typename(o)
    then you can look up that object name in the object browser to see what it supports. A watch on o could also reveal more
    now that its an individual element.

    so it sounds like you will want to use

    Code:
    for n = 0 to ticks.count -1
        set o = ticks(n)
       'dostuff
    the _NewEnum should allow for
    Code:
    For Each o In  ticks
        'do stuff

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: Issue with accessing data from what I assume is a collection

    You're a lifesaver! Someone here always is, to be honest...though I do my best to rack my brains to work it out beforehand (as you can tell from the amount of things I mentioned in the original post).

    I was a little hesitant to be hopeful when the msgbox returned "ComHistoricalTickBidAsk" but setting a watch told me all the lovely data I was after was sitting within that little weird variable that only its mother loves (trust me, with the amount of hassle I go through trying to work out how to interface with this broker you'd understand if you had to go through it :-P )

    While awaiting your response, I happened to find https://www.vbforums.com/showthread....=1#post4330835 which gave me some insights into accessing memory directly, but I wasn't getting anywhere with it...still, I don't need to now you've solved the problem for me :-)

    Thanks again, you're in my will :-P

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    133

    Re: [RESOLVED] Issue with accessing data from what I assume is a collection

    Oh, and for the record, the watch for o returned variables "priceAsk", "priceBid", "sizeAsk", "sizeBid", and "time" and a few other bits. I can now use o.priceAsk to get the priceAsk data, for instance. The data is clearly and easily accessible and I just need to pull it out and store it now!

    And here's the real pain...while ticks only listed the 4 options, priceAsk was always available through it though the watch didn't show it...I just tested and ticks(0).priceAsk returns the same as o.priceAsk...I shouldn't need to iterate quite as badly as I thought!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width