Announcement

Collapse
No announcement yet.

Time & Sales - how to work correctly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Time & Sales - how to work correctly

    Hi

    I have a question about Time&Sales
    What I want to achieve is to make a T&S request and get first all the historical data that is available then continue to receive real-time data. I wrote such a code (VB6) for OnTimeSalesChanged event.
    Static lLastTsCount As Long
    Dim lNumBars, lBar, lDiff As Long
    Dim item As IESignal.TimeSalesData

    lNumBars = esignal.GetNumTimeSalesBars(lTsHandle)
    If lNumBars <= 0 Then Exit Sub

    ' how many new bars since last time?
    lDiff = (lNumBars - lLastTsCount) * -1

    For lBar = lDiff - 1 To 0
    item = esignal.GetTimeSalesBar(lTsHandle, lBar)
    sBar = FormatTS(item)
    list.AddItem sBar, 0
    Next lBar

    lLastTsCount = lNumBars


    However I see duplicate historical records (same time stamp) in list box. I guess I do something wrong when receiving historical data. I tried to find any samples that shows how to work with historical and rela-time T&S data but couldn't find one. All I found is only for real-time data.

    Pls advise what I do wrong.

    Thx

  • #2
    There is a simpler way to do this. You can take a look at the
    Time and Sales in VB.zip sample here:

    Comment


    • #3
      Hi

      Yes, I know about that page, but pls show me a link that shows how to work with Historical T&S data. The last 3 (that you pointed) are simple samples for real-time only.
      Did I miss something?

      Thx

      Comment


      • #4
        The "Time&Sales in VB" sample handles both historical and real-time time&sales data. It first obtains the historical data followed by the real-time portion. You can take a look at that sample.

        To obtain just the historical time&sales data, you can use the following logic:

        Private Sub esignal_OnTimeSalesChanged(ByVal tsHandle As Long)
        'Debug.Print ("OnTimeSalesChanged Fired")
        If requestHandle = tsHandle Then

        Debug.Print ("OnTimeSalesChanged: " & tsHandle)
        'lHandle is the handle to the time sales request that requested
        'this data
        Dim lNumBars, lNumRtBars, lBar, lDiff As Long
        Dim item As IESignal.TimeSalesData

        lNumBars = esignal.GetNumTimeSalesBars(tsHandle) 'Gets number of
        'historical bars

        For lBar = (lNumBars * -1) + 1 To (lLastTsCount * -1)
        'Debug.Print "Processing from " + Str(lBar) + "to " + Str(lLastTsCount * -1)
        item = esignal.GetTimeSalesBar(tsHandle, lBar) 'Gets a TimeSalesData structure.

        If item.DataType = tsdBID Then
        sBar = Format$(item.dtTime) & vbTab & Format$(item.dPrice) & " (Bid)" & vbTab & Format$(item.sExchange)
        ElseIf item.DataType = tsdASK Then
        sBar = Format$(item.dtTime) & vbTab & Format$(item.dPrice) & " (Ask)" & vbTab & Format$(item.sExchange)
        Else
        sBar = Format$(item.dtTime) & vbTab & Format$(item.dPrice) & vbTab & vbTab & Format$(item.sExchange) & vbTab & Format$(item.lFlags)
        End If

        List1.AddItem sBar, 0
        Next lBar

        lLastTsCount = lNumBars
        'esignal.ReleaseTimeSales (requestHandle)
        If esignal.IsTimeSalesReady(tsHandle) Then
        esignal.ReleaseTimeSales (tsHandle)
        End If
        End If

        End Sub

        Comment

        Working...
        X