'10/3/07 WCS 'Modified to work with generalized timebars Public Sub GetTimeAndSales(tsFilter As IESignal.TimeSalesFilter) Dim nCookie&, vC(nCookieItems) As Variant, sInterval$, sIdx$ Dim i&, sSymbol$ sInterval = sBarInterval nActiveHistoryCnt = nActiveHistoryCnt + 1 nActiveSymbolCnt = nActiveSymbolCnt + 1 'Debug.Print "Before RequestHistory", sSymbol nCookie = eSignal.RequestTimeSales(tsFilter) 'fires event to esignal_OnTimeSalesChanged when data ready If nCookie = 0 Then '10/14/07 WCS 'This can occur even when symbol is not invalid. And, the reentry can fail 'with a delay of .5 secs. 'Check validity of symbol. If Not VerifySymbol(sSymbol) Then nUErr = nUErr + 1 AddLog sSymbol & " is an invalid symbol" Else 'what to do? try a couple more times with .5 sec waitstate then trash For i = 1 To 3 WaitAwhile 0.5 nCookie = eSignal.RequestTimeSales(tsFilter) 'fires event to esignal_OnTimeSalesChanged when data ready If nCookie <> 0 Then Exit For Next i If i > 3 Then nUErr = nUErr + 1 AddLog sSymbol & " has no data. Cookie=0" End If End If End If 'With eSignal ' Debug.Print "After RequestHistory Cookie=", nCookie, .GetNumBars(nCookie), CBool(.IsHistoryReady(nCookie)) 'End With sSymbol = tsFilter.sSymbol If nCookie <> 0 Then vC(colSymbol) = sSymbol 'vC(colInterval) = sInterval 'vC(colBar_Type) = btDAYS 'vC(colNumOfBars) = nDays 'vC(colStartTime) = -1 'vC(colEndTime) = -1 Dim vTsFilter As Variant ReDim vTsFilter(13) With tsFilter vTsFilter(1) = .sSymbol vTsFilter(2) = .lNumDays vTsFilter(3) = .bQuotes vTsFilter(4) = .bTrades vTsFilter(5) = .bFilterPrice vTsFilter(6) = .dMinPrice vTsFilter(7) = .dMaxPrice vTsFilter(8) = .bFilterVolume vTsFilter(9) = .lVolume vTsFilter(10) = .bFilterTradeExchanges vTsFilter(11) = .sTradeExchangesList vTsFilter(12) = .bFilterQuoteExchanges vTsFilter(13) = .sQuoteExchangesList End With vC(colTimeSalesFilter) = vTsFilter vC(colBegTime) = Timer() 'begin clocking On Error Resume Next Dim ws As Worksheet Err = 0 With ThisWorkbook.Sheets Set ws = .item(sSymbol) If Err <> 0 Then Set ws = .Add(, .item(.Count)) ws.Name = sSymbol Else ws.Cells.Clear End If End With On Error GoTo 0 'mark other state in sheet memory variables With ws .Names.Add BarCount, 0, False End With Set vC(colSheet) = ws 'remember sheet for recall in event vC(colHandle) = nCookie sIdx = CStr(nCookie) colCookies.Add vC, sIdx Else AddLog sSymbol & " failed. Could not request history" DecrementActiveSymbolCnt DecrementActiveHistoryCnt End If '10/12/07 WCS 'Using debug.Print at various points, it appears that '(1) OnBarsChanged may be fired before return from HistoryRequest '(2) At least one OnBarsReceived is fired '(3) Multiple OnBarsChanged are fired End Sub Private Sub eSignal_OnTimeSalesChanged(ByVal lHandle As Long) Dim vC As Variant, sIdx$ Dim dtChange!, nEr&, k&, j& Dim sM$, nNewBars& Dim nElapsed! Dim lNumBars, lNumRtBars, lBar, lDiff As Long Dim item As IESignal.TimeSalesData, lLastTsCount& Dim ws As Worksheet, r As Range, sV$ Dim nm As Name #If WCS Then 'globals can get reset during debug, etc. If dtLastChange <= 0! Then dtLastChange = Timer() - nThrottleDefault If nThrottle <= 0# Then nThrottle = nThrottleDefault dtChange = Timer() nThrottle = nThrottle * (1 - nAlphaThrottle) + _ (dtChange - dtLastChange) * nAlphaThrottle If nThrottle <= nThrottleDefault Then dtLastChange = dtChange Else 'hang up...force reset dtLastChange = 0! nThrottle = nThrottleDefault End If #End If On Error Resume Next sIdx = CStr(lHandle) Err = 0 vC = colCookies.item(sIdx) If Err <> 0 Then Exit Sub 'ignore With eSignal lNumBars = .GetNumTimeSalesBars(lHandle) 'total bars If lNumBars <= 0 Then Exit Sub 'this can be 0! lNumRtBars = .GetNumTimeSalesRtBars(lHandle) 'total new bars since last entry End With Set ws = vC(colSheet) With ws Set nm = .Names(BarCount) sV = nm.RefersTo lLastTsCount = CLng(Right$(sV, Len(sV) - 1)) 'strip off = .Names.Add BarCount, lNumBars 'save state to sheet for later recall. Row count can get mashed when >64K. End With If False Then 'read items and save in worksheet Application.ScreenUpdating = False nNewBars = lNumBars - lLastTsCount lDiff = nNewBars * -1 k = lLastTsCount ReDim vBar(1 To 1, 1 To 6) With ws For lBar = lDiff + 1 To 0 item = eSignal.GetTimeSalesBar(lHandle, lBar) With item vBar(1, 1) = .DataType vBar(1, 2) = .dPrice vBar(1, 3) = .dtTime vBar(1, 4) = .lFlags vBar(1, 5) = .lSize vBar(1, 6) = .sExchange End With k = k + 1 If k <= .Rows.Count Then .Cells(k, 1).Resize(1, 6).Value = vBar 'overflow not handled here! Next lBar End With End If nElapsed = Timer() - CSng(vC(colBegTime)) sM = "Bars = " & CStr(lNumBars) & vbCrLf & "Elapsed VBA time = " & Format(nElapsed, "#,###.##0") & " secs" frmUpdate.StatusMsg sM, False, False Application.ScreenUpdating = False End Sub